Browse Source

支持删除和撤回消息

master
xie.bx 3 years ago
parent
commit
999e883b77
  1. 2
      im-platform/src/main/java/com/bx/implatform/service/impl/GroupMessageServiceImpl.java
  2. 2
      im-platform/src/main/java/com/bx/implatform/service/impl/PrivateMessageServiceImpl.java
  3. 72
      im-ui/src/components/chat/ChatBox.vue
  4. 24
      im-ui/src/store/chatStore.js

2
im-platform/src/main/java/com/bx/implatform/service/impl/GroupMessageServiceImpl.java

@ -109,7 +109,7 @@ public class GroupMessageServiceImpl extends ServiceImpl<GroupMessageMapper, Gro
String content = String.format("'%s'撤回了一条消息",member.getAliasName());
msgInfo.setContent(content);
this.sendMessage(userIds,msgInfo);
log.info("删除群聊消息,发送id:{},群聊id:{},内容:{}",userId,msg.getGroupId(),msg.getContent());
log.info("撤回群聊消息,发送id:{},群聊id:{},内容:{}",userId,msg.getGroupId(),msg.getContent());
}

2
im-platform/src/main/java/com/bx/implatform/service/impl/PrivateMessageServiceImpl.java

@ -97,7 +97,7 @@ public class PrivateMessageServiceImpl extends ServiceImpl<PrivateMessageMapper,
msgInfo.setContent("对方撤回了一条消息");
redisTemplate.opsForList().rightPush(sendKey,msgInfo);
}
log.info("删除私聊消息,发送id:{},接收id:{},内容:{}",msg.getSendId(),msg.getRecvId(),msg.getContent());
log.info("撤回私聊消息,发送id:{},接收id:{},内容:{}",msg.getSendId(),msg.getRecvId(),msg.getContent());
}
/**

72
im-ui/src/components/chat/ChatBox.vue

@ -97,39 +97,23 @@
}
},
methods: {
handleImageSuccess(res, file) {
let msgInfo = {
recvId: file.raw.targetId,
content: JSON.stringify(res.data),
type: 1
}
// id
this.setTargetId(msgInfo, this.chat.targetId);
let msgInfo = JSON.parse(JSON.stringify(file.raw.msgInfo));
msgInfo.content = JSON.stringify(res.data);
this.$http({
url: this.messageAction,
method: 'post',
data: msgInfo
}).then((id) => {
let info = {
type: this.chat.type,
targetId: file.raw.targetId,
msgId : id,
fileId: file.raw.uid,
content: JSON.stringify(res.data),
loadStatus: "ok"
}
this.$store.commit("handleFileUpload", info);
msgInfo.loadStatus = 'ok';
msgInfo.id = id;
this.$store.commit("insertMessage", msgInfo);
})
},
handleImageFail(res, file) {
let info = {
type: this.chat.type,
targetId: file.raw.targetId,
fileId: file.raw.uid,
loadStatus: "fail"
}
this.$store.commit("handleFileUpload", info);
let msgInfo = JSON.parse(JSON.stringify(file.raw.msgInfo));
msgInfo.loadStatus = 'fail';
this.$store.commit("insertMessage", msgInfo);
},
handleImageBefore(file) {
let url = URL.createObjectURL(file);
@ -153,8 +137,8 @@
this.$store.commit("insertMessage", msgInfo);
//
this.scrollToBottom();
// fileid
file.targetId = this.chat.targetId;
// file
file.msgInfo = msgInfo;
},
handleFileSuccess(res, file) {
let data = {
@ -162,36 +146,22 @@
size: file.size,
url: res.data
}
let msgInfo = {
content: JSON.stringify(data),
type: 2
}
// id
this.setTargetId(msgInfo, this.chat.targetId);
let msgInfo = JSON.parse(JSON.stringify(file.raw.msgInfo));
msgInfo.content = JSON.stringify(data);
this.$http({
url: this.messageAction,
method: 'post',
data: msgInfo
}).then((id) => {
let info = {
type: this.chat.type,
targetId: file.raw.targetId,
fileId: file.raw.uid,
msgId : id,
content: JSON.stringify(data),
loadStatus: "ok"
}
this.$store.commit("handleFileUpload", info);
msgInfo.loadStatus = 'ok';
msgInfo.id = id;
this.$store.commit("insertMessage", msgInfo);
})
},
handleFileFail(res, file) {
let info = {
type: this.chat.type,
targetId: file.raw.targetId,
fileId: file.raw.uid,
loadStatus: "fail"
}
this.$store.commit("handleFileUpload", info);
let msgInfo = JSON.parse(JSON.stringify(file.raw.msgInfo));
msgInfo.loadStatus = 'fail';
this.$store.commit("insertMessage", msgInfo);
},
handleFileBefore(file) {
let url = URL.createObjectURL(file);
@ -202,7 +172,6 @@
}
let msgInfo = {
id: 0,
fileId: file.uid,
sendId: this.mine.id,
content: JSON.stringify(data),
sendTime: new Date().getTime(),
@ -216,8 +185,8 @@
this.$store.commit("insertMessage", msgInfo);
//
this.scrollToBottom();
// file
file.targetId = this.chat.targetId;
// file
file.msgInfo = msgInfo;
},
handleCloseSide() {
this.showSide = false;
@ -413,7 +382,6 @@
messageAction() {
return `/message/${this.chat.type.toLowerCase()}/send`;
}
},
watch: {
chat: {

24
im-ui/src/store/chatStore.js

@ -100,13 +100,18 @@ export default {
if(msgInfo.selfSend){
chat.unreadCount=0;
}
console.log(msgInfo);
// 如果是已存在消息,则覆盖旧的消息数据
for (let idx in chat.messages) {
if(msgInfo.id && chat.messages[idx].id == msgInfo.id){
Object.assign(chat.messages[idx], msgInfo);
return;
}
// 正在发送中的消息可能没有id,通过发送时间判断
if(msgInfo.selfSend && chat.messages[idx].selfSend
&& chat.messages[idx].sendTime == msgInfo.sendTime){
Object.assign(chat.messages[idx], msgInfo);
return;
}
}
// 新的消息
chat.messages.push(msgInfo);
@ -131,25 +136,14 @@ export default {
chat.messages.splice(idx, 1);
break;
}
// 没有发送成功的,根据发送时间删除
if(!chat.messages[idx].id && chat.messages[idx].sendTime == msgInfo.sendTime){
// 正在发送中的消息可能没有id,根据发送时间删除
if(msgInfo.selfSend && chat.messages[idx].selfSend
&&chat.messages[idx].sendTime == msgInfo.sendTime){
chat.messages.splice(idx, 1);
break;
}
}
},
handleFileUpload(state, info) {
// 文件上传后数据更新
let chat = state.chats.find((c) => c.type==info.type && c.targetId === info.targetId);
let msg = chat.messages.find((m) => info.fileId == m.fileId);
msg.loadStatus = info.loadStatus;
if (info.content) {
msg.content = info.content;
}
if(info.msgId){
msg.id = info.msgId;
}
},
updateChatFromFriend(state, friend) {
for (let i in state.chats) {
let chat = state.chats[i];

Loading…
Cancel
Save