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 ffb8898..6f094cf 100644 --- a/im-platform/src/main/java/com/bx/implatform/IMPlatformApp.java +++ b/im-platform/src/main/java/com/bx/implatform/IMPlatformApp.java @@ -1,19 +1,49 @@ package com.bx.implatform; +import cn.hutool.core.util.StrUtil; +import com.bx.implatform.contant.RedisKey; import lombok.extern.slf4j.Slf4j; import org.mybatis.spring.annotation.MapperScan; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.data.redis.core.RedisTemplate; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Set; @Slf4j @EnableAspectJAutoProxy(exposeProxy = true) @MapperScan(basePackages = {"com.bx.implatform.mapper"}) @SpringBootApplication(exclude = {SecurityAutoConfiguration.class})// 禁用secrity -public class IMPlatformApp { +public class IMPlatformApp implements ApplicationRunner { 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/java/com/bx/implatform/entity/GroupMessage.java b/im-platform/src/main/java/com/bx/implatform/entity/GroupMessage.java index 870f1a2..b94b8a4 100644 --- a/im-platform/src/main/java/com/bx/implatform/entity/GroupMessage.java +++ b/im-platform/src/main/java/com/bx/implatform/entity/GroupMessage.java @@ -73,6 +73,12 @@ public class GroupMessage extends Model { @TableField("receipt") private Boolean receipt; + /** + * 回执消息是否完成 + */ + @TableField("receipt_ok") + private Boolean receiptOk; + /** * 状态 MessageStatus */ diff --git a/im-platform/src/main/java/com/bx/implatform/service/impl/GroupMessageServiceImpl.java b/im-platform/src/main/java/com/bx/implatform/service/impl/GroupMessageServiceImpl.java index d893c1e..5b6f5f5 100644 --- a/im-platform/src/main/java/com/bx/implatform/service/impl/GroupMessageServiceImpl.java +++ b/im-platform/src/main/java/com/bx/implatform/service/impl/GroupMessageServiceImpl.java @@ -233,6 +233,7 @@ public class GroupMessageServiceImpl extends ServiceImpl receiptMessages = this.list(wrapper); if (CollectionUtil.isNotEmpty(receiptMessages)) { @@ -240,10 +241,16 @@ public class GroupMessageServiceImpl extends ServiceImpl maxIdMap = redisTemplate.opsForHash().entries(key); for (GroupMessage receiptMessage : receiptMessages) { Integer readedCount = getReadedUserIds(maxIdMap, receiptMessage.getId(),receiptMessage.getSendId()).size(); + // 如果所有人都已读,记录回执消息完成标记 + if(readedCount >= userIds.size() - 1){ + receiptMessage.setReceiptOk(true); + this.updateById(receiptMessage); + } msgInfo = new GroupMessageVO(); msgInfo.setId(receiptMessage.getId()); msgInfo.setGroupId(groupId); msgInfo.setReadedCount(readedCount); + msgInfo.setReceiptOk(receiptMessage.getReceiptOk()); msgInfo.setType(MessageType.RECEIPT.code());; sendMessage = new IMGroupMessage<>(); sendMessage.setSender(new IMUserInfo(session.getUserId(), session.getTerminal())); diff --git a/im-platform/src/main/java/com/bx/implatform/vo/GroupMessageVO.java b/im-platform/src/main/java/com/bx/implatform/vo/GroupMessageVO.java index f7deb0b..377fd8a 100644 --- a/im-platform/src/main/java/com/bx/implatform/vo/GroupMessageVO.java +++ b/im-platform/src/main/java/com/bx/implatform/vo/GroupMessageVO.java @@ -33,6 +33,9 @@ public class GroupMessageVO { @ApiModelProperty(value = "是否回执消息") private Boolean receipt; + @ApiModelProperty(value = "回执消息是否完成") + private Boolean receiptOk; + @ApiModelProperty(value = "已读消息数量") private Integer readedCount = 0; diff --git a/im-platform/src/main/resources/application.yml b/im-platform/src/main/resources/application.yml index 9e28aa4..eddde6f 100644 --- a/im-platform/src/main/resources/application.yml +++ b/im-platform/src/main/resources/application.yml @@ -1,7 +1,5 @@ -#这是配置服务的端口 server: port: 8888 -#配置项目的数据源 spring: application: name: im-platform @@ -17,7 +15,7 @@ spring: redis: host: 127.0.0.1 port: 6379 - database: 1 + servlet: multipart: @@ -26,12 +24,10 @@ spring: mybatis-plus: configuration: - # 是否开启自动驼峰命名规则(camel case)映射,即从经典数据库列名 A_COLUMN(下划线命名) 到经典 Java 属性名 aColumn(驼峰命名) 的类似映射 + # 是否开启自动驼峰命名规则 map-underscore-to-camel-case: false - #log-impl: org.apache.ibatis.logging.stdout.StdOutImpl - # mapper + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl mapper-locations: - # *.xml的具体路径 - classpath*:mapper/*.xml minio: endpoint: http://127.0.0.1:9001 #内网地址 diff --git a/im-platform/src/main/resources/db/db.sql b/im-platform/src/main/resources/db/db.sql index a724696..776b08a 100644 --- a/im-platform/src/main/resources/db/db.sql +++ b/im-platform/src/main/resources/db/db.sql @@ -71,6 +71,7 @@ create table `im_group_message`( `content` text comment '发送内容', `at_user_ids` varchar(1024) comment '被@的用户id列表,逗号分隔', `receipt` tinyint DEFAULT 0 comment '是否回执消息', + `receipt_ok` tinyint DEFAULT 0 comment '回执消息是否完成', `type` tinyint(1) NOT NULL comment '消息类型 0:文字 1:图片 2:文件 3:语音 4:视频 10:系统提示' , `status` tinyint(1) DEFAULT 0 comment '状态 0:未发出 1:已送达 2:撤回 3:已读', `send_time` datetime DEFAULT CURRENT_TIMESTAMP comment '发送时间', diff --git a/im-server/pom.xml b/im-server/pom.xml index f799b0c..e5d0e78 100644 --- a/im-server/pom.xml +++ b/im-server/pom.xml @@ -22,10 +22,6 @@ org.springframework.boot spring-boot - - org.springframework.boot - spring-boot-starter-web - io.netty netty-all diff --git a/im-server/src/main/resources/application.yml b/im-server/src/main/resources/application.yml index e3110a4..827343d 100644 --- a/im-server/src/main/resources/application.yml +++ b/im-server/src/main/resources/application.yml @@ -1,11 +1,7 @@ -server: - port: 8877 - spring: redis: host: 127.0.0.1 port: 6379 - database: 1 websocket: enable: true diff --git a/im-ui/src/components/chat/ChatGroupReaded.vue b/im-ui/src/components/chat/ChatGroupReaded.vue index 5b5e54b..f9e5867 100644 --- a/im-ui/src/components/chat/ChatGroupReaded.vue +++ b/im-ui/src/components/chat/ChatGroupReaded.vue @@ -49,7 +49,6 @@ export default { y: 0, arrowY: 0 }, - msgInfo: {}, readedMembers: [], unreadMembers: [] } @@ -57,15 +56,17 @@ export default { props: { groupMembers: { type: Array - } + }, + msgInfo: { + type: Object + } }, methods: { close() { this.show = false; }, - open(msgInfo, rect) { + open(rect) { this.show = true; - this.msgInfo = msgInfo; this.pos.arrowY = 200; // 计算窗口位置 if (this.msgInfo.selfSend) { @@ -93,7 +94,7 @@ export default { }).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-ui/src/components/chat/ChatMessageItem.vue b/im-ui/src/components/chat/ChatMessageItem.vue index c0205e8..816c174 100644 --- a/im-ui/src/components/chat/ChatMessageItem.vue +++ b/im-ui/src/components/chat/ChatMessageItem.vue @@ -53,8 +53,9 @@ 未读
- {{msgInfo.readedCount}}人已读 - + + {{msgInfo.readedCount}}人已读 +
@@ -62,7 +63,7 @@ - + @@ -149,7 +150,7 @@ export default { }, onShowReadedBox() { let rect = this.$refs.chatMsgBox.getBoundingClientRect(); - this.$refs.chatGroupReadedBox.open(this.msgInfo, rect); + this.$refs.chatGroupReadedBox.open(rect); } }, computed: { @@ -370,7 +371,7 @@ export default { .icon-ok { font-size: 20px; - color: green; + color: #329432; } } } diff --git a/im-ui/src/view/Home.vue b/im-ui/src/view/Home.vue index 613dfe6..dbd79fa 100644 --- a/im-ui/src/view/Home.vue +++ b/im-ui/src/view/Home.vue @@ -236,7 +236,8 @@ export default { let msgInfo = { id: msg.id, groupId: msg.groupId, - readedCount: msg.readedCount + readedCount: msg.readedCount, + receiptOk: msg.receiptOk }; this.$store.commit("updateMessage", msgInfo) return; diff --git a/im-uniapp/App.vue b/im-uniapp/App.vue index 72eeeed..b04d91f 100644 --- a/im-uniapp/App.vue +++ b/im-uniapp/App.vue @@ -172,7 +172,8 @@ let msgInfo = { id: msg.id, groupId: msg.groupId, - readedCount: msg.readedCount + readedCount: msg.readedCount, + receiptOk: msg.receiptOk }; this.$store.commit("updateMessage", msgInfo) return; diff --git a/im-uniapp/components/chat-message-item/chat-message-item.vue b/im-uniapp/components/chat-message-item/chat-message-item.vue index e32be6c..d00763d 100644 --- a/im-uniapp/components/chat-message-item/chat-message-item.vue +++ b/im-uniapp/components/chat-message-item/chat-message-item.vue @@ -45,8 +45,9 @@ 未读 - {{msgInfo.readedCount}}人已读 - + + {{msgInfo.readedCount}}人已读 +