Browse Source

用户封禁和群封禁增加提示语

master
xsx 1 year ago
parent
commit
3634be2f55
  1. 6
      im-platform/src/main/java/com/bx/implatform/vo/GroupVO.java
  2. 5
      im-platform/src/main/java/com/bx/implatform/vo/UserVO.java
  3. 10
      im-uniapp/App.vue
  4. 12
      im-uniapp/components/chat-group-readed/chat-group-readed.vue
  5. 71
      im-uniapp/pages/chat/chat-box.vue
  6. 35
      im-uniapp/store/chatStore.js
  7. 75
      im-web/src/components/chat/ChatBox.vue
  8. 2
      im-web/src/components/chat/ChatInput.vue
  9. 35
      im-web/src/store/chatStore.js
  10. 5
      im-web/src/view/Home.vue

6
im-platform/src/main/java/com/bx/implatform/vo/GroupVO.java

@ -50,5 +50,11 @@ public class GroupVO {
@Schema(description = "是否已退出") @Schema(description = "是否已退出")
private Boolean quit; private Boolean quit;
@Schema(description = "账号是否被封禁")
private Boolean isBanned;
@Schema(description = "被封禁原因")
private String reason;
} }

5
im-platform/src/main/java/com/bx/implatform/vo/UserVO.java

@ -43,4 +43,9 @@ public class UserVO {
@Schema(description = "是否在线") @Schema(description = "是否在线")
private Boolean online; private Boolean online;
@Schema(description = "账号是否被封禁")
private Boolean isBanned;
@Schema(description = "被封禁原因")
private String reason;
} }

10
im-uniapp/App.vue

@ -169,7 +169,7 @@ export default {
// //
this.chatStore.openChat(chatInfo); this.chatStore.openChat(chatInfo);
// //
this.chatStore.insertMessage(msg); this.chatStore.insertMessage(msg, chatInfo);
// //
this.playAudioTip(); this.playAudioTip();
@ -192,6 +192,10 @@ export default {
} }
// //
if (msg.type == enums.MESSAGE_TYPE.RECEIPT) { if (msg.type == enums.MESSAGE_TYPE.RECEIPT) {
let chatInfo = {
type: 'GROUP',
targetId: msg.groupId
}
// //
let msgInfo = { let msgInfo = {
id: msg.id, id: msg.id,
@ -199,7 +203,7 @@ export default {
readedCount: msg.readedCount, readedCount: msg.readedCount,
receiptOk: msg.receiptOk receiptOk: msg.receiptOk
}; };
this.chatStore.updateMessage(msgInfo) this.chatStore.updateMessage(msgInfo,chatInfo)
return; return;
} }
// //
@ -259,7 +263,7 @@ export default {
// //
this.chatStore.openChat(chatInfo); this.chatStore.openChat(chatInfo);
// //
this.chatStore.insertMessage(msg); this.chatStore.insertMessage(msg, chatInfo);
// //
this.playAudioTip(); this.playAudioTip();
}, },

12
im-uniapp/components/chat-group-readed/chat-group-readed.vue

