From aaf883b46edae2b1d93cf911d196700b3cf12aa7 Mon Sep 17 00:00:00 2001 From: Blue <825657193@qq.com> Date: Fri, 26 Jan 2024 00:35:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=9A=E8=AF=9D=E7=BD=AE=E9=A1=B6bug?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/bx/implatform/IMPlatformApp.java | 20 +------------------ .../src/main/resources/application.yml | 1 - im-ui/src/components/chat/ChatBox.vue | 14 +++++++++++++ im-ui/src/store/chatStore.js | 9 +++++++++ .../chat-group-readed/chat-group-readed.vue | 2 +- im-uniapp/pages/chat/chat-box.vue | 10 ++++++++++ im-uniapp/store/chatStore.js | 9 +++++++++ 7 files changed, 44 insertions(+), 21 deletions(-) diff --git a/im-platform/src/main/java/com/bx/implatform/IMPlatformApp.java b/im-platform/src/main/java/com/bx/implatform/IMPlatformApp.java index 6f094cf..e2aabee 100644 --- a/im-platform/src/main/java/com/bx/implatform/IMPlatformApp.java +++ b/im-platform/src/main/java/com/bx/implatform/IMPlatformApp.java @@ -22,28 +22,10 @@ import java.util.Set; @EnableAspectJAutoProxy(exposeProxy = true) @MapperScan(basePackages = {"com.bx.implatform.mapper"}) @SpringBootApplication(exclude = {SecurityAutoConfiguration.class})// 禁用secrity -public class IMPlatformApp implements ApplicationRunner { +public class IMPlatformApp { public static void main(String[] args) { SpringApplication.run(IMPlatformApp.class, args); } - @Autowired - private RedisTemplate redisTemplate; - @Override - public void run(ApplicationArguments args) throws Exception { -// String matchKey = RedisKey.IM_GROUP_READED_POSITION+"*"; -// Set keys = redisTemplate.keys(matchKey); -// Map> map = new HashMap<>(); -// for(String key:keys){ -// String[] arr = key.split(":"); -// String groupId = arr[4]; -// String userId = arr[5]; -// Object messageId = redisTemplate.opsForValue().get(key); -// String newKey = StrUtil.join(":",RedisKey.IM_GROUP_READED_POSITION,groupId); -// redisTemplate.opsForHash().put(newKey,userId,messageId); -// redisTemplate.delete(key); -// log.info("key:{},value:{}",newKey,messageId); -// } - } } diff --git a/im-platform/src/main/resources/application.yml b/im-platform/src/main/resources/application.yml index eddde6f..b195ce1 100644 --- a/im-platform/src/main/resources/application.yml +++ b/im-platform/src/main/resources/application.yml @@ -16,7 +16,6 @@ spring: host: 127.0.0.1 port: 6379 - servlet: multipart: max-file-size: 50MB diff --git a/im-ui/src/components/chat/ChatBox.vue b/im-ui/src/components/chat/ChatBox.vue index 6d0472d..93af571 100644 --- a/im-ui/src/components/chat/ChatBox.vue +++ b/im-ui/src/components/chat/ChatBox.vue @@ -131,6 +131,11 @@ export default { } }, methods: { + moveChatToTop(){ + let chatIdx = this.$store.getters.findChatIdx(this.chat); + console.log(chatIdx); + this.$store.commit("moveTop",chatIdx); + }, closeRefBox() { this.$refs.emoBox.close(); this.$refs.atBox.close(); @@ -320,6 +325,8 @@ export default { this.fillTargetId(msgInfo, this.chat.targetId); // 插入消息 this.$store.commit("insertMessage", msgInfo); + // 会话置顶 + this.moveChatToTop(); // 滚动到底部 this.scrollToBottom(); // 借助file对象保存 @@ -372,6 +379,8 @@ export default { this.fillTargetId(msgInfo, this.chat.targetId); // 插入消息 this.$store.commit("insertMessage", msgInfo); + // 会话置顶 + this.moveChatToTop(); // 滚动到底部 this.scrollToBottom(); // 借助file对象透传 @@ -456,6 +465,8 @@ export default { msgInfo.status = this.$enums.MESSAGE_STATUS.UNSEND; msgInfo.readedCount = 0; this.$store.commit("insertMessage", msgInfo); + // 会话置顶 + this.moveChatToTop(); // 保持输入框焦点 this.$refs.editBox.focus(); // 滚动到底部 @@ -463,6 +474,7 @@ export default { // 关闭录音窗口 this.showVoice = false; this.isReceipt = false; + }) }, fillTargetId(msgInfo, targetId) { @@ -530,6 +542,8 @@ export default { msgInfo.readedCount = 0; msgInfo.status = this.$enums.MESSAGE_STATUS.UNSEND; this.$store.commit("insertMessage", msgInfo); + // 会话置顶 + this.moveChatToTop(); }).finally(() => { // 解除锁定 this.lockMessage = false; diff --git a/im-ui/src/store/chatStore.js b/im-ui/src/store/chatStore.js index ede92f0..6a5fa04 100644 --- a/im-ui/src/store/chatStore.js +++ b/im-ui/src/store/chatStore.js @@ -273,6 +273,15 @@ export default { } }, getters: { + findChatIdx: (state) => (chat) => { + for (let idx in state.chats) { + if (state.chats[idx].type == chat.type && + state.chats[idx].targetId === chat.targetId) { + chat = state.chats[idx]; + return idx + } + } + }, findChat: (state) => (msgInfo) => { // 获取对方id或群id let type = msgInfo.groupId ? 'GROUP' : 'PRIVATE'; diff --git a/im-uniapp/components/chat-group-readed/chat-group-readed.vue b/im-uniapp/components/chat-group-readed/chat-group-readed.vue index cca2587..6b7452f 100644 --- a/im-uniapp/components/chat-group-readed/chat-group-readed.vue +++ b/im-uniapp/components/chat-group-readed/chat-group-readed.vue @@ -66,7 +66,7 @@ }).then(userIds => { this.groupMembers.forEach(member => { // 发送者和已退群的不显示 - if (member.userId == this.msgInfo.sendId && member.quit) { + if (member.userId == this.msgInfo.sendId || member.quit) { return; } // 区分已读还是未读 diff --git a/im-uniapp/pages/chat/chat-box.vue b/im-uniapp/pages/chat/chat-box.vue index 7a0c21a..34cf110 100644 --- a/im-uniapp/pages/chat/chat-box.vue +++ b/im-uniapp/pages/chat/chat-box.vue @@ -118,6 +118,10 @@ icon: "none" }) }, + moveChatToTop(){ + let chatIdx = this.$store.getters.findChatIdx(this.chat); + this.$store.commit("moveTop",chatIdx); + }, switchReceipt(){ this.isReceipt = !this.isReceipt; }, @@ -179,6 +183,8 @@ msgInfo.readedCount = 0, msgInfo.status = this.$enums.MESSAGE_STATUS.UNSEND; this.$store.commit("insertMessage", msgInfo); + // 会话置顶 + this.moveChatToTop(); this.sendText = ""; }).finally(() => { // 滚动到底部 @@ -275,6 +281,8 @@ this.fillTargetId(msgInfo, this.chat.targetId); // 插入消息 this.$store.commit("insertMessage", msgInfo); + // 会话置顶 + this.moveChatToTop(); // 借助file对象保存 file.msgInfo = msgInfo; // 滚到最低部 @@ -322,6 +330,8 @@ this.fillTargetId(msgInfo, this.chat.targetId); // 插入消息 this.$store.commit("insertMessage", msgInfo); + // 会话置顶 + this.moveChatToTop(); // 借助file对象保存 file.msgInfo = msgInfo; // 滚到最低部 diff --git a/im-uniapp/store/chatStore.js b/im-uniapp/store/chatStore.js index 0155b3d..9d026a2 100644 --- a/im-uniapp/store/chatStore.js +++ b/im-uniapp/store/chatStore.js @@ -309,6 +309,15 @@ export default { } }, getters: { + findChatIdx: (state) => (chat) => { + for (let idx in state.chats) { + if (state.chats[idx].type == chat.type && + state.chats[idx].targetId === chat.targetId) { + chat = state.chats[idx]; + return idx; + } + } + }, findChat: (state) => (msgInfo) => { // 获取对方id或群id let type = msgInfo.groupId ? 'GROUP' : 'PRIVATE';