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
27fae3ae
authored
Nov 01, 2021
by
Sixong.Zhu
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
update
parent
8cc8f134
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
26 deletions
store/index.ts
xim/index.ts
store/index.ts
View file @
27fae3ae
...
@@ -31,7 +31,7 @@ function uniqueMessages(
...
@@ -31,7 +31,7 @@ function uniqueMessages(
messages
:
NonNullable
<
ChatStore
.
STATE_CHAT_MSG_HISTORY
>
messages
:
NonNullable
<
ChatStore
.
STATE_CHAT_MSG_HISTORY
>
)
{
)
{
const
arr
=
[...
messages
];
const
arr
=
[...
messages
];
return
unique
(
arr
,
function
(
item
,
all
)
{
return
unique
(
arr
,
function
(
item
,
all
)
{
return
all
.
findIndex
((
k
)
=>
k
.
id
===
item
.
id
);
return
all
.
findIndex
((
k
)
=>
k
.
id
===
item
.
id
);
});
});
}
}
...
@@ -327,7 +327,7 @@ export default {
...
@@ -327,7 +327,7 @@ export default {
state
[
ChatStore
.
STATE_CHAT_SENDING_MESSAGES
]
=
[...
current
];
state
[
ChatStore
.
STATE_CHAT_SENDING_MESSAGES
]
=
[...
current
];
}
}
},
},
[
ChatStore
.
MUTATION_SAVE_CURRENT_CHAT_INPUTING
]:
(
function
()
{
[
ChatStore
.
MUTATION_SAVE_CURRENT_CHAT_INPUTING
]:
(
function
()
{
const
setTimeoutId
:
{
[
key
:
string
]:
number
}
=
{};
const
setTimeoutId
:
{
[
key
:
string
]:
number
}
=
{};
return
(
return
(
state
:
ChatStoreState
,
state
:
ChatStoreState
,
...
@@ -404,26 +404,52 @@ export default {
...
@@ -404,26 +404,52 @@ export default {
.
map
((
i
)
=>
Math
.
max
(
i
.
last_msg_ts
,
i
.
update_time
))
.
map
((
i
)
=>
Math
.
max
(
i
.
last_msg_ts
,
i
.
update_time
))
.
sort
();
.
sort
();
const
last
=
ts
[
ts
.
length
-
1
];
const
last
=
ts
[
ts
.
length
-
1
];
await
xim
.
fetchChatListAfter
(
last
)
!
.
then
((
r
)
=>
{
const
execute
=
()
=>
const
list
=
filterActiveChats
(
r
.
args
[
0
]
as
RawChatItem
[]);
new
Promise
<
ChatType
[]
>
((
resolve
)
=>
{
const
items
=
list
.
map
((
i
)
=>
buildChatItem
(
i
));
Chat
.
onReady
(()
=>
{
if
(
items
&&
items
.
length
)
{
xim
.
fetchChatListAfter
(
last
)
!
.
then
((
r
)
=>
{
cache
=
dbController
.
mergeChatList
(
cache
,
items
);
const
list
=
filterActiveChats
(
}
r
.
args
[
0
]
as
RawChatItem
[]
});
);
return
buildUnreadMessage
(
cache
);
const
items
=
list
.
map
((
i
)
=>
buildChatItem
(
i
));
if
(
items
&&
items
.
length
)
{
cache
=
dbController
.
mergeChatList
(
cache
,
items
);
}
resolve
(
buildUnreadMessage
(
cache
));
});
});
});
return
await
execute
().
then
((
d
)
=>
d
);
}
}
const
data
=
await
xim
.
fetchChatList
();
const
execute
=
()
=>
if
(
data
==
null
)
return
;
new
Promise
<
ChatType
[]
>
((
resolve
)
=>
{
const
chatList
=
filterActiveChats
(
data
.
args
[
0
]
as
RawChatItem
[]);
Chat
.
onReady
(()
=>
{
const
items
=
chatList
.
map
((
chat
)
=>
buildChatItem
(
chat
));
xim
.
fetchChatList
().
then
((
data
)
=>
{
dbController
.
saveChatList
(
items
);
if
(
!
data
)
{
commit
(
ChatStore
.
MUTATION_SAVE_CHAT_LIST
,
{
return
resolve
([]);
list
:
items
,
}
total
:
9999
,
const
chatList
=
filterActiveChats
(
});
data
.
args
[
0
]
as
RawChatItem
[]
return
buildUnreadMessage
(
items
);
);
const
items
=
chatList
.
map
((
chat
)
=>
buildChatItem
(
chat
)
);
dbController
.
saveChatList
(
items
);
commit
(
ChatStore
.
MUTATION_SAVE_CHAT_LIST
,
{
list
:
items
,
total
:
9999
,
});
resolve
(
buildUnreadMessage
(
items
));
});
});
});
return
await
execute
().
then
((
d
)
=>
d
);
},
},
async
[
ChatStore
.
ACTION_REBUILD_UNREAD_MESSAGE_COUNT
]({
state
})
{
async
[
ChatStore
.
ACTION_REBUILD_UNREAD_MESSAGE_COUNT
]({
state
})
{
let
items
=
await
dbController
.
getChatList
();
let
items
=
await
dbController
.
getChatList
();
...
@@ -734,7 +760,7 @@ export default {
...
@@ -734,7 +760,7 @@ export default {
}
}
commit
(
commit
(
ChatStore
.
MUTATION_SAVE_CURRENT_CHAT_MEMBERS
,
ChatStore
.
MUTATION_SAVE_CURRENT_CHAT_MEMBERS
,
unique
(
newChatMembers
,
function
(
item
,
all
)
{
unique
(
newChatMembers
,
function
(
item
,
all
)
{
return
all
.
findIndex
((
k
)
=>
k
.
eid
===
item
.
eid
);
return
all
.
findIndex
((
k
)
=>
k
.
eid
===
item
.
eid
);
})
})
);
);
...
...
xim/index.ts
View file @
27fae3ae
...
@@ -22,10 +22,20 @@ class Chat {
...
@@ -22,10 +22,20 @@ class Chat {
private
eventHub
:
Vue
|
null
=
null
;
private
eventHub
:
Vue
|
null
=
null
;
private
keywords
:
string
[]
=
[];
private
keywords
:
string
[]
=
[];
private
ws
=
""
;
private
ws
=
""
;
private
connectedActions
:
(()
=>
void
)[]
=
[];
private
connected
=
false
;
private
userMapping
:
{
[
key
:
string
]:
{
name
:
string
;
avatar
:
string
}
}
=
private
userMapping
:
{
[
key
:
string
]:
{
name
:
string
;
avatar
:
string
}
}
=
{};
{};
public
onReady
(
action
:
()
=>
void
)
{
if
(
this
.
connected
)
{
action
();
}
else
{
this
.
connectedActions
.
push
(
action
);
}
}
public
async
setup
(
option
:
ChatOption
)
{
public
async
setup
(
option
:
ChatOption
)
{
if
(
!
option
)
{
if
(
!
option
)
{
throw
new
Error
(
`You must specify a chat option for chat service`
);
throw
new
Error
(
`You must specify a chat option for chat service`
);
...
@@ -63,7 +73,12 @@ class Chat {
...
@@ -63,7 +73,12 @@ class Chat {
// this.keywords = ["社保"];
// this.keywords = ["社保"];
return
this
.
initChatSdk
((
this
.
ws
=
option
.
webSocketUri
));
return
this
.
initChatSdk
((
this
.
ws
=
option
.
webSocketUri
)).
finally
(()
=>
{
this
.
connected
=
true
;
for
(
const
item
of
this
.
connectedActions
)
{
item
();
}
});
}
}
private
setupIndexDb
()
{
private
setupIndexDb
()
{
...
@@ -123,11 +138,17 @@ class Chat {
...
@@ -123,11 +138,17 @@ class Chat {
private
async
initChatSdk
(
uri
:
string
)
{
private
async
initChatSdk
(
uri
:
string
)
{
if
(
xim
.
isConnected
())
{
if
(
xim
.
isConnected
())
{
return
uri
;
return
Promise
.
resolve
(
uri
)
;
}
}
return
new
Promise
((
resolve
:
(
p
?:
unknown
)
=>
void
)
=>
{
return
new
Promise
((
resolve
)
=>
{
xim
.
open
(
uri
,
this
.
token
);
xim
.
open
(
uri
,
this
.
token
).
finally
(()
=>
{
this
.
registerXimEvent
(
resolve
);
this
.
registerXimEvent
();
if
(
xim
.
isConnected
())
{
resolve
();
}
else
{
setTimeout
(()
=>
resolve
(),
2000
);
}
});
});
});
}
}
...
...
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