Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
foreign
/
customer-service
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
9aed20af
authored
Nov 02, 2021
by
Sixong.Zhu
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
msg
parent
4ef8859e
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
14 deletions
components/chat-room.vue
model/index.ts
xim/index.ts
xim/xim.ts
components/chat-room.vue
View file @
9aed20af
...
...
@@ -47,6 +47,7 @@
import
MessageInput
from
"@/customer-service/components/message-input.vue"
;
import
messages
from
"@/customer-service/components/message-list.vue"
;
import
{
ChatStore
,
chatStore
}
from
"@/customer-service/store/model"
;
import
Chat
from
"@/customer-service/xim"
;
type
RoomInfoTab
=
"customer"
|
"order"
;
...
...
@@ -125,7 +126,7 @@
}
private
onError
(
msg
:
string
)
{
this
.
$message
.
error
(
msg
);
Chat
.
error
(
msg
);
}
private
dragControllerDiv
(
e
:
MouseEvent
)
{
...
...
model/index.ts
View file @
9aed20af
...
...
@@ -69,6 +69,13 @@ export interface ChatOption {
* 用户信息(头像,别名)可选
*/
user
?:
{
icon
?:
string
;
username
?:
string
};
message
?:
ChatMessageController
;
}
export
interface
ChatMessageController
{
error
:
(
msg
:
string
)
=>
void
;
info
:
(
msg
:
string
)
=>
void
;
}
export
interface
ChatServiceLogger
{
...
...
xim/index.ts
View file @
9aed20af
...
...
@@ -7,13 +7,14 @@ import {
TokenStringGetter
,
ServiceType
,
CustomerServiceProduct
,
ChatMessageController
,
}
from
"./../model"
;
import
{
ChatLoggerService
}
from
"./logger"
;
import
tokenManager
from
"./token"
;
import
xim
from
"./xim"
;
import
{
dbController
}
from
"../database"
;
class
Chat
{
class
Chat
implements
ChatMessageController
{
private
_sdk
?:
()
=>
UniplatSdk
;
private
_orgId
:
()
=>
string
|
number
=
()
=>
"0"
;
private
token
!
:
TokenStringGetter
;
...
...
@@ -24,6 +25,7 @@ class Chat {
private
ws
=
""
;
private
connectedActions
:
(()
=>
void
)[]
=
[];
private
connected
=
false
;
private
messageController
:
ChatMessageController
|
null
=
null
;
private
userMapping
:
{
[
key
:
string
]:
{
name
:
string
;
avatar
:
string
}
}
=
{};
...
...
@@ -59,6 +61,8 @@ class Chat {
};
}
option
.
message
&&
(
this
.
messageController
=
option
.
message
);
this
.
setupIndexDb
();
this
.
token
=
async
()
=>
option
.
sdk
().
global
.
jwtToken
;
tokenManager
.
save
(
this
.
token
);
...
...
@@ -88,7 +92,7 @@ class Chat {
s
.
global
.
uid
+
"-"
+
(
s
.
global
.
initData
.
orgId
||
0
)
);
}
return
Promise
.
reject
();
return
Promise
.
reject
(
new
Error
(
'Sdk is not defined'
)
);
}
public
resetup
(
org
:
()
=>
string
|
number
)
{
...
...
@@ -140,7 +144,7 @@ class Chat {
if
(
xim
.
isConnected
())
{
return
Promise
.
resolve
(
uri
);
}
return
new
Promise
((
resolve
)
=>
{
return
new
Promise
<
void
>
((
resolve
)
=>
{
xim
.
open
(
uri
,
this
.
token
).
finally
(()
=>
{
this
.
registerXimEvent
();
if
(
xim
.
isConnected
())
{
...
...
@@ -172,7 +176,7 @@ class Chat {
}
private
debug
(
message
:
string
)
{
ChatLoggerService
.
logger
?
.
debug
(
message
);
ChatLoggerService
.
logger
&&
ChatLoggerService
.
logger
.
debug
(
message
);
}
public
$emit
(
event
:
string
,
...
args
:
any
[])
{
...
...
@@ -190,6 +194,14 @@ class Chat {
public
getMatchedTextKeywords
()
{
return
this
.
keywords
;
}
public
error
(
msg
:
string
)
{
this
.
messageController
&&
this
.
messageController
.
error
(
msg
);
}
public
info
(
msg
:
string
)
{
this
.
messageController
&&
this
.
messageController
.
info
(
msg
);
}
}
export
default
new
Chat
();
xim/xim.ts
View file @
9aed20af
...
...
@@ -96,6 +96,10 @@ export class Xim {
return
token
.
replace
(
/^Bearer
\s
/
,
""
);
}
private
buildError
()
{
return
new
Error
(
`Connect is not ready`
);
}
/**
* token过期或者切换用户登录时,需要设置新的token
*/
...
...
@@ -108,22 +112,22 @@ export class Xim {
}
public
fetchMsgInBox
(
chatId
:
number
,
msgId
:
number
)
{
if
(
this
.
client
==
null
)
return
Promise
.
reject
();
if
(
this
.
client
==
null
)
return
Promise
.
reject
(
this
.
buildError
()
);
return
this
.
client
.
fetchMsgInBox
(
chatType
,
chatId
,
msgId
);
}
public
fetchChatList
()
{
if
(
this
.
client
==
null
)
return
Promise
.
reject
();
if
(
this
.
client
==
null
)
return
Promise
.
reject
(
this
.
buildError
()
);
return
this
.
client
.
fetchChatList
({});
}
public
fetchChatListAfter
(
lastMsgTs
:
number
)
{
if
(
this
.
client
==
null
)
return
Promise
.
reject
();
if
(
this
.
client
==
null
)
return
Promise
.
reject
(
this
.
buildError
()
);
return
this
.
client
.
fetchChatList
({
last_msg_ts
:
lastMsgTs
});
}
public
fetchChat
(
chat_id
:
number
)
{
if
(
this
.
client
==
null
)
return
Promise
.
reject
();
if
(
this
.
client
==
null
)
return
Promise
.
reject
(
this
.
buildError
()
);
return
this
.
client
.
fetchChat
(
chat_id
);
}
...
...
@@ -137,13 +141,13 @@ export class Xim {
msg
:
string
)
{
this
.
checkConnected
();
if
(
this
.
client
==
null
)
return
Promise
.
reject
();
if
(
this
.
client
==
null
)
return
Promise
.
reject
(
this
.
buildError
()
);
return
this
.
client
.
sendMsg
(
chatType
,
chatId
,
msgType
,
msg
,
""
,
{});
}
public
inputing
(
chatId
:
number
)
{
this
.
checkConnected
();
if
(
this
.
client
==
null
)
return
Promise
.
reject
();
if
(
this
.
client
==
null
)
return
Promise
.
reject
(
this
.
buildError
()
);
return
this
.
client
.
userInput
(
chatType
,
chatId
);
}
...
...
@@ -152,7 +156,7 @@ export class Xim {
*/
public
fetchChatMembers
(
chat_id
:
number
)
{
this
.
checkConnected
();
if
(
this
.
client
==
null
)
return
Promise
.
reject
();
if
(
this
.
client
==
null
)
return
Promise
.
reject
(
this
.
buildError
()
);
return
this
.
client
.
fetchChatMembers
(
chat_id
);
}
...
...
@@ -384,7 +388,7 @@ export class Xim {
if
(
this
.
client
==
null
)
return
;
if
(
!
this
.
client
.
connected
)
{
try
{
this
.
client
?
.
open
();
this
.
client
&&
this
.
client
.
open
();
}
catch
(
e
)
{
// eslint-disable-next-line no-console
console
.
error
(
"checkConnected"
,
e
);
...
...
@@ -394,7 +398,7 @@ export class Xim {
}
private
debug
(
message
:
any
,
...
params
:
any
[])
{
ChatLoggerService
.
logger
?
.
debug
(
message
,
params
);
ChatLoggerService
.
logger
&&
ChatLoggerService
.
logger
.
debug
(
message
,
params
);
}
public
registerOnMessage
(
vue
:
Vue
,
action
:
(
e
:
Message
)
=>
void
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment