From a9559e245538cb3408e0458c51ad93b7e586a618 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Fri, 21 Apr 2023 17:50:17 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=89=B9=E9=87=8F=E5=A4=84=E7=90=86?= =?UTF-8?q?=E6=9C=BA=E5=99=A8=E4=BA=BA=E5=B7=B2=E8=AF=BB=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConversationGroupHandlerService.java | 28 +++++++++++++++++++ .../ConversationGroupListener.java | 4 +-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupHandlerService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupHandlerService.java index afba7c0dd..c1c108900 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupHandlerService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupHandlerService.java @@ -282,6 +282,34 @@ public class ConversationGroupHandlerService { return ConversationGroupMessageVO.convert2VO(messageList); } + /** + * 机器人批量已读信息 + * @param simulation 仿真 + * @param memberList 成员列表 + * @param id 用户群组ID + */ + public void robotBatchRead(Simulation simulation, List memberList, Long id) { + // 查找群组 + ConversationGroup conversationGroup = simulation.getConversationGroup(id); + Set robotMemberIds = memberList.stream().map(SimulationMember::getId).collect(Collectors.toSet()); + Set allMemberIds = conversationGroup.getMemberList().stream().map(m -> m.getMember().getId()).collect(Collectors.toSet()); + // 是否全部是群成员 + if (!allMemberIds.containsAll(robotMemberIds)) { + return; + } + // 获取到所有没有读取的消息 + List messageList = conversationGroup.getMessageList().stream() + .filter(m -> !m.isAllRead()).collect(Collectors.toList()); + messageList.forEach(message -> { + message.getReaderSet().addAll(robotMemberIds); + if (allMemberIds.stream().filter(mid -> !Objects.equals(message.getMember().getId(), mid)) + .allMatch(mid -> message.getReaderSet().contains(mid))) { // 除发送用户外全部已读 + message.finishRead(); + } + }); + applicationEventPublisher.publishEvent(new SimulationConversationGroupMessageStatusEvent(this, simulation, conversationGroup, messageList)); + } + /** * 对群组操作时基础判断 * diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupListener.java b/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupListener.java index e53aec4e8..56675fdb4 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupListener.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/conversation/ConversationGroupListener.java @@ -192,8 +192,8 @@ public class ConversationGroupListener { if (CollectionUtils.isEmpty(memberList)) { // 人员全部为真实人员时直接返回 return; } - // 增加机器人已读操作 - memberList.forEach(m -> conversationGroupHandlerService.readConversationGroup(simulation, m, conversationGroup.getId())); + // 增加机器人已读操作(批量操作) + conversationGroupHandlerService.robotBatchRead(simulation, memberList, conversationGroup.getId()); // 如果消息来源不为机器人,则执行语音识别,目前先不做语音识别回复 // if (!event.getMessage().getMember().isRobot()) { // VoiceDiscriminateService.doAnalysis(event.getSimulation(), conversationGroup.getId(), event.getMessage().getContent(), memberList);