|
@@ -1,8 +1,10 @@
|
|
|
import {Module} from "vuex";
|
|
|
import socket from "$utils/socket";
|
|
|
+import {MessageType} from "$utils/socket/const";
|
|
|
|
|
|
let storageData: Array<Record<string, any>> = [];
|
|
|
let storageDataArray = [];
|
|
|
+let storageQueue = undefined;
|
|
|
|
|
|
export default <Module<any,any>>{
|
|
|
|
|
@@ -17,6 +19,7 @@ export default <Module<any,any>>{
|
|
|
|
|
|
// 获取会话列表
|
|
|
setSessionList(state,data = []){
|
|
|
+
|
|
|
state.chatSessionStatus = true;
|
|
|
let newData = [];
|
|
|
let chatUserObject = [];
|
|
@@ -31,17 +34,51 @@ export default <Module<any,any>>{
|
|
|
}
|
|
|
|
|
|
if (item.latestMessage && item.latestMessage.content) {
|
|
|
+
|
|
|
+ if (item.latestMessage.content.user) {
|
|
|
+ let useUser = item.latestMessage.content.user;
|
|
|
+
|
|
|
+ if (item.targetId == useUser.id) {
|
|
|
+ item.latestMessage.content.user = {
|
|
|
+ uid:useUser.id,
|
|
|
+ nick_name:useUser.name,
|
|
|
+ head_pic:useUser.portrait,
|
|
|
+ ...useUser
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ item.latestMessage.content.user = {
|
|
|
+ uid:item.targetId,
|
|
|
+ nick_name:item.targetId,
|
|
|
+ head_pic:''
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ let content = item.latestMessage.content.content || item.latestMessage.content.message;
|
|
|
+ if (MessageType._entries.indexOf(item.latestMessage.messageType) < 0) {
|
|
|
+ content = MessageType.noSupper;
|
|
|
+ }
|
|
|
+
|
|
|
resultItem = {
|
|
|
...resultItem,
|
|
|
- message:item.latestMessage.content.message,
|
|
|
- ...((item.latestMessage.content.userInfo || {})[item.targetId] || {})
|
|
|
+ message:content,
|
|
|
+ ...(item.latestMessage.content.userInfo ? ((item.latestMessage.content.userInfo || {})[item.targetId] || {}) : item.latestMessage.content.user)
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// @ts-ignore
|
|
|
if (resultItem.uid) {
|
|
|
chatCount +=resultItem.count;
|
|
|
- chatUserObject[newData.push(resultItem) -1] = resultItem.uid;
|
|
|
+ resultItem.uid = parseInt(resultItem.uid);
|
|
|
+
|
|
|
+ let index = chatUserObject.indexOf(resultItem.uid);
|
|
|
+ if (index < 0) {
|
|
|
+ index = newData.push(resultItem) -1;
|
|
|
+ chatUserObject[index] = resultItem.uid;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
});
|
|
|
|
|
@@ -83,6 +120,8 @@ export default <Module<any,any>>{
|
|
|
state.chatUserList = [];
|
|
|
state.chatUserObject = [];
|
|
|
state.chatCount = 0;
|
|
|
+ storageData = [];
|
|
|
+ storageDataArray = [];
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -121,22 +160,47 @@ export default <Module<any,any>>{
|
|
|
object:state.chatUserObject
|
|
|
});
|
|
|
} else {
|
|
|
- socket.getConversationList({
|
|
|
- count:200,
|
|
|
- // @ts-ignore
|
|
|
- startTime:+new Date(),
|
|
|
- order:0
|
|
|
- }).then((data)=>{
|
|
|
- storageData = JSON.parse(JSON.stringify(data));
|
|
|
- storageDataArray = storageData.map((item)=>{
|
|
|
- return parseInt(item.targetId);
|
|
|
- });
|
|
|
- commit('setSessionList',data||[]);
|
|
|
- resolve({
|
|
|
- data:state.chatUserList,
|
|
|
- object:state.chatUserObject
|
|
|
+
|
|
|
+ if (storageQueue === undefined) {
|
|
|
+ storageQueue = [];
|
|
|
+ socket.getConversationList({
|
|
|
+ count:200,
|
|
|
+ // @ts-ignore
|
|
|
+ startTime:+new Date(),
|
|
|
+ order:0
|
|
|
+ }).then((data)=>{
|
|
|
+
|
|
|
+ storageData = JSON.parse(JSON.stringify(data));
|
|
|
+ storageDataArray = storageData.map((item)=>{
|
|
|
+ return parseInt(item.targetId);
|
|
|
+ });
|
|
|
+ commit('setSessionList',data||[]);
|
|
|
+
|
|
|
+ resolve({
|
|
|
+ data:state.chatUserList,
|
|
|
+ object:state.chatUserObject
|
|
|
+ });
|
|
|
+
|
|
|
+ storageQueue.map((item)=>{
|
|
|
+ item.resolve({
|
|
|
+ data:state.chatUserList,
|
|
|
+ object:state.chatUserObject
|
|
|
+ });
|
|
|
+ })
|
|
|
+
|
|
|
+ storageQueue = undefined;
|
|
|
+ }).catch(()=>{
|
|
|
+ storageQueue.map((item)=>{
|
|
|
+ item.reject();
|
|
|
+ })
|
|
|
+ storageQueue = undefined;
|
|
|
});
|
|
|
- }).catch(reject);
|
|
|
+ }
|
|
|
+ storageQueue.push({
|
|
|
+ resolve,
|
|
|
+ reject
|
|
|
+ });
|
|
|
+
|
|
|
}
|
|
|
|
|
|
});
|