@ -79,12 +79,18 @@ export default {
}) })
this.items[0] = `已读(${this.readedMembers.length})`; this.items[0] = `已读(${this.readedMembers.length})`;
this.items[1] = `未读(${this.unreadMembers.length})`; this.items[1] = `未读(${this.unreadMembers.length})`;
//
this.chatStore.updateMessage({ let chatInfo = {
type: 'GROUP',
targetId: this.msgInfo.groupId
}
let msgInfo = {
id: this.msgInfo.id, id: this.msgInfo.id,
groupId: this.msgInfo.groupId, groupId: this.msgInfo.groupId,
readedCount: this.readedMembers.length readedCount: this.readedMembers.length
}) }
//
this.chatStore.updateMessage(msgInfo, chatInfo)
}) })
}, },
onClickItem(e) { onClickItem(e) {

71
im-uniapp/pages/chat/chat-box.vue

@ -155,6 +155,11 @@ export default {
this.switchChatTabBox('none'); this.switchChatTabBox('none');
}, },
onSendRecord(data) { onSendRecord(data) {
//
if (this.isBanned) {
this.showBannedTip();
return;
}
let msgInfo = { let msgInfo = {
content: JSON.stringify(data), content: JSON.stringify(data),
type: this.$enums.MESSAGE_TYPE.AUDIO, type: this.$enums.MESSAGE_TYPE.AUDIO,
@ -164,7 +169,7 @@ export default {
this.fillTargetId(msgInfo, this.chat.targetId); this.fillTargetId(msgInfo, this.chat.targetId);
this.sendMessageRequest(msgInfo).then((m) => { this.sendMessageRequest(msgInfo).then((m) => {
m.selfSend = true; m.selfSend = true;
this.chatStore.insertMessage(m); this.chatStore.insertMessage(m, this.chat);
// //
this.moveChatToTop(); this.moveChatToTop();
// //
@ -260,6 +265,17 @@ export default {
sendTextMessage() { sendTextMessage() {
this.editorCtx.getContents({ this.editorCtx.getContents({
success: (e) => { success: (e) => {
//
this.editorCtx.clear();
this.atUserIds = [];
this.isReceipt = false;
//
if (this.isBanned) {
this.showBannedTip();
return;
}
let sendText = this.isReceipt ? "【回执消息】" : ""; let sendText = this.isReceipt ? "【回执消息】" : "";
e.delta.ops.forEach((op) => { e.delta.ops.forEach((op) => {
if (op.insert.image) { if (op.insert.image) {
@ -286,6 +302,7 @@ export default {
} }
// id // id
this.fillTargetId(msgInfo, this.chat.targetId); this.fillTargetId(msgInfo, this.chat.targetId);
this.sendMessageRequest(msgInfo).then((m) => { this.sendMessageRequest(msgInfo).then((m) => {
m.selfSend = true; m.selfSend = true;
this.chatStore.insertMessage(m, this.chat); this.chatStore.insertMessage(m, this.chat);
@ -294,10 +311,6 @@ export default {
}).finally(() => { }).finally(() => {
// //
this.scrollToBottom(); this.scrollToBottom();
//
this.atUserIds = [];
this.isReceipt = false;
this.editorCtx.clear();
}); });
} }
}) })
@ -379,6 +392,11 @@ export default {
}) })
}, },
onUploadImageBefore(file) { onUploadImageBefore(file) {
//
if (this.isBanned) {
this.showBannedTip();
return;
}
let data = { let data = {
originUrl: file.path, originUrl: file.path,
thumbUrl: file.path thumbUrl: file.path
@ -399,7 +417,7 @@ export default {
// id // id
this.fillTargetId(msgInfo, this.chat.targetId); this.fillTargetId(msgInfo, this.chat.targetId);
// //
this.chatStore.insertMessage(msgInfo); this.chatStore.insertMessage(msgInfo, this.chat);
// //
this.moveChatToTop(); this.moveChatToTop();
// file // file
@ -416,15 +434,20 @@ export default {
msgInfo.loadStatus = 'ok'; msgInfo.loadStatus = 'ok';
msgInfo.id = m.id; msgInfo.id = m.id;
this.isReceipt = false; this.isReceipt = false;
this.chatStore.insertMessage(msgInfo); this.chatStore.insertMessage(msgInfo, this.chat);
}) })
}, },
onUploadImageFail(file, err) { onUploadImageFail(file, err) {
let msgInfo = JSON.parse(JSON.stringify(file.msgInfo)); let msgInfo = JSON.parse(JSON.stringify(file.msgInfo));
msgInfo.loadStatus = 'fail'; msgInfo.loadStatus = 'fail';
this.chatStore.insertMessage(msgInfo); this.chatStore.insertMessage(msgInfo, this.chat);
}, },
onUploadFileBefore(file) { onUploadFileBefore(file) {
//
if (this.isBanned) {
this.showBannedTip();
return;
}
let data = { let data = {
name: file.name, name: file.name,
size: file.size, size: file.size,
@ -445,7 +468,7 @@ export default {
// id // id
this.fillTargetId(msgInfo, this.chat.targetId); this.fillTargetId(msgInfo, this.chat.targetId);
// //
this.chatStore.insertMessage(msgInfo); this.chatStore.insertMessage(msgInfo, this.chat);
// //
this.moveChatToTop(); this.moveChatToTop();
// file // file
@ -467,13 +490,13 @@ export default {
msgInfo.loadStatus = 'ok'; msgInfo.loadStatus = 'ok';
msgInfo.id = m.id; msgInfo.id = m.id;
this.isReceipt = false; this.isReceipt = false;
this.chatStore.insertMessage(msgInfo); this.chatStore.insertMessage(msgInfo, this.chat);
}) })
}, },
onUploadFileFail(file, res) { onUploadFileFail(file, res) {
let msgInfo = JSON.parse(JSON.stringify(file.msgInfo)); let msgInfo = JSON.parse(JSON.stringify(file.msgInfo));
msgInfo.loadStatus = 'fail'; msgInfo.loadStatus = 'fail';
this.chatStore.insertMessage(msgInfo); this.chatStore.insertMessage(msgInfo, this.chat);
}, },
onDeleteMessage(msgInfo) { onDeleteMessage(msgInfo) {
uni.showModal({ uni.showModal({
@ -481,7 +504,7 @@ export default {
content: '确认删除消息?', content: '确认删除消息?',
success: (res) => { success: (res) => {
if (!res.cancel) { if (!res.cancel) {
this.chatStore.deleteMessage(msgInfo); this.chatStore.deleteMessage(msgInfo, this.chat);
uni.showToast({ uni.showToast({
title: "删除成功", title: "删除成功",
icon: "none" icon: "none"
@ -505,7 +528,7 @@ export default {
msgInfo.type = this.$enums.MESSAGE_TYPE.RECALL; msgInfo.type = this.$enums.MESSAGE_TYPE.RECALL;
msgInfo.content = '你撤回了一条消息'; msgInfo.content = '你撤回了一条消息';
msgInfo.status = this.$enums.MESSAGE_STATUS.RECALL; msgInfo.status = this.$enums.MESSAGE_STATUS.RECALL;
this.chatStore.insertMessage(msgInfo); this.chatStore.insertMessage(msgInfo, this.chat);
}) })
} }
} }
@ -697,6 +720,22 @@ export default {
}); });
// #endif // #endif
}, },
showBannedTip() {
let msgInfo = {
tmpId: this.generateId(),
sendId: this.mine.id,
sendTime: new Date().getTime(),
type: this.$enums.MESSAGE_TYPE.TIP_TEXT
}
if (this.chat.type == "PRIVATE") {
msgInfo.recvId = this.mine.id
msgInfo.content = "该用户已被管理员封禁,原因:" + this.friend.reason
} else {
msgInfo.groupId = this.group.id;
msgInfo.content = "本群聊已被管理员封禁,原因:" + this.group.reason
}
this.chatStore.insertMessage(msgInfo, this.chat);
},
reCalChatMainHeight() { reCalChatMainHeight() {
const sysInfo = uni.getSystemInfoSync(); const sysInfo = uni.getSystemInfoSync();
let h = sysInfo.windowHeight; let h = sysInfo.windowHeight;
@ -753,6 +792,10 @@ export default {
} }
return this.chat.unreadCount; return this.chat.unreadCount;
}, },
isBanned() {
return (this.chat.type == "PRIVATE" && this.friend.isBanned) ||
(this.chat.type == "GROUP" && this.group.isBanned)
},
atUserItems() { atUserItems() {
let atUsers = []; let atUsers = [];
this.atUserIds.forEach((id) => { this.atUserIds.forEach((id) => {
@ -815,7 +858,7 @@ export default {
// //
this.listenKeyBoard(); this.listenKeyBoard();
// //
this.$nextTick(()=>this.reCalChatMainHeight()) this.$nextTick(() => this.reCalChatMainHeight())
}, },
onShow() { onShow() {
if (this.needScrollToBottom) { if (this.needScrollToBottom) {

35
im-uniapp/store/chatStore.js

@ -141,9 +141,9 @@ export default defineStore('chatStore', {
this.saveToStorage(); this.saveToStorage();
} }
}, },
insertMessage(msgInfo) { insertMessage(msgInfo, chatInfo) {
// 获取对方id或群id // 获取对方id或群id
let type = msgInfo.groupId ? 'GROUP' : 'PRIVATE'; let type = chatInfo.type;
// 记录消息的最大id // 记录消息的最大id
if (msgInfo.id && type == "PRIVATE" && msgInfo.id > this.privateMsgMaxId) { if (msgInfo.id && type == "PRIVATE" && msgInfo.id > this.privateMsgMaxId) {
this.privateMsgMaxId = msgInfo.id; this.privateMsgMaxId = msgInfo.id;
@ -152,7 +152,7 @@ export default defineStore('chatStore', {
this.groupMsgMaxId = msgInfo.id; this.groupMsgMaxId = msgInfo.id;
} }
// 如果是已存在消息,则覆盖旧的消息数据 // 如果是已存在消息,则覆盖旧的消息数据
let chat = this.findChat(msgInfo); let chat = this.findChat(chatInfo);
let message = this.findMessage(chat, msgInfo); let message = this.findMessage(chat, msgInfo);
if (message) { if (message) {
Object.assign(message, msgInfo); Object.assign(message, msgInfo);
@ -228,9 +228,9 @@ export default defineStore('chatStore', {
chat.stored = false; chat.stored = false;
this.saveToStorage(); this.saveToStorage();
}, },
updateMessage(msgInfo) { updateMessage(msgInfo, chatInfo) {
// 获取对方id或群id // 获取对方id或群id
let chat = this.findChat(msgInfo); let chat = this.findChat(chatInfo);
let message = this.findMessage(chat, msgInfo); let message = this.findMessage(chat, msgInfo);
if (message) { if (message) {
// 属性拷贝 // 属性拷贝
@ -239,9 +239,9 @@ export default defineStore('chatStore', {
this.saveToStorage(); this.saveToStorage();
} }
}, },
deleteMessage(msgInfo) { deleteMessage(msgInfo, chatInfo) {
// 获取对方id或群id // 获取对方id或群id
let chat = this.findChat(msgInfo); let chat = this.findChat(chatInfo);
for (let idx in chat.messages) { for (let idx in chat.messages) {
// 已经发送成功的,根据id删除 // 已经发送成功的,根据id删除
if (chat.messages[idx].id && chat.messages[idx].id == msgInfo.id) { if (chat.messages[idx].id && chat.messages[idx].id == msgInfo.id) {
@ -261,7 +261,7 @@ export default defineStore('chatStore', {
updateChatFromFriend(friend) { updateChatFromFriend(friend) {
let chat = this.findChatByFriend(friend.id) let chat = this.findChatByFriend(friend.id)
if (chat && (chat.headImage != friend.headImageThumb || if (chat && (chat.headImage != friend.headImageThumb ||
chat.showName != friend.nickName)) { chat.showName != friend.nickName)) {
// 更新会话中的群名和头像 // 更新会话中的群名和头像
chat.headImage = friend.headImageThumb; chat.headImage = friend.headImageThumb;
chat.showName = friend.nickName; chat.showName = friend.nickName;
@ -272,7 +272,7 @@ export default defineStore('chatStore', {
updateChatFromGroup(group) { updateChatFromGroup(group) {
let chat = this.findChatByGroup(group.id); let chat = this.findChatByGroup(group.id);
if (chat && (chat.headImage != group.headImageThumb || if (chat && (chat.headImage != group.headImageThumb ||
chat.showName != group.showGroupName)) { chat.showName != group.showGroupName)) {
// 更新会话中的群名称和头像 // 更新会话中的群名称和头像
chat.headImage = group.headImageThumb; chat.headImage = group.headImageThumb;
chat.showName = group.showGroupName; chat.showName = group.showGroupName;
@ -390,21 +390,10 @@ export default defineStore('chatStore', {
} }
} }
}, },
findChat: (state) => (msgInfo) => { findChat: (state) => (chat) => {
let chats = state.curChats; let chats = state.curChats;
// 获取对方id或群id let idx = state.findChatIdx(chat);
let type = msgInfo.groupId ? 'GROUP' : 'PRIVATE'; return chats[idx];
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 &&
chats[idx].targetId === targetId) {
chat = chats[idx];
break;
}
}
return chat;
}, },
findChatByFriend: (state) => (fid) => { findChatByFriend: (state) => (fid) => {
return state.curChats.find(chat => chat.type == 'PRIVATE' && return state.curChats.find(chat => chat.type == 'PRIVATE' &&

75
im-web/src/components/chat/ChatBox.vue

@ -161,15 +161,20 @@ export default {
msgInfo.loadStatus = 'ok'; msgInfo.loadStatus = 'ok';
msgInfo.id = m.id; msgInfo.id = m.id;
this.isReceipt = false; this.isReceipt = false;
this.$store.commit("insertMessage", msgInfo); this.$store.commit("insertMessage", [msgInfo, this.chat]);
}) })
}, },
onImageFail(e, file) { onImageFail(e, file) {
let msgInfo = JSON.parse(JSON.stringify(file.msgInfo)); let msgInfo = JSON.parse(JSON.stringify(file.msgInfo));
msgInfo.loadStatus = 'fail'; msgInfo.loadStatus = 'fail';
this.$store.commit("insertMessage", msgInfo); this.$store.commit("insertMessage", [msgInfo, this.chat]);
}, },
onImageBefore(file) { onImageBefore(file) {
//
if (this.isBanned) {
this.showBannedTip();
return;
}
let url = URL.createObjectURL(file); let url = URL.createObjectURL(file);
let data = { let data = {
originUrl: url, originUrl: url,
@ -191,7 +196,7 @@ export default {
// id // id
this.fillTargetId(msgInfo, this.chat.targetId); this.fillTargetId(msgInfo, this.chat.targetId);
// //
this.$store.commit("insertMessage", msgInfo); this.$store.commit("insertMessage", [msgInfo, this.chat]);
// //
this.moveChatToTop(); this.moveChatToTop();
// //
@ -213,15 +218,20 @@ export default {
msgInfo.id = m.id; msgInfo.id = m.id;
this.isReceipt = false; this.isReceipt = false;
this.refreshPlaceHolder(); this.refreshPlaceHolder();
this.$store.commit("insertMessage", msgInfo); this.$store.commit("insertMessage", [msgInfo, this.chat]);
}) })
}, },
onFileFail(e, file) { onFileFail(e, file) {
let msgInfo = JSON.parse(JSON.stringify(file.msgInfo)); let msgInfo = JSON.parse(JSON.stringify(file.msgInfo));
msgInfo.loadStatus = 'fail'; msgInfo.loadStatus = 'fail';
this.$store.commit("insertMessage", msgInfo); this.$store.commit("insertMessage", [msgInfo, this.chat]);
}, },
onFileBefore(file) { onFileBefore(file) {
//
if (this.isBanned) {
this.showBannedTip();
return;
}
let url = URL.createObjectURL(file); let url = URL.createObjectURL(file);
let data = { let data = {
name: file.name, name: file.name,
@ -243,7 +253,7 @@ export default {
// id // id
this.fillTargetId(msgInfo, this.chat.targetId); this.fillTargetId(msgInfo, this.chat.targetId);
// //
this.$store.commit("insertMessage", msgInfo); this.$store.commit("insertMessage", [msgInfo, this.chat]);
// //
this.moveChatToTop(); this.moveChatToTop();
// //
@ -285,6 +295,12 @@ export default {
this.showRecord = false; this.showRecord = false;
}, },
showPrivateVideo(mode) { showPrivateVideo(mode) {
//
if (this.isBanned) {
this.showBannedTip();
return;
}
let rtcInfo = { let rtcInfo = {
mode: mode, mode: mode,
isHost: true, isHost: true,
@ -294,6 +310,11 @@ export default {
this.$eventBus.$emit("openPrivateVideo", rtcInfo); this.$eventBus.$emit("openPrivateVideo", rtcInfo);
}, },
onGroupVideo() { onGroupVideo() {
//
if (this.isBanned) {
this.showBannedTip();
return;
}
// //
let ids = [this.mine.id]; let ids = [this.mine.id];
let maxChannel = this.$store.state.configStore.webrtc.maxChannel; let maxChannel = this.$store.state.configStore.webrtc.maxChannel;
@ -329,6 +350,11 @@ export default {
this.showHistory = false; this.showHistory = false;
}, },
onSendRecord(data) { onSendRecord(data) {
//
if (this.isBanned) {
this.showBannedTip();
return;
}
let msgInfo = { let msgInfo = {
content: JSON.stringify(data), content: JSON.stringify(data),
type: 3, type: 3,
@ -338,7 +364,7 @@ export default {
this.fillTargetId(msgInfo, this.chat.targetId); this.fillTargetId(msgInfo, this.chat.targetId);
this.sendMessageRequest(msgInfo).then((m) => { this.sendMessageRequest(msgInfo).then((m) => {
m.selfSend = true; m.selfSend = true;
this.$store.commit("insertMessage", m); this.$store.commit("insertMessage", [m, this.chat]);
// //
this.moveChatToTop(); this.moveChatToTop();
// //
@ -364,6 +390,11 @@ export default {
async sendMessage(fullList) { async sendMessage(fullList) {
this.resetEditor(); this.resetEditor();
this.readedMessage(); this.readedMessage();
//
if (this.isBanned) {
this.showBannedTip();
return;
}
let sendText = this.isReceipt ? "【回执消息】" : ""; let sendText = this.isReceipt ? "【回执消息】" : "";
let promiseList = []; let promiseList = [];
for (let i = 0; i < fullList.length; i++) { for (let i = 0; i < fullList.length; i++) {
@ -421,7 +452,7 @@ export default {
this.lockMessage = true; this.lockMessage = true;
this.sendMessageRequest(msgInfo).then((m) => { this.sendMessageRequest(msgInfo).then((m) => {
m.selfSend = true; m.selfSend = true;
this.$store.commit("insertMessage", m); this.$store.commit("insertMessage", [m, this.chat]);
// //
this.moveChatToTop(); this.moveChatToTop();
}).finally(() => { }).finally(() => {
@ -465,7 +496,7 @@ export default {
msgInfo.type = 10; msgInfo.type = 10;
msgInfo.content = '你撤回了一条消息'; msgInfo.content = '你撤回了一条消息';
msgInfo.status = this.$enums.MESSAGE_STATUS.RECALL; msgInfo.status = this.$enums.MESSAGE_STATUS.RECALL;
this.$store.commit("insertMessage", msgInfo); this.$store.commit("insertMessage", [msgInfo, this.chat]);
}) })
}); });
}, },
@ -482,7 +513,7 @@ export default {
this.$http({ this.$http({
url: url, url: url,
method: 'put' method: 'put'
}).then(() => { }) }).then(() => {})
}, },
loadReaded(fId) { loadReaded(fId) {
this.$http({ this.$http({
@ -588,6 +619,22 @@ export default {
}) })
} }
}, },
showBannedTip() {
let msgInfo = {
tmpId: this.generateId(),
sendId: this.mine.id,
sendTime: new Date().getTime(),
type: this.$enums.MESSAGE_TYPE.TIP_TEXT
}
if (this.chat.type == "PRIVATE") {
msgInfo.recvId = this.mine.id
msgInfo.content = "该用户已被管理员封禁,原因:" + this.friend.reason
} else {
msgInfo.groupId = this.group.id;
msgInfo.content = "本群聊已被管理员封禁,原因:" + this.group.reason
}
this.$store.commit("insertMessage", [msgInfo, this.chat]);
},
generateId() { generateId() {
// id // id
return String(new Date().getTime()) + String(Math.floor(Math.random() * 1000)); return String(new Date().getTime()) + String(Math.floor(Math.random() * 1000));
@ -616,13 +663,17 @@ export default {
return 0; return 0;
} }
return this.chat.messages.length; return this.chat.messages.length;
},
isBanned() {
return (this.chat.type == "PRIVATE" && this.friend.isBanned) ||
(this.chat.type == "GROUP" && this.group.isBanned)
} }
}, },
watch: { watch: {
chat: { chat: {
handler(newChat, oldChat) { handler(newChat, oldChat) {
if (newChat.targetId > 0 && (!oldChat || newChat.type != oldChat.type || if (newChat.targetId > 0 && (!oldChat || newChat.type != oldChat.type ||
newChat.targetId != oldChat.targetId)) { newChat.targetId != oldChat.targetId)) {
if (this.chat.type == "GROUP") { if (this.chat.type == "GROUP") {
this.loadGroup(this.chat.targetId); this.loadGroup(this.chat.targetId);
} else { } else {
@ -831,4 +882,4 @@ export default {
} }
} }
</style> </style>

2
im-web/src/components/chat/ChatInput.vue

@ -443,7 +443,7 @@ export default {
if (node.dataset.id) { if (node.dataset.id) {
tempText += node.innerHTML; tempText += node.innerHTML;
atUserIds.push(node.dataset.id) atUserIds.push(node.dataset.id)
} else { } else if(node.outerHtml) {
tempText += node.outerHtml; tempText += node.outerHtml;
} }
} }

35
im-web/src/store/chatStore.js

@ -137,8 +137,8 @@ export default {
this.commit("saveToStorage"); this.commit("saveToStorage");
} }
}, },
insertMessage(state, msgInfo) { insertMessage(state, [msgInfo, chatInfo]) {
let type = msgInfo.groupId ? 'GROUP' : 'PRIVATE'; let type = chatInfo.type;
// 记录消息的最大id // 记录消息的最大id
if (msgInfo.id && type == "PRIVATE" && msgInfo.id > state.privateMsgMaxId) { if (msgInfo.id && type == "PRIVATE" && msgInfo.id > state.privateMsgMaxId) {
state.privateMsgMaxId = msgInfo.id; state.privateMsgMaxId = msgInfo.id;
@ -147,7 +147,7 @@ export default {
state.groupMsgMaxId = msgInfo.id; state.groupMsgMaxId = msgInfo.id;
} }
// 如果是已存在消息,则覆盖旧的消息数据 // 如果是已存在消息,则覆盖旧的消息数据
let chat = this.getters.findChat(msgInfo); let chat = this.getters.findChat(chatInfo);
let message = this.getters.findMessage(chat, msgInfo); let message = this.getters.findMessage(chat, msgInfo);
if (message) { if (message) {
Object.assign(message, msgInfo); Object.assign(message, msgInfo);
@ -178,7 +178,8 @@ export default {
chat.lastSendTime = msgInfo.sendTime; chat.lastSendTime = msgInfo.sendTime;
chat.sendNickName = msgInfo.sendNickName; chat.sendNickName = msgInfo.sendNickName;
// 未读加1 // 未读加1
if (!msgInfo.selfSend && msgInfo.status != MESSAGE_STATUS.READED && msgInfo.type != MESSAGE_TYPE.TIP_TEXT) { if (!msgInfo.selfSend && msgInfo.status != MESSAGE_STATUS.READED &&
msgInfo.type != MESSAGE_TYPE.TIP_TEXT) {
chat.unreadCount++; chat.unreadCount++;
} }
// 是否有人@我 // 是否有人@我
@ -216,9 +217,9 @@ export default {
chat.stored = false; chat.stored = false;
this.commit("saveToStorage"); this.commit("saveToStorage");
}, },
updateMessage(state, msgInfo) { updateMessage(state, [msgInfo, chatInfo]) {
// 获取对方id或群id // 获取对方id或群id
let chat = this.getters.findChat(msgInfo); let chat = this.getters.findChat(chatInfo);
let message = this.getters.findMessage(chat, msgInfo); let message = this.getters.findMessage(chat, msgInfo);
if (message) { if (message) {
// 属性拷贝 // 属性拷贝
@ -227,8 +228,8 @@ export default {
this.commit("saveToStorage"); this.commit("saveToStorage");
} }
}, },
deleteMessage(state, msgInfo) { deleteMessage(state, [msgInfo, chatInfo]) {
let chat = this.getters.findChat(msgInfo); let chat = this.getters.findChat(chatInfo);
for (let idx in chat.messages) { for (let idx in chat.messages) {
// 已经发送成功的,根据id删除 // 已经发送成功的,根据id删除
if (chat.messages[idx].id && chat.messages[idx].id == msgInfo.id) { if (chat.messages[idx].id && chat.messages[idx].id == msgInfo.id) {
@ -289,7 +290,7 @@ export default {
}); });
// 将消息一次性装载回来 // 将消息一次性装载回来
state.chats = cacheChats; state.chats = cacheChats;
// 清空缓存,不再使用 // 清空缓存
cacheChats = null; cacheChats = null;
this.commit("saveToStorage"); this.commit("saveToStorage");
}, },
@ -384,20 +385,10 @@ export default {
} }
} }
}, },
findChat: (state, getters) => (msgInfo) => { findChat: (state, getters) => (chat) => {
let chats = getters.findChats(); let chats = getters.findChats();
// 获取对方id或群id let idx = getters.findChatIdx(chat);
let type = msgInfo.groupId ? 'GROUP' : 'PRIVATE'; return chats[idx];
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 &&
chats[idx].targetId === targetId) {
chat = chats[idx];
break;
}
}
return chat;
}, },
findChatByFriend: (state, getters) => (fid) => { findChatByFriend: (state, getters) => (fid) => {
let chats = getters.findChats(); let chats = getters.findChats();

5
im-web/src/view/Home.vue

@ -201,7 +201,7 @@ export default {
// //
this.$store.commit("openChat", chatInfo); this.$store.commit("openChat", chatInfo);
// //
this.$store.commit("insertMessage", msg); this.$store.commit("insertMessage", [msg, chatInfo]);
// //
if (!msg.selfSend && this.$msgType.isNormal(msg.type) && if (!msg.selfSend && this.$msgType.isNormal(msg.type) &&
msg.status != this.$enums.MESSAGE_STATUS.READED) { msg.status != this.$enums.MESSAGE_STATUS.READED) {
@ -251,7 +251,6 @@ export default {
}) })
}, },
insertGroupMessage(group, msg) { insertGroupMessage(group, msg) {
let chatInfo = { let chatInfo = {
type: 'GROUP', type: 'GROUP',
targetId: group.id, targetId: group.id,
@ -261,7 +260,7 @@ export default {
// //
this.$store.commit("openChat", chatInfo); this.$store.commit("openChat", chatInfo);
// //
this.$store.commit("insertMessage", msg); this.$store.commit("insertMessage", [msg, chatInfo]);
// //
if (!msg.selfSend && msg.type <= this.$enums.MESSAGE_TYPE.VIDEO && if (!msg.selfSend && msg.type <= this.$enums.MESSAGE_TYPE.VIDEO &&
msg.status != this.$enums.MESSAGE_STATUS.READED) { msg.status != this.$enums.MESSAGE_STATUS.READED) {

Loading…
Cancel
Save