|
|
@ -6,7 +6,7 @@ import userStore from './userStore'; |
|
|
export default { |
|
|
export default { |
|
|
|
|
|
|
|
|
state: { |
|
|
state: { |
|
|
activeIndex: -1, |
|
|
activeChat: null, |
|
|
privateMsgMaxId: 0, |
|
|
privateMsgMaxId: 0, |
|
|
groupMsgMaxId: 0, |
|
|
groupMsgMaxId: 0, |
|
|
loadingPrivateMsg: false, |
|
|
loadingPrivateMsg: false, |
|
|
@ -30,14 +30,12 @@ export default { |
|
|
}, |
|
|
}, |
|
|
openChat(state, chatInfo) { |
|
|
openChat(state, chatInfo) { |
|
|
let chat = null; |
|
|
let chat = null; |
|
|
let activeChat = state.activeIndex >= 0 ? state.chats[state.activeIndex] : null; |
|
|
for (let idx in state.chats) { |
|
|
for (let i in state.chats) { |
|
|
if (state.chats[idx].type == chatInfo.type && |
|
|
if (state.chats[i].type == chatInfo.type && |
|
|
state.chats[idx].targetId === chatInfo.targetId) { |
|
|
state.chats[i].targetId === chatInfo.targetId) { |
|
|
chat = state.chats[idx]; |
|
|
chat = state.chats[i]; |
|
|
|
|
|
// 放置头部
|
|
|
// 放置头部
|
|
|
state.chats.splice(i, 1); |
|
|
this.commit("moveTop", idx) |
|
|
state.chats.unshift(chat); |
|
|
|
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -55,18 +53,9 @@ export default { |
|
|
}; |
|
|
}; |
|
|
state.chats.unshift(chat); |
|
|
state.chats.unshift(chat); |
|
|
} |
|
|
} |
|
|
// 选中会话保持不变
|
|
|
|
|
|
if (activeChat) { |
|
|
|
|
|
state.chats.forEach((chat, idx) => { |
|
|
|
|
|
if (activeChat.type == chat.type && |
|
|
|
|
|
activeChat.targetId == chat.targetId) { |
|
|
|
|
|
state.activeIndex = idx; |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
}, |
|
|
activeChat(state, idx) { |
|
|
activeChat(state, idx) { |
|
|
state.activeIndex = idx; |
|
|
state.activeChat = state.chats[idx]; |
|
|
}, |
|
|
}, |
|
|
resetUnreadCount(state, chatInfo) { |
|
|
resetUnreadCount(state, chatInfo) { |
|
|
for (let idx in state.chats) { |
|
|
for (let idx in state.chats) { |
|
|
@ -93,18 +82,23 @@ export default { |
|
|
this.commit("saveToStorage"); |
|
|
this.commit("saveToStorage"); |
|
|
}, |
|
|
}, |
|
|
removeChat(state, idx) { |
|
|
removeChat(state, idx) { |
|
|
state.chats.splice(idx, 1); |
|
|
if (state.chats[idx] == state.activeChat) { |
|
|
if (state.activeIndex >= state.chats.length) { |
|
|
state.activeChat = null; |
|
|
state.activeIndex = state.chats.length - 1; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
state.chats.splice(idx, 1); |
|
|
this.commit("saveToStorage"); |
|
|
this.commit("saveToStorage"); |
|
|
}, |
|
|
}, |
|
|
moveTop(state, idx) { |
|
|
moveTop(state, idx) { |
|
|
let chat = state.chats[idx]; |
|
|
// 加载中不移动,很耗性能
|
|
|
// 放置头部
|
|
|
if(state.loadingPrivateMsg || state.loadingGroupMsg){ |
|
|
state.chats.splice(idx, 1); |
|
|
return ; |
|
|
state.chats.unshift(chat); |
|
|
} |
|
|
this.commit("saveToStorage"); |
|
|
if (idx > 0) { |
|
|
|
|
|
let chat = state.chats[idx]; |
|
|
|
|
|
state.chats.splice(idx, 1); |
|
|
|
|
|
state.chats.unshift(chat); |
|
|
|
|
|
this.commit("saveToStorage"); |
|
|
|
|
|
} |
|
|
}, |
|
|
}, |
|
|
removeGroupChat(state, groupId) { |
|
|
removeGroupChat(state, groupId) { |
|
|
for (let idx in state.chats) { |
|
|
for (let idx in state.chats) { |
|
|
@ -131,6 +125,7 @@ export default { |
|
|
if (state.chats[idx].type == type && |
|
|
if (state.chats[idx].type == type && |
|
|
state.chats[idx].targetId === targetId) { |
|
|
state.chats[idx].targetId === targetId) { |
|
|
chat = state.chats[idx]; |
|
|
chat = state.chats[idx]; |
|
|
|
|
|
this.commit("moveTop", idx) |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -151,13 +146,13 @@ export default { |
|
|
chat.unreadCount++; |
|
|
chat.unreadCount++; |
|
|
} |
|
|
} |
|
|
// 是否有人@我
|
|
|
// 是否有人@我
|
|
|
if(!msgInfo.selfSend && chat.type=="GROUP" && msgInfo.atUserIds |
|
|
if (!msgInfo.selfSend && chat.type == "GROUP" && msgInfo.atUserIds && |
|
|
&& msgInfo.status != MESSAGE_STATUS.READED){ |
|
|
msgInfo.status != MESSAGE_STATUS.READED) { |
|
|
let userId = userStore.state.userInfo.id; |
|
|
let userId = userStore.state.userInfo.id; |
|
|
if(msgInfo.atUserIds.indexOf(userId)>=0){ |
|
|
if (msgInfo.atUserIds.indexOf(userId) >= 0) { |
|
|
chat.atMe = true; |
|
|
chat.atMe = true; |
|
|
} |
|
|
} |
|
|
if(msgInfo.atUserIds.indexOf(-1)>=0){ |
|
|
if (msgInfo.atUserIds.indexOf(-1) >= 0) { |
|
|
chat.atAll = true; |
|
|
chat.atAll = true; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -248,9 +243,18 @@ export default { |
|
|
|
|
|
|
|
|
loadingPrivateMsg(state, loadding) { |
|
|
loadingPrivateMsg(state, loadding) { |
|
|
state.loadingPrivateMsg = loadding; |
|
|
state.loadingPrivateMsg = loadding; |
|
|
|
|
|
if(!state.loadingPrivateMsg && !state.loadingGroupMsg){ |
|
|
|
|
|
this.commit("sort") |
|
|
|
|
|
} |
|
|
}, |
|
|
}, |
|
|
loadingGroupMsg(state, loadding) { |
|
|
loadingGroupMsg(state, loadding) { |
|
|
state.loadingGroupMsg = loadding; |
|
|
state.loadingGroupMsg = loadding; |
|
|
|
|
|
if(!state.loadingPrivateMsg && !state.loadingGroupMsg){ |
|
|
|
|
|
this.commit("sort") |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
sort(state){ |
|
|
|
|
|
state.chats.sort((c1,c2)=>c2.lastSendTime-c1.lastSendTime); |
|
|
}, |
|
|
}, |
|
|
saveToStorage(state) { |
|
|
saveToStorage(state) { |
|
|
let userId = userStore.state.userInfo.id; |
|
|
let userId = userStore.state.userInfo.id; |
|
|
@ -263,7 +267,7 @@ export default { |
|
|
localStorage.setItem(key, JSON.stringify(chatsData)); |
|
|
localStorage.setItem(key, JSON.stringify(chatsData)); |
|
|
}, |
|
|
}, |
|
|
clear(state) { |
|
|
clear(state) { |
|
|
state.activeIndex = -1; |
|
|
state.activeChat = null; |
|
|
state.chats = []; |
|
|
state.chats = []; |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
|