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
1cda55d0
authored
Nov 03, 2021
by
Sixong.Zhu
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
notify
parent
4a06dee9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
2 deletions
xim/xim.ts
xim/xim.ts
View file @
1cda55d0
...
@@ -38,6 +38,10 @@ const chatType = "group";
...
@@ -38,6 +38,10 @@ const chatType = "group";
export
class
Xim
{
export
class
Xim
{
private
eventBus
=
new
Vue
();
private
eventBus
=
new
Vue
();
private
readonly
messageNotifyActions
:
{
key
:
string
;
action
:
(
m
:
Message
)
=>
void
;
}[]
=
[];
private
client
?:
XChatClient
;
private
client
?:
XChatClient
;
...
@@ -420,6 +424,17 @@ export class Xim {
...
@@ -420,6 +424,17 @@ export class Xim {
private
handleMsg
(
kind
:
any
,
msg
:
any
)
{
private
handleMsg
(
kind
:
any
,
msg
:
any
)
{
this
.
debug
(
`收到消息
${
new
Date
().
getTime
()}
`
,
kind
,
msg
);
this
.
debug
(
`收到消息
${
new
Date
().
getTime
()}
`
,
kind
,
msg
);
if
(
(
kind
===
"chat"
||
kind
===
"chat_notify"
)
&&
msg
&&
msg
.
msg_type
!==
"read"
&&
msg
.
msg_type
!==
"user.input"
)
{
for
(
const
item
of
this
.
messageNotifyActions
)
{
item
.
action
(
msg
);
}
}
switch
(
kind
)
{
switch
(
kind
)
{
case
"chat"
:
case
"chat"
:
this
.
emit
(
`msg`
,
msg
);
this
.
emit
(
`msg`
,
msg
);
...
@@ -453,8 +468,15 @@ export class Xim {
...
@@ -453,8 +468,15 @@ export class Xim {
}
}
public
registerOnMessage
(
vue
:
Vue
,
action
:
(
e
:
Message
)
=>
void
)
{
public
registerOnMessage
(
vue
:
Vue
,
action
:
(
e
:
Message
)
=>
void
)
{
this
.
on
(
"msg"
,
action
);
const
key
=
`
${
new
Date
().
valueOf
()}
-
${
Math
.
random
()}
`
;
vue
.
$once
(
"hook:beforeDestroy"
,
()
=>
this
.
off
(
"msg"
,
action
));
this
.
messageNotifyActions
.
push
({
key
,
action
});
vue
.
$once
(
"hook:beforeDestroy"
,
()
=>
{
const
t
=
this
.
messageNotifyActions
.
find
((
i
)
=>
i
.
key
===
key
);
if
(
t
)
{
const
index
=
this
.
messageNotifyActions
.
indexOf
(
t
);
this
.
messageNotifyActions
.
splice
(
index
,
1
);
}
});
}
}
}
}
...
...
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