Ver código fonte

会话置顶bug修复

Blue 2 anos atrás
pai
commit
aaf883b46e

+ 1 - 19
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<String,Object> redisTemplate;
-    @Override
-    public void run(ApplicationArguments args) throws Exception {
-//        String matchKey = RedisKey.IM_GROUP_READED_POSITION+"*";
-//        Set<String> keys = redisTemplate.keys(matchKey);
-//        Map<String, Map<String,Object>> 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);
-//        }
-    }
 }

+ 0 - 1
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

+ 14 - 0
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;

+ 9 - 0
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';

+ 1 - 1
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;
 						}
 						// 区分已读还是未读

+ 10 - 0
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;
 				// 滚到最低部

+ 9 - 0
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';