|
|
|
@ -1,48 +1,34 @@ |
|
|
|
import { |
|
|
|
MESSAGE_TYPE, |
|
|
|
MESSAGE_STATUS |
|
|
|
} from '@/common/enums.js'; |
|
|
|
import userStore from './userStore'; |
|
|
|
/* |
|
|
|
uniapp性能优化: |
|
|
|
1.由于uniapp渲染消息性能非常拉胯,所以先把离线消息存储到cacheChats,等 |
|
|
|
待所有离线消息拉取完成后,再统一进行渲染 |
|
|
|
2.在vuex中对数组进行unshift,splice特别卡,所以删除会话、会话置顶、删 |
|
|
|
除消息等操作进行优化,不通过unshift,splice实现,改造方案如下: |
|
|
|
删除会话: 通过delete标志判断是否删除 |
|
|
|
删除消息:通过delete标志判断是否删除 |
|
|
|
会话置顶:通过lastSendTime排序确定会话顺序 |
|
|
|
*/ |
|
|
|
import { defineStore } from 'pinia'; |
|
|
|
import { MESSAGE_TYPE, MESSAGE_STATUS } from '@/common/enums.js'; |
|
|
|
import useUserStore from './userStore'; |
|
|
|
|
|
|
|
let cacheChats = []; |
|
|
|
export default { |
|
|
|
state: { |
|
|
|
export default defineStore('chatStore', { |
|
|
|
state: () => { |
|
|
|
return { |
|
|
|
chats: [], |
|
|
|
privateMsgMaxId: 0, |
|
|
|
groupMsgMaxId: 0, |
|
|
|
loadingPrivateMsg: false, |
|
|
|
loadingGroupMsg: false, |
|
|
|
loadingGroupMsg: false |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
mutations: { |
|
|
|
initChats(state, chatsData) { |
|
|
|
actions: { |
|
|
|
initChats(chatsData) { |
|
|
|
cacheChats = []; |
|
|
|
state.chats = []; |
|
|
|
this.chats = []; |
|
|
|
for (let chat of chatsData.chats) { |
|
|
|
// 已删除的会话直接丢弃
|
|
|
|
if (chat.delete) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
// 暂存至缓冲区
|
|
|
|
chat.stored = false; |
|
|
|
cacheChats.push(JSON.parse(JSON.stringify(chat))); |
|
|
|
// 加载期间显示只前15个会话做做样子,一切都为了加快初始化时间
|
|
|
|
if (state.chats.length < 15) { |
|
|
|
if (this.chats.length < 15) { |
|
|
|
chat.messages = []; |
|
|
|
state.chats.push(chat); |
|
|
|
this.chats.push(chat); |
|
|
|
} |
|
|
|
} |
|
|
|
state.privateMsgMaxId = chatsData.privateMsgMaxId || 0; |
|
|
|
state.groupMsgMaxId = chatsData.groupMsgMaxId || 0; |
|
|
|
this.privateMsgMaxId = chatsData.privateMsgMaxId || 0; |
|
|
|
this.groupMsgMaxId = chatsData.groupMsgMaxId || 0; |
|
|
|
// 防止图片一直处在加载中状态
|
|
|
|
cacheChats.forEach((chat) => { |
|
|
|
chat.messages.forEach((msg) => { |
|
|
|
@ -52,16 +38,15 @@ export default { |
|
|
|
}) |
|
|
|
}) |
|
|
|
}, |
|
|
|
openChat(state, chatInfo) { |
|
|
|
let chats = this.getters.findChats(); |
|
|
|
openChat(chatInfo) { |
|
|
|
let chats = this.curChats; |
|
|
|
let chat = null; |
|
|
|
for (let idx in chats) { |
|
|
|
if (chats[idx].type == chatInfo.type && |
|
|
|
chats[idx].targetId === chatInfo.targetId) { |
|
|
|
chat = chats[idx]; |
|
|
|
chat.delete = false; |
|
|
|
// 放置头部
|
|
|
|
this.commit("moveTop", idx) |
|
|
|
this.moveTop(idx) |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -78,97 +63,106 @@ export default { |
|
|
|
messages: [], |
|
|
|
atMe: false, |
|
|
|
atAll: false, |
|
|
|
delete: false |
|
|
|
stored: false |
|
|
|
}; |
|
|
|
chats.push(chat); |
|
|
|
this.commit("moveTop", chats.length - 1) |
|
|
|
chats.unshift(chat); |
|
|
|
this.saveToStorage(); |
|
|
|
} |
|
|
|
}, |
|
|
|
activeChat(state, idx) { |
|
|
|
let chats = this.getters.findChats(); |
|
|
|
activeChat(idx) { |
|
|
|
let chats = this.curChats; |
|
|
|
if (idx >= 0) { |
|
|
|
chats[idx].unreadCount = 0; |
|
|
|
} |
|
|
|
}, |
|
|
|
resetUnreadCount(state, chatInfo) { |
|
|
|
let chats = this.getters.findChats(); |
|
|
|
resetUnreadCount(chatInfo) { |
|
|
|
let chats = this.curChats; |
|
|
|
for (let idx in chats) { |
|
|
|
if (chats[idx].type == chatInfo.type && |
|
|
|
chats[idx].targetId == chatInfo.targetId) { |
|
|
|
chats[idx].unreadCount = 0; |
|
|
|
chats[idx].atMe = false; |
|
|
|
chats[idx].atAll = false; |
|
|
|
chats[idx].stored = false; |
|
|
|
this.saveToStorage(); |
|
|
|
} |
|
|
|
} |
|
|
|
this.commit("saveToStorage"); |
|
|
|
|
|
|
|
}, |
|
|
|
readedMessage(state, pos) { |
|
|
|
let chats = this.getters.findChats(); |
|
|
|
for (let idx in chats) { |
|
|
|
if (chats[idx].type == 'PRIVATE' && |
|
|
|
chats[idx].targetId == pos.friendId) { |
|
|
|
chats[idx].messages.forEach((m) => { |
|
|
|
if (m.selfSend && m.status != MESSAGE_STATUS.RECALL) { |
|
|
|
readedMessage(pos) { |
|
|
|
let chat = this.findChatByFriend(pos.friendId); |
|
|
|
chat.messages.forEach((m) => { |
|
|
|
if (m.id && m.selfSend && m.status < MESSAGE_STATUS.RECALL) { |
|
|
|
// pos.maxId为空表示整个会话已读
|
|
|
|
if (!pos.maxId || m.id <= pos.maxId) { |
|
|
|
m.status = MESSAGE_STATUS.READED |
|
|
|
chat.stored = false; |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
if(!chat.stored){ |
|
|
|
this.saveToStorage(); |
|
|
|
} |
|
|
|
} |
|
|
|
this.commit("saveToStorage"); |
|
|
|
}, |
|
|
|
removeChat(state, idx) { |
|
|
|
let chats = this.getters.findChats(); |
|
|
|
removeChat(idx) { |
|
|
|
let chats = this.curChats; |
|
|
|
chats[idx].delete = true; |
|
|
|
this.commit("saveToStorage"); |
|
|
|
chats[idx].stored = false; |
|
|
|
this.saveToStorage(); |
|
|
|
}, |
|
|
|
removePrivateChat(state, userId) { |
|
|
|
let chats = this.getters.findChats(); |
|
|
|
removePrivateChat(userId) { |
|
|
|
let chats = this.curChats; |
|
|
|
for (let idx in chats) { |
|
|
|
if (chats[idx].type == 'PRIVATE' && |
|
|
|
chats[idx].targetId == userId) { |
|
|
|
this.commit("removeChat", idx); |
|
|
|
this.removeChat(idx); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
removeGroupChat(state, groupId) { |
|
|
|
let chats = this.getters.findChats(); |
|
|
|
removeGroupChat(groupId) { |
|
|
|
let chats = this.curChats; |
|
|
|
for (let idx in chats) { |
|
|
|
if (chats[idx].type == 'GROUP' && |
|
|
|
chats[idx].targetId == groupId) { |
|
|
|
this.commit("removeChat", idx); |
|
|
|
this.removeChat(idx); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
moveTop(state, idx) { |
|
|
|
let chats = this.getters.findChats(); |
|
|
|
moveTop(idx) { |
|
|
|
if (this.isLoading()) { |
|
|
|
return; |
|
|
|
} |
|
|
|
let chats = this.curChats; |
|
|
|
if (idx > 0) { |
|
|
|
let chat = chats[idx]; |
|
|
|
// 最新的时间会显示在顶部
|
|
|
|
chats.splice(idx, 1); |
|
|
|
chats.unshift(chat); |
|
|
|
chat.lastSendTime = new Date().getTime(); |
|
|
|
this.commit("saveToStorage"); |
|
|
|
chat.stored = false; |
|
|
|
this.saveToStorage(); |
|
|
|
} |
|
|
|
}, |
|
|
|
insertMessage(state, msgInfo) { |
|
|
|
insertMessage(msgInfo) { |
|
|
|
// 获取对方id或群id
|
|
|
|
let type = msgInfo.groupId ? 'GROUP' : 'PRIVATE'; |
|
|
|
// 记录消息的最大id
|
|
|
|
if (msgInfo.id && type == "PRIVATE" && msgInfo.id > state.privateMsgMaxId) { |
|
|
|
state.privateMsgMaxId = msgInfo.id; |
|
|
|
if (msgInfo.id && type == "PRIVATE" && msgInfo.id > this.privateMsgMaxId) { |
|
|
|
this.privateMsgMaxId = msgInfo.id; |
|
|
|
} |
|
|
|
if (msgInfo.id && type == "GROUP" && msgInfo.id > state.groupMsgMaxId) { |
|
|
|
state.groupMsgMaxId = msgInfo.id; |
|
|
|
if (msgInfo.id && type == "GROUP" && msgInfo.id > this.groupMsgMaxId) { |
|
|
|
this.groupMsgMaxId = msgInfo.id; |
|
|
|
} |
|
|
|
// 如果是已存在消息,则覆盖旧的消息数据
|
|
|
|
let chat = this.getters.findChat(msgInfo); |
|
|
|
let message = this.getters.findMessage(chat, msgInfo); |
|
|
|
let chat = this.findChat(msgInfo); |
|
|
|
let message = this.findMessage(chat, msgInfo); |
|
|
|
if (message) { |
|
|
|
Object.assign(message, msgInfo); |
|
|
|
// 撤回消息需要显示
|
|
|
|
if (msgInfo.type == MESSAGE_TYPE.RECALL) { |
|
|
|
chat.lastContent = msgInfo.content; |
|
|
|
} |
|
|
|
this.commit("saveToStorage"); |
|
|
|
chat.stored = false; |
|
|
|
this.saveToStorage(); |
|
|
|
return; |
|
|
|
} |
|
|
|
// 会话列表内容
|
|
|
|
@ -178,16 +172,17 @@ export default { |
|
|
|
chat.lastContent = "[文件]"; |
|
|
|
} else if (msgInfo.type == MESSAGE_TYPE.AUDIO) { |
|
|
|
chat.lastContent = "[语音]"; |
|
|
|
} else if (msgInfo.type == MESSAGE_TYPE.TEXT || msgInfo.type == MESSAGE_TYPE.RECALL) { |
|
|
|
chat.lastContent = msgInfo.content; |
|
|
|
} else if (msgInfo.type == MESSAGE_TYPE.ACT_RT_VOICE) { |
|
|
|
chat.lastContent = "[语音通话]"; |
|
|
|
} else if (msgInfo.type == MESSAGE_TYPE.ACT_RT_VIDEO) { |
|
|
|
chat.lastContent = "[视频通话]"; |
|
|
|
} else if (msgInfo.type == MESSAGE_TYPE.TEXT || |
|
|
|
msgInfo.type == MESSAGE_TYPE.RECALL || |
|
|
|
msgInfo.type == MESSAGE_TYPE.TIP_TEXT) { |
|
|
|
chat.lastContent = msgInfo.content; |
|
|
|
} |
|
|
|
chat.lastSendTime = msgInfo.sendTime; |
|
|
|
chat.sendNickName = msgInfo.sendNickName; |
|
|
|
|
|
|
|
// 未读加1
|
|
|
|
if (!msgInfo.selfSend && msgInfo.status != MESSAGE_STATUS.READED && |
|
|
|
msgInfo.type != MESSAGE_TYPE.TIP_TEXT) { |
|
|
|
@ -196,7 +191,8 @@ export default { |
|
|
|
// 是否有人@我
|
|
|
|
if (!msgInfo.selfSend && chat.type == "GROUP" && msgInfo.atUserIds && |
|
|
|
msgInfo.status != MESSAGE_STATUS.READED) { |
|
|
|
let userId = userStore.state.userInfo.id; |
|
|
|
const userStore = useUserStore(); |
|
|
|
let userId = userStore.userInfo.id; |
|
|
|
if (msgInfo.atUserIds.indexOf(userId) >= 0) { |
|
|
|
chat.atMe = true; |
|
|
|
} |
|
|
|
@ -230,70 +226,71 @@ export default { |
|
|
|
} else { |
|
|
|
chat.messages.splice(insertPos, 0, msgInfo); |
|
|
|
} |
|
|
|
this.commit("saveToStorage"); |
|
|
|
chat.stored = false; |
|
|
|
this.saveToStorage(); |
|
|
|
}, |
|
|
|
updateMessage(state, msgInfo) { |
|
|
|
updateMessage(msgInfo) { |
|
|
|
// 获取对方id或群id
|
|
|
|
let chat = this.getters.findChat(msgInfo); |
|
|
|
let message = this.getters.findMessage(chat, msgInfo); |
|
|
|
let chat = this.findChat(msgInfo); |
|
|
|
let message = this.findMessage(chat, msgInfo); |
|
|
|
if (message) { |
|
|
|
// 属性拷贝
|
|
|
|
Object.assign(message, msgInfo); |
|
|
|
this.commit("saveToStorage"); |
|
|
|
chat.stored = false; |
|
|
|
this.saveToStorage(); |
|
|
|
} |
|
|
|
}, |
|
|
|
deleteMessage(state, msgInfo) { |
|
|
|
deleteMessage(msgInfo) { |
|
|
|
// 获取对方id或群id
|
|
|
|
let chat = this.getters.findChat(msgInfo); |
|
|
|
let chat = this.findChat(msgInfo); |
|
|
|
for (let idx in chat.messages) { |
|
|
|
// 已经发送成功的,根据id删除
|
|
|
|
if (chat.messages[idx].id && chat.messages[idx].id == msgInfo.id) { |
|
|
|
chat.messages[idx].delete = true; |
|
|
|
chat.messages.splice(idx, 1); |
|
|
|
break; |
|
|
|
} |
|
|
|
// 正在发送中的消息可能没有id,根据发送时间删除
|
|
|
|
if (msgInfo.selfSend && chat.messages[idx].selfSend && |
|
|
|
chat.messages[idx].sendTime == msgInfo.sendTime) { |
|
|
|
chat.messages[idx].delete = true; |
|
|
|
chat.messages.splice(idx, 1); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
this.commit("saveToStorage"); |
|
|
|
chat.stored = false; |
|
|
|
this.saveToStorage(); |
|
|
|
}, |
|
|
|
updateChatFromFriend(state, friend) { |
|
|
|
let chats = this.getters.findChats(); |
|
|
|
for (let i in chats) { |
|
|
|
let chat = chats[i]; |
|
|
|
if (chat.type == 'PRIVATE' && chat.targetId == friend.id) { |
|
|
|
updateChatFromFriend(friend) { |
|
|
|
let chat = this.findChatByFriend(friend.id) |
|
|
|
if (chat && (chat.headImage != friend.headImageThumb || |
|
|
|
chat.showName != friend.nickName)) { |
|
|
|
// 更新会话中的群名和头像
|
|
|
|
chat.headImage = friend.headImageThumb; |
|
|
|
chat.showName = friend.nickName; |
|
|
|
break; |
|
|
|
} |
|
|
|
chat.stored = false; |
|
|
|
this.saveToStorage(); |
|
|
|
} |
|
|
|
this.commit("saveToStorage"); |
|
|
|
}, |
|
|
|
updateChatFromGroup(state, group) { |
|
|
|
let chats = this.getters.findChats(); |
|
|
|
for (let i in chats) { |
|
|
|
let chat = chats[i]; |
|
|
|
if (chat.type == 'GROUP' && chat.targetId == group.id) { |
|
|
|
updateChatFromGroup(group) { |
|
|
|
let chat = this.findChatByGroup(group.id); |
|
|
|
if (chat && (chat.headImage != group.headImageThumb || |
|
|
|
chat.showName != group.showGroupName)) { |
|
|
|
// 更新会话中的群名称和头像
|
|
|
|
chat.headImage = group.headImageThumb; |
|
|
|
chat.showName = group.showGroupName; |
|
|
|
break; |
|
|
|
chat.stored = false; |
|
|
|
this.saveToStorage(); |
|
|
|
} |
|
|
|
} |
|
|
|
this.commit("saveToStorage"); |
|
|
|
}, |
|
|
|
loadingPrivateMsg(state, loading) { |
|
|
|
state.loadingPrivateMsg = loading; |
|
|
|
if (!this.getters.isLoading()) { |
|
|
|
this.commit("refreshChats") |
|
|
|
setLoadingPrivateMsg(loading) { |
|
|
|
this.loadingPrivateMsg = loading; |
|
|
|
if (!this.isLoading()) { |
|
|
|
this.refreshChats() |
|
|
|
} |
|
|
|
}, |
|
|
|
loadingGroupMsg(state, loading) { |
|
|
|
state.loadingGroupMsg = loading; |
|
|
|
if (!this.getters.isLoading()) { |
|
|
|
this.commit("refreshChats") |
|
|
|
setLoadingGroupMsg(loading) { |
|
|
|
this.loadingGroupMsg = loading; |
|
|
|
if (!this.isLoading()) { |
|
|
|
this.refreshChats() |
|
|
|
} |
|
|
|
}, |
|
|
|
refreshChats(state) { |
|
|
|
@ -302,51 +299,70 @@ export default { |
|
|
|
return chat2.lastSendTime - chat1.lastSendTime; |
|
|
|
}); |
|
|
|
// 将消息一次性装载回来
|
|
|
|
state.chats = cacheChats; |
|
|
|
this.chats = cacheChats; |
|
|
|
// 断线重连后不能使用缓存模式,否则会导致聊天窗口的消息不刷新
|
|
|
|
cacheChats = state.chats; |
|
|
|
this.commit("saveToStorage"); |
|
|
|
cacheChats = this.chats; |
|
|
|
this.saveToStorage(); |
|
|
|
}, |
|
|
|
saveToStorage(state) { |
|
|
|
// 加载中不保存,防止卡顿
|
|
|
|
if (this.getters.isLoading()) { |
|
|
|
if (this.isLoading()) { |
|
|
|
return; |
|
|
|
} |
|
|
|
let userId = userStore.state.userInfo.id; |
|
|
|
const userStore = useUserStore(); |
|
|
|
let userId = userStore.userInfo.id; |
|
|
|
let key = "chats-app-" + userId; |
|
|
|
let chatsData = { |
|
|
|
privateMsgMaxId: state.privateMsgMaxId, |
|
|
|
groupMsgMaxId: state.groupMsgMaxId, |
|
|
|
chats: state.chats |
|
|
|
let chatKeys = []; |
|
|
|
// 按会话为单位存储,只存储有改动的会话
|
|
|
|
this.chats.forEach((chat)=>{ |
|
|
|
let chatKey = `${key}-${chat.type}-${chat.targetId}` |
|
|
|
if(!chat.stored){ |
|
|
|
if(chat.delete){ |
|
|
|
uni.removeStorageSync(chatKey); |
|
|
|
}else{ |
|
|
|
uni.setStorageSync(chatKey,chat); |
|
|
|
} |
|
|
|
chat.stored = true; |
|
|
|
} |
|
|
|
if(!chat.delete){ |
|
|
|
chatKeys.push(chatKey); |
|
|
|
} |
|
|
|
uni.setStorage({ |
|
|
|
key: key, |
|
|
|
data: chatsData , |
|
|
|
}) |
|
|
|
// 会话核心信息
|
|
|
|
let chatsData = { |
|
|
|
privateMsgMaxId: this.privateMsgMaxId, |
|
|
|
groupMsgMaxId: this.groupMsgMaxId, |
|
|
|
chatKeys: chatKeys |
|
|
|
} |
|
|
|
uni.setStorageSync(key, chatsData) |
|
|
|
}, |
|
|
|
clear(state) { |
|
|
|
cacheChats = []; |
|
|
|
state.chats = []; |
|
|
|
state.privateMsgMaxId = 0; |
|
|
|
state.groupMsgMaxId = 0; |
|
|
|
state.loadingPrivateMsg = false; |
|
|
|
state.loadingGroupMsg = false; |
|
|
|
} |
|
|
|
this.chats = []; |
|
|
|
this.privateMsgMaxId = 0; |
|
|
|
this.groupMsgMaxId = 0; |
|
|
|
this.loadingPrivateMsg = false; |
|
|
|
this.loadingGroupMsg = false; |
|
|
|
}, |
|
|
|
actions: { |
|
|
|
loadChat(context) { |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
let userId = userStore.state.userInfo.id; |
|
|
|
uni.getStorage({ |
|
|
|
key: "chats-app-" + userId, |
|
|
|
success(res) { |
|
|
|
context.commit("initChats", res.data); |
|
|
|
resolve() |
|
|
|
}, |
|
|
|
fail(e) { |
|
|
|
resolve() |
|
|
|
let userStore = useUserStore(); |
|
|
|
let userId = userStore.userInfo.id; |
|
|
|
let chatsData = uni.getStorageSync("chats-app-" + userId) |
|
|
|
if(chatsData){ |
|
|
|
if(chatsData.chatKeys){ |
|
|
|
let time = new Date().getTime(); |
|
|
|
chatsData.chats = []; |
|
|
|
chatsData.chatKeys.forEach(key=>{ |
|
|
|
let chat = uni.getStorageSync(key); |
|
|
|
if(chat){ |
|
|
|
chatsData.chats.push(chat); |
|
|
|
} |
|
|
|
}); |
|
|
|
}) |
|
|
|
} |
|
|
|
this.initChats(chatsData); |
|
|
|
} |
|
|
|
resolve() |
|
|
|
}) |
|
|
|
} |
|
|
|
}, |
|
|
|
@ -354,11 +370,11 @@ export default { |
|
|
|
isLoading: (state) => () => { |
|
|
|
return state.loadingPrivateMsg || state.loadingGroupMsg |
|
|
|
}, |
|
|
|
findChats: (state, getters) => () => { |
|
|
|
return getters.isLoading() ? cacheChats : state.chats; |
|
|
|
curChats: (state) => { |
|
|
|
return state.isLoading() ? cacheChats : state.chats; |
|
|
|
}, |
|
|
|
findChatIdx: (state, getters) => (chat) => { |
|
|
|
let chats = getters.findChats(); |
|
|
|
findChatIdx: (state) => (chat) => { |
|
|
|
let chats = state.curChats; |
|
|
|
for (let idx in chats) { |
|
|
|
if (chats[idx].type == chat.type && |
|
|
|
chats[idx].targetId === chat.targetId) { |
|
|
|
@ -367,11 +383,12 @@ export default { |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
findChat: (state, getters) => (msgInfo) => { |
|
|
|
let chats = getters.findChats(); |
|
|
|
findChat: (state) => (msgInfo) => { |
|
|
|
let chats = state.curChats; |
|
|
|
// 获取对方id或群id
|
|
|
|
let type = msgInfo.groupId ? 'GROUP' : 'PRIVATE'; |
|
|
|
let targetId = msgInfo.groupId ? msgInfo.groupId : msgInfo.selfSend ? msgInfo.recvId : msgInfo.sendId; |
|
|
|
let targetId = msgInfo.groupId ? msgInfo.groupId : msgInfo.selfSend ? msgInfo.recvId : msgInfo |
|
|
|
.sendId; |
|
|
|
let chat = null; |
|
|
|
for (let idx in chats) { |
|
|
|
if (chats[idx].type == type && |
|
|
|
@ -382,6 +399,14 @@ export default { |
|
|
|
} |
|
|
|
return chat; |
|
|
|
}, |
|
|
|
findChatByFriend: (state) => (fid) => { |
|
|
|
return state.curChats.find(chat => chat.type == 'PRIVATE' && |
|
|
|
chat.targetId == fid) |
|
|
|
}, |
|
|
|
findChatByGroup: (state) => (gid) => { |
|
|
|
return state.curChats.find(chat => chat.type == 'GROUP' && |
|
|
|
chat.targetId == gid) |
|
|
|
}, |
|
|
|
findMessage: (state) => (chat, msgInfo) => { |
|
|
|
if (!chat) { |
|
|
|
return null; |
|
|
|
@ -394,10 +419,9 @@ export default { |
|
|
|
// 正在发送中的消息可能没有id,只有tmpId
|
|
|
|
if (msgInfo.tmpId && chat.messages[idx].tmpId && |
|
|
|
chat.messages[idx].tmpId == msgInfo.tmpId) { |
|
|
|
console.log("chat.messages[idx].tmpId == msgInfo.tmpId") |
|
|
|
return chat.messages[idx]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |