|
|
@ -78,7 +78,9 @@ export default { |
|
|
showSettingDialog: false, |
|
|
showSettingDialog: false, |
|
|
lastPlayAudioTime: new Date().getTime() - 1000, |
|
|
lastPlayAudioTime: new Date().getTime() - 1000, |
|
|
isFullscreen: true, |
|
|
isFullscreen: true, |
|
|
reconnecting: false |
|
|
reconnecting: false, |
|
|
|
|
|
privateMessagesBuffer: [], |
|
|
|
|
|
groupMessagesBuffer: [] |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
methods: { |
|
|
methods: { |
|
|
@ -108,8 +110,7 @@ export default { |
|
|
this.onReconnectWs(); |
|
|
this.onReconnectWs(); |
|
|
} else { |
|
|
} else { |
|
|
// 加载离线消息 |
|
|
// 加载离线消息 |
|
|
this.pullPrivateOfflineMessage(this.chatStore.privateMsgMaxId); |
|
|
this.pullOfflineMessage(); |
|
|
this.pullGroupOfflineMessage(this.chatStore.groupMsgMaxId); |
|
|
|
|
|
this.configStore.setAppInit(true); |
|
|
this.configStore.setAppInit(true); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
@ -126,11 +127,21 @@ export default { |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
} else if (cmd == 3) { |
|
|
} else if (cmd == 3) { |
|
|
// 插入私聊消息 |
|
|
if (!this.configStore.appInit || this.chatStore.loading) { |
|
|
this.handlePrivateMessage(msgInfo); |
|
|
// 如果正在拉取离线消息,先放进缓存区,等待消息拉取完成再处理,防止消息乱序 |
|
|
|
|
|
this.privateMessagesBuffer.push(msgInfo); |
|
|
|
|
|
} else { |
|
|
|
|
|
// 插入私聊消息 |
|
|
|
|
|
this.handlePrivateMessage(msgInfo); |
|
|
|
|
|
} |
|
|
} else if (cmd == 4) { |
|
|
} else if (cmd == 4) { |
|
|
// 插入群聊消息 |
|
|
if (!this.configStore.appInit || this.chatStore.loading) { |
|
|
this.handleGroupMessage(msgInfo); |
|
|
// 如果正在拉取离线消息,先放进缓存区,等待消息拉取完成再处理,防止消息乱序 |
|
|
|
|
|
this.groupMessagesBuffer.push(msgInfo); |
|
|
|
|
|
} else { |
|
|
|
|
|
// 插入群聊消息 |
|
|
|
|
|
this.handleGroupMessage(msgInfo); |
|
|
|
|
|
} |
|
|
} else if (cmd == 5) { |
|
|
} else if (cmd == 5) { |
|
|
// 处理系统消息 |
|
|
// 处理系统消息 |
|
|
this.handleSystemMessage(msgInfo); |
|
|
this.handleSystemMessage(msgInfo); |
|
|
@ -170,8 +181,7 @@ export default { |
|
|
promises.push(this.groupStore.loadGroup()); |
|
|
promises.push(this.groupStore.loadGroup()); |
|
|
Promise.all(promises).then(() => { |
|
|
Promise.all(promises).then(() => { |
|
|
// 加载离线消息 |
|
|
// 加载离线消息 |
|
|
this.pullPrivateOfflineMessage(this.chatStore.privateMsgMaxId); |
|
|
this.pullOfflineMessage(); |
|
|
this.pullGroupOfflineMessage(this.chatStore.groupMsgMaxId); |
|
|
|
|
|
this.configStore.setAppInit(true) |
|
|
this.configStore.setAppInit(true) |
|
|
this.$message.success("重新连接成功"); |
|
|
this.$message.success("重新连接成功"); |
|
|
}).catch(() => { |
|
|
}).catch(() => { |
|
|
@ -194,23 +204,42 @@ export default { |
|
|
this.groupStore.clear(); |
|
|
this.groupStore.clear(); |
|
|
this.chatStore.clear(); |
|
|
this.chatStore.clear(); |
|
|
this.userStore.clear(); |
|
|
this.userStore.clear(); |
|
|
|
|
|
}, |
|
|
|
|
|
pullOfflineMessage() { |
|
|
|
|
|
this.chatStore.setLoading(true); |
|
|
|
|
|
const promises = []; |
|
|
|
|
|
promises.push(this.pullPrivateOfflineMessage(this.chatStore.privateMsgMaxId)); |
|
|
|
|
|
promises.push(this.pullGroupOfflineMessage(this.chatStore.groupMsgMaxId)); |
|
|
|
|
|
Promise.all(promises).then(messages => { |
|
|
|
|
|
// 处理离线消息 |
|
|
|
|
|
messages[0].forEach(m => this.handlePrivateMessage(m)); |
|
|
|
|
|
messages[1].forEach(m => this.handleGroupMessage(m)); |
|
|
|
|
|
// 处理缓冲区收到的实时消息 |
|
|
|
|
|
this.privateMessagesBuffer.forEach(m => this.handlePrivateMessage(m)); |
|
|
|
|
|
this.groupMessagesBuffer.forEach(m => this.handleGroupMessage(m)); |
|
|
|
|
|
// 清空缓冲区 |
|
|
|
|
|
this.privateMessagesBuffer = []; |
|
|
|
|
|
this.groupMessagesBuffer = []; |
|
|
|
|
|
// 关闭加载离线标记 |
|
|
|
|
|
this.chatStore.setLoading(false); |
|
|
|
|
|
// 刷新会话 |
|
|
|
|
|
this.chatStore.refreshChats(); |
|
|
|
|
|
}).catch((e) => { |
|
|
|
|
|
console.log(e) |
|
|
|
|
|
this.$message.error("拉取离线消息失败"); |
|
|
|
|
|
this.onExit(); |
|
|
|
|
|
}) |
|
|
}, |
|
|
}, |
|
|
pullPrivateOfflineMessage(minId) { |
|
|
pullPrivateOfflineMessage(minId) { |
|
|
this.chatStore.setLoadingPrivateMsg(true) |
|
|
return this.$http({ |
|
|
this.$http({ |
|
|
url: "/message/private/loadOfflineMessage?minId=" + minId, |
|
|
url: "/message/private/pullOfflineMessage?minId=" + minId, |
|
|
|
|
|
method: 'GET' |
|
|
method: 'GET' |
|
|
}).catch(() => { |
|
|
|
|
|
this.chatStore.setLoadingPrivateMsg(false) |
|
|
|
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
pullGroupOfflineMessage(minId) { |
|
|
pullGroupOfflineMessage(minId) { |
|
|
this.chatStore.setLoadingGroupMsg(true) |
|
|
return this.$http({ |
|
|
this.$http({ |
|
|
url: "/message/group/loadOfflineMessage?minId=" + minId, |
|
|
url: "/message/group/pullOfflineMessage?minId=" + minId, |
|
|
|
|
|
method: 'GET' |
|
|
method: 'GET' |
|
|
}).catch(() => { |
|
|
|
|
|
this.chatStore.setLoadingGroupMsg(false) |
|
|
|
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
handlePrivateMessage(msg) { |
|
|
handlePrivateMessage(msg) { |
|
|
@ -223,11 +252,6 @@ export default { |
|
|
type: 'PRIVATE', |
|
|
type: 'PRIVATE', |
|
|
targetId: friendId |
|
|
targetId: friendId |
|
|
} |
|
|
} |
|
|
// 消息加载标志 |
|
|
|
|
|
if (msg.type == this.$enums.MESSAGE_TYPE.LOADING) { |
|
|
|
|
|
this.chatStore.setLoadingPrivateMsg(JSON.parse(msg.content)) |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
// 消息已读处理,清空已读数量 |
|
|
// 消息已读处理,清空已读数量 |
|
|
if (msg.type == this.$enums.MESSAGE_TYPE.READED) { |
|
|
if (msg.type == this.$enums.MESSAGE_TYPE.READED) { |
|
|
this.chatStore.resetUnreadCount(chatInfo) |
|
|
this.chatStore.resetUnreadCount(chatInfo) |
|
|
@ -285,7 +309,7 @@ export default { |
|
|
// 插入消息 |
|
|
// 插入消息 |
|
|
this.chatStore.insertMessage(msg, chatInfo); |
|
|
this.chatStore.insertMessage(msg, chatInfo); |
|
|
// 播放提示音 |
|
|
// 播放提示音 |
|
|
if (!friend.isDnd && !this.chatStore.isLoading() && !msg.selfSend && this.$msgType.isNormal(msg.type) && |
|
|
if (!friend.isDnd && !this.chatStore.loading && !msg.selfSend && this.$msgType.isNormal(msg.type) && |
|
|
msg.status != this.$enums.MESSAGE_STATUS.READED) { |
|
|
msg.status != this.$enums.MESSAGE_STATUS.READED) { |
|
|
this.playAudioTip(); |
|
|
this.playAudioTip(); |
|
|
} |
|
|
} |
|
|
@ -297,11 +321,6 @@ export default { |
|
|
type: 'GROUP', |
|
|
type: 'GROUP', |
|
|
targetId: msg.groupId |
|
|
targetId: msg.groupId |
|
|
} |
|
|
} |
|
|
// 消息加载标志 |
|
|
|
|
|
if (msg.type == this.$enums.MESSAGE_TYPE.LOADING) { |
|
|
|
|
|
this.chatStore.setLoadingGroupMsg(JSON.parse(msg.content)) |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
// 消息已读处理 |
|
|
// 消息已读处理 |
|
|
if (msg.type == this.$enums.MESSAGE_TYPE.READED) { |
|
|
if (msg.type == this.$enums.MESSAGE_TYPE.READED) { |
|
|
// 我已读对方的消息,清空已读数量 |
|
|
// 我已读对方的消息,清空已读数量 |
|
|
@ -367,7 +386,7 @@ export default { |
|
|
// 插入消息 |
|
|
// 插入消息 |
|
|
this.chatStore.insertMessage(msg, chatInfo); |
|
|
this.chatStore.insertMessage(msg, chatInfo); |
|
|
// 播放提示音 |
|
|
// 播放提示音 |
|
|
if (!group.isDnd && !this.chatStore.isLoading() && |
|
|
if (!group.isDnd && !this.chatStore.loading && |
|
|
!msg.selfSend && this.$msgType.isNormal(msg.type) |
|
|
!msg.selfSend && this.$msgType.isNormal(msg.type) |
|
|
&& msg.status != this.$enums.MESSAGE_STATUS.READED) { |
|
|
&& msg.status != this.$enums.MESSAGE_STATUS.READED) { |
|
|
this.playAudioTip(); |
|
|
this.playAudioTip(); |
|
|
|