【会话群组消息通知事件】

This commit is contained in:
weizhihong 2023-04-17 14:03:23 +08:00
parent ad2900926e
commit d83de6f4bd
13 changed files with 502 additions and 18 deletions

View File

@ -1578,6 +1578,60 @@ public class Operation {
*/ */
YJDDZH_VOICE_COMMAND(new Label[]{Label.CLIENT},true), YJDDZH_VOICE_COMMAND(new Label[]{Label.CLIENT},true),
/**
* 会话群组创建
*/
Conversation_Group_Create(new Label[]{Label.CLIENT}, true),
/**
* 会话群组修改组名
*/
Conversation_Group_Update_Name(new Label[]{Label.CLIENT}, true),
/**
* 会话群组修改群主
*/
Conversation_Group_Update_Leader(new Label[]{Label.CLIENT}, true),
/**
* 会话群组邀请成员
*/
Conversation_Group_Invite_Member(new Label[]{Label.CLIENT}, true),
/**
* 会话群组移除成员
*/
Conversation_Group_Remove_Member(new Label[]{Label.CLIENT}, true),
/**
* 会话群组退出
*/
Conversation_Group_Exit(new Label[]{Label.CLIENT}, true),
/**
* 会话群组解散
*/
Conversation_Group_Dissolve(new Label[]{Label.CLIENT}, true),
/**
* 会话群组语音文件聊天
*/
Conversation_Group_Audio_Chat(new Label[]{Label.CLIENT}, true),
/**
* 会话群组文字聊天
*/
Conversation_Group_Text_Chat(new Label[]{Label.CLIENT}, true),
/**
* 会话群组语音文件聊天
*/
Conversation_Group_Audio_Base64(new Label[]{Label.CLIENT}, true),
/**
* 会话群组获取未读消息
*/
Conversation_Group_Get_Unread_Message(new Label[]{Label.CLIENT}, true),
//---------------------------- PSL ------------------------------ //---------------------------- PSL ------------------------------
/** /**
* PSL盘按下按钮 * PSL盘按下按钮

View File

@ -326,6 +326,10 @@ public class Simulation extends club.joylink.rtss.simulation.Simulation<Simulati
this.simulationConversationGroupMap.put(group.getId(), group); this.simulationConversationGroupMap.put(group.getId(), group);
} }
public void removeConversionGroup(ConversationGroup group) {
this.simulationConversationGroupMap.remove(group.getId());
}
public void initDefaultConversationGroupMap(Map<Long, ConversationGroup> map) { public void initDefaultConversationGroupMap(Map<Long, ConversationGroup> map) {
this.simulationConversationGroupMap.putAll(map); this.simulationConversationGroupMap.putAll(map);
Long groupId = map.keySet().stream().max(Comparator.comparing(Long::longValue)).orElse(0L); Long groupId = map.keySet().stream().max(Comparator.comparing(Long::longValue)).orElse(0L);

View File

@ -11,6 +11,7 @@ import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -30,8 +31,19 @@ public class ConversationGroup extends Chat {
*/ */
private String name; private String name;
/**
* 群主
*/
private SimulationMember leader;
/**
* 群消息列表
*/
private List<ConversationGroupMessage> messageList = new ArrayList<>(); private List<ConversationGroupMessage> messageList = new ArrayList<>();
/**
* 消息主键
*/
private AtomicInteger messageId = new AtomicInteger(0); private AtomicInteger messageId = new AtomicInteger(0);
/** /**
@ -44,11 +56,11 @@ public class ConversationGroup extends Chat {
this.id = info.getId(); this.id = info.getId();
this.name = info.getName(); this.name = info.getName();
setTime(simulation.getCorrectSystemTime()); setTime(simulation.getCorrectSystemTime());
SimulationMember leader = null; if (info.getLeaderId() != null) { // 设置群主
if (info.getLeaderId() != null) { this.leader = simulation.getSimulationMemberById(info.getLeaderId());
leader = simulation.getSimulationMemberById(info.getLeaderId()); setCreator(this.leader);
setCreator(leader);
} }
setTime(simulation.getCorrectSystemTime());
List<ConversationMember> memberList = null; List<ConversationMember> memberList = null;
if (!CollectionUtils.isEmpty(info.getMemberIds())) { if (!CollectionUtils.isEmpty(info.getMemberIds())) {
memberList = info.getMemberIds().stream().distinct().map(simulation::getSimulationMemberById) memberList = info.getMemberIds().stream().distinct().map(simulation::getSimulationMemberById)
@ -60,6 +72,7 @@ public class ConversationGroup extends Chat {
public ConversationGroup(Long id, String name, LocalDateTime time, SimulationMember leader, List<SimulationMember> simulationMembers){ public ConversationGroup(Long id, String name, LocalDateTime time, SimulationMember leader, List<SimulationMember> simulationMembers){
this.id = id; this.id = id;
this.name = name; this.name = name;
this.leader = leader;
setTime(time); setTime(time);
setCreator(leader); setCreator(leader);
if (!CollectionUtils.isEmpty(simulationMembers)) { if (!CollectionUtils.isEmpty(simulationMembers)) {
@ -94,7 +107,7 @@ public class ConversationGroup extends Chat {
public List<ConversationGroupMessage> getUnreadMessages(SimulationMember member) { public List<ConversationGroupMessage> getUnreadMessages(SimulationMember member) {
ConversationMember conversationMember = getConversionMember(member); ConversationMember conversationMember = getConversionMember(member);
// 没有消息不是本群人员 // 没有消息不是本群人员
if (CollectionUtils.isEmpty(getMessageList()) && !isCreator(member) && conversationMember != null) { if (CollectionUtils.isEmpty(getMessageList()) && !isLeader(member) && conversationMember == null) {
return List.of(); return List.of();
} }
return messageList.stream().filter(message -> { return messageList.stream().filter(message -> {
@ -128,4 +141,13 @@ public class ConversationGroup extends Chat {
getMemberList().add(conversationMember); getMemberList().add(conversationMember);
} }
} }
/**
* 是否群主
* @param member 成员
* @return 结果
*/
public boolean isLeader(SimulationMember member) {
return Objects.equals(member, this.leader);
}
} }

View File

@ -5,6 +5,7 @@ import club.joylink.rtss.simulation.cbtc.GroupSimulationCache;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.vo.ConversationGroupMessageVO; import club.joylink.rtss.simulation.cbtc.data.vo.ConversationGroupMessageVO;
import club.joylink.rtss.simulation.cbtc.data.vo.ConversationGroupVO; import club.joylink.rtss.simulation.cbtc.data.vo.ConversationGroupVO;
import club.joylink.rtss.simulation.cbtc.event.conversation.*;
import club.joylink.rtss.simulation.cbtc.exception.SimulationException; import club.joylink.rtss.simulation.cbtc.exception.SimulationException;
import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType; import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType;
import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
@ -12,6 +13,8 @@ import club.joylink.rtss.vo.client.voice.VoiceRecognitionResult;
import club.joylink.rtss.vo.client.voice.VoiceRecognitionVO; import club.joylink.rtss.vo.client.voice.VoiceRecognitionVO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -32,10 +35,13 @@ public class ConversationGroupHandlerService {
@Autowired @Autowired
private SimulationVoiceHandler simulationVoiceHandler; private SimulationVoiceHandler simulationVoiceHandler;
@Autowired
private ApplicationEventPublisher applicationEventPublisher;
/** /**
* 获取所有群组信息 * 获取所有群组信息
* @param group * @param group 仿真ID
* @return * @return 群组信息
*/ */
public List<ConversationGroupVO> getAllConversationsGroup(String group) { public List<ConversationGroupVO> getAllConversationsGroup(String group) {
Simulation simulation = groupSimulationCache.getSimulationByGroup(group); Simulation simulation = groupSimulationCache.getSimulationByGroup(group);
@ -60,8 +66,8 @@ public class ConversationGroupHandlerService {
Long groupId = simulation.getMaxConversationGroupId(); Long groupId = simulation.getMaxConversationGroupId();
conversationGroup = new ConversationGroup(groupId, name, simulation.getCorrectSystemTime(), member, simulationMembers); conversationGroup = new ConversationGroup(groupId, name, simulation.getCorrectSystemTime(), member, simulationMembers);
simulation.addConversationGroup(conversationGroup); simulation.addConversationGroup(conversationGroup);
// 通知用户消息 TODO // 通知用户消息
applicationEventPublisher.publishEvent(new SimulationConversationGroupCreateEvent(this, simulation, conversationGroup));
return new ConversationGroupVO(conversationGroup); return new ConversationGroupVO(conversationGroup);
} }
@ -83,8 +89,8 @@ public class ConversationGroupHandlerService {
return; return;
} }
conversationGroup.setName(name); conversationGroup.setName(name);
// 通知其他用户群名变更 TODO // 通知其他用户群名变更
applicationEventPublisher.publishEvent(new SimulationConversationGroupUpdateEvent(this, simulation, conversationGroup));
} }
/** /**
@ -103,8 +109,8 @@ public class ConversationGroupHandlerService {
} }
// 设置群组 // 设置群组
conversationGroup.setCreator(simulationMember); conversationGroup.setCreator(simulationMember);
// 发送通知消息 TODO // 发送通知消息
applicationEventPublisher.publishEvent(new SimulationConversationGroupUpdateEvent(this, simulation, conversationGroup));
} }
/** /**
@ -125,8 +131,30 @@ public class ConversationGroupHandlerService {
SimulationMember newMember = simulation.getSimulationMemberById(memberId); SimulationMember newMember = simulation.getSimulationMemberById(memberId);
conversationGroup.addSimulationMember(newMember, simulation.getCorrectSystemTime()); conversationGroup.addSimulationMember(newMember, simulation.getCorrectSystemTime());
}); });
// 给新加入的用户发送消息 TODO // 给新加入的用户发送消息
applicationEventPublisher.publishEvent(new SimulationConversationGroupInviteEvent(this, simulation, conversationGroup, groupMemberIds, newMemberIds));
}
/**
* 移除群组用户
* @param simulation 仿真
* @param member 用户
* @param groupId 群组主键
* @param memberIds 角色ID
*/
public void removeMemberConversationGroup(Simulation simulation, SimulationMember member, Long groupId, List<String> memberIds) {
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, member, groupId);
if (memberIds.contains(conversationGroup.getLeader().getId())) {
throw new SimulationException(SimulationExceptionType.Illegal_Argument, "群主不能移除");
}
List<SimulationMember> removeSimulationMemberList = new ArrayList<>(memberIds.size());
conversationGroup.getSimulationMemberList().stream().filter(m -> memberIds.contains(m.getId()))
.forEach(m -> {
removeSimulationMemberList.add(m);
conversationGroup.exit(m);
});
// 给新加入的用户发送消息
applicationEventPublisher.publishEvent(new SimulationConversationGroupRemoveEvent(this, simulation, conversationGroup, removeSimulationMemberList));
} }
/** /**
@ -144,8 +172,21 @@ public class ConversationGroupHandlerService {
throw new SimulationException(SimulationExceptionType.Illegal_Argument, "请先变更群主"); throw new SimulationException(SimulationExceptionType.Illegal_Argument, "请先变更群主");
} }
conversationGroup.exit(member); conversationGroup.exit(member);
// 发送退群消息 TODO // 发送退群消息
applicationEventPublisher.publishEvent(new SimulationConversationGroupExitEvent(this, simulation, conversationGroup, member));
}
/**
* 解散群组
* @param simulation 仿真
* @param member 用户
* @param groupId 群组主键
*/
public void dissolveConversationGroup(Simulation simulation, SimulationMember member, Long groupId) {
ConversationGroup conversationGroup = checkGroupIdAndReturn(simulation, member, groupId);
simulation.removeConversionGroup(conversationGroup);
// 发送解散消息
applicationEventPublisher.publishEvent(new SimulationConversationGroupDissolveEvent(this, simulation, conversationGroup));
} }
/** /**
@ -197,8 +238,7 @@ public class ConversationGroupHandlerService {
public ConversationGroupMessageVO audioBase64(Simulation simulation, SimulationMember member, Long groupId, String fileBase64Str) { public ConversationGroupMessageVO audioBase64(Simulation simulation, SimulationMember member, Long groupId, String fileBase64Str) {
ConversationGroupMessage message = sendMessage(simulation, member, groupId, () -> { ConversationGroupMessage message = sendMessage(simulation, member, groupId, () -> {
VoiceRecognitionVO vo = VoiceRecognitionVO.load(fileBase64Str); VoiceRecognitionVO vo = VoiceRecognitionVO.load(fileBase64Str);
VoiceRecognitionResult recognitionResult = iVoiceService.voiceRecognition(vo); return iVoiceService.voiceRecognition(vo);
return recognitionResult;
}); });
return new ConversationGroupMessageVO(message); return new ConversationGroupMessageVO(message);
} }
@ -228,6 +268,62 @@ public class ConversationGroupHandlerService {
return ConversationGroupMessageVO.convert2VO(messageList); return ConversationGroupMessageVO.convert2VO(messageList);
} }
/**
* 处理创建群组事件
* @param event 事件信息
*/
@EventListener
public void handleCreate(SimulationConversationGroupCreateEvent event) {
ConversationGroup conversationGroup = event.getConversationGroup();
}
/**
* 处理更新群组信息事件
* @param event 事件信息
*/
@EventListener
public void handleUpdate(SimulationConversationGroupUpdateEvent event) {
}
/**
* 处理邀请成员事件
* @param event 事件信息
*/
@EventListener
public void handleInvite(SimulationConversationGroupInviteEvent event) {
}
/**
* 群组移除人员事件
*
* @param event 事件信息
*/
@EventListener
public void handleRemove(SimulationConversationGroupRemoveEvent event) {
}
/**
* 处理退出群组事件
* @param event 事件信息
*/
@EventListener
public void handleExit(SimulationConversationGroupExitEvent event) {
}
/**
* 解散群主事件
* @param event 事件信息
*/
@EventListener
public void handleDissolve(SimulationConversationGroupDissolveEvent event) {
}
/** /**
* 对群组操作时基础判断 * 对群组操作时基础判断
* *
@ -241,7 +337,7 @@ public class ConversationGroupHandlerService {
if (conversationGroup == null) { if (conversationGroup == null) {
throw new SimulationException(SimulationExceptionType.Illegal_Argument, "群组不存在"); throw new SimulationException(SimulationExceptionType.Illegal_Argument, "群组不存在");
} }
if (member != null && !Objects.equals(member.getId(), conversationGroup.getCreator().getId())) { if (member != null && !Objects.equals(member.getId(), conversationGroup.getLeader().getId())) {
throw new SimulationException(SimulationExceptionType.Illegal_Argument, "您无操作权限"); throw new SimulationException(SimulationExceptionType.Illegal_Argument, "您无操作权限");
} }
return conversationGroup; return conversationGroup;
@ -278,4 +374,6 @@ public class ConversationGroupHandlerService {
return message; return message;
} }
} }

View File

@ -1,6 +1,8 @@
package club.joylink.rtss.simulation.cbtc.conversation; package club.joylink.rtss.simulation.cbtc.conversation;
import club.joylink.rtss.simulation.cbtc.ATS.operation.Operation;
import club.joylink.rtss.simulation.cbtc.ATS.operation.annotation.OperateHandler; import club.joylink.rtss.simulation.cbtc.ATS.operation.annotation.OperateHandler;
import club.joylink.rtss.simulation.cbtc.ATS.operation.annotation.OperateHandlerMapping;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.vo.ConversationGroupMessageVO; import club.joylink.rtss.simulation.cbtc.data.vo.ConversationGroupMessageVO;
import club.joylink.rtss.simulation.cbtc.data.vo.ConversationGroupVO; import club.joylink.rtss.simulation.cbtc.data.vo.ConversationGroupVO;
@ -26,6 +28,7 @@ public class ConversationGroupOperateHandler {
* @param name * @param name
* @param memberIds * @param memberIds
*/ */
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Create)
public ConversationGroupVO createConversationGroup(Simulation simulation, SimulationMember member, String name, List<String> memberIds) { public ConversationGroupVO createConversationGroup(Simulation simulation, SimulationMember member, String name, List<String> memberIds) {
return conversationGroupManagerService.createConversationGroup(simulation, member, name, memberIds); return conversationGroupManagerService.createConversationGroup(simulation, member, name, memberIds);
} }
@ -33,6 +36,7 @@ public class ConversationGroupOperateHandler {
/** /**
* 修改群组名称等基本信息 * 修改群组名称等基本信息
*/ */
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Update_Name)
public void updateConversationGroup(Simulation simulation, SimulationMember member, Long groupId, String name) { public void updateConversationGroup(Simulation simulation, SimulationMember member, Long groupId, String name) {
conversationGroupManagerService.updateConversationGroup(simulation, member, groupId, name); conversationGroupManagerService.updateConversationGroup(simulation, member, groupId, name);
} }
@ -45,6 +49,7 @@ public class ConversationGroupOperateHandler {
* @param groupId 群组ID * @param groupId 群组ID
* @param memberId 用户ID * @param memberId 用户ID
*/ */
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Update_Leader)
public void setConversationGroupLeader(Simulation simulation, SimulationMember member, Long groupId, String memberId) { public void setConversationGroupLeader(Simulation simulation, SimulationMember member, Long groupId, String memberId) {
conversationGroupManagerService.setConversationGroupLeader(simulation, member, groupId, memberId); conversationGroupManagerService.setConversationGroupLeader(simulation, member, groupId, memberId);
} }
@ -52,20 +57,39 @@ public class ConversationGroupOperateHandler {
/** /**
* 邀请角色进群组 * 邀请角色进群组
*/ */
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Invite_Member)
public void inviteMembersInConversationGroup(Simulation simulation, SimulationMember member, Long groupId, List<String> memberIds) { public void inviteMembersInConversationGroup(Simulation simulation, SimulationMember member, Long groupId, List<String> memberIds) {
conversationGroupManagerService.inviteMembersInConversationGroup(simulation, member, groupId, memberIds); conversationGroupManagerService.inviteMembersInConversationGroup(simulation, member, groupId, memberIds);
} }
/**
* 踢人
*/
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Remove_Member)
public void removeMemberConversationGroup(Simulation simulation, SimulationMember member, Long groupId, List<String> memberIds) {
conversationGroupManagerService.removeMemberConversationGroup(simulation, member, groupId, memberIds);
}
/** /**
* 退出群组信息 * 退出群组信息
*/ */
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Exit)
public void exitConversationGroup(Simulation simulation, SimulationMember member, Long groupId) { public void exitConversationGroup(Simulation simulation, SimulationMember member, Long groupId) {
conversationGroupManagerService.exitConversationGroup(simulation, member, groupId); conversationGroupManagerService.exitConversationGroup(simulation, member, groupId);
} }
/**
* 解散群组
*/
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Dissolve)
public void dissolveConversationGroup(Simulation simulation, SimulationMember member, Long groupId) {
conversationGroupManagerService.dissolveConversationGroup(simulation, member, groupId);
}
/** /**
* 发送语音信息 * 发送语音信息
*/ */
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Audio_Chat)
public ConversationGroupMessageVO audioChat(Simulation simulation, SimulationMember member, Long groupId, String audioPath, String content) { public ConversationGroupMessageVO audioChat(Simulation simulation, SimulationMember member, Long groupId, String audioPath, String content) {
return conversationGroupManagerService.audioChat(simulation, member, groupId, audioPath, content); return conversationGroupManagerService.audioChat(simulation, member, groupId, audioPath, content);
} }
@ -73,6 +97,7 @@ public class ConversationGroupOperateHandler {
/** /**
* 发送文字信息 * 发送文字信息
*/ */
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Text_Chat)
public ConversationGroupMessageVO textChat(Simulation simulation, SimulationMember member, Long groupId, String content) { public ConversationGroupMessageVO textChat(Simulation simulation, SimulationMember member, Long groupId, String content) {
return conversationGroupManagerService.textChat(simulation, member, groupId, content); return conversationGroupManagerService.textChat(simulation, member, groupId, content);
} }
@ -80,6 +105,7 @@ public class ConversationGroupOperateHandler {
/** /**
* 发送Base64音频文件 * 发送Base64音频文件
*/ */
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Audio_Base64)
public ConversationGroupMessageVO audioBase64(Simulation simulation, SimulationMember member, Long groupId, String fileBase64Str) { public ConversationGroupMessageVO audioBase64(Simulation simulation, SimulationMember member, Long groupId, String fileBase64Str) {
return conversationGroupManagerService.audioBase64(simulation, member, groupId, fileBase64Str); return conversationGroupManagerService.audioBase64(simulation, member, groupId, fileBase64Str);
} }
@ -87,6 +113,7 @@ public class ConversationGroupOperateHandler {
/** /**
* 阅读群组信息 * 阅读群组信息
*/ */
@OperateHandlerMapping(type = Operation.Type.Conversation_Group_Get_Unread_Message)
public List<ConversationGroupMessageVO> readConversationGroup(Simulation simulation, SimulationMember member, Long groupId) { public List<ConversationGroupMessageVO> readConversationGroup(Simulation simulation, SimulationMember member, Long groupId) {
return conversationGroupManagerService.readConversationGroup(simulation, member, groupId); return conversationGroupManagerService.readConversationGroup(simulation, member, groupId);
} }

View File

@ -0,0 +1,108 @@
package club.joylink.rtss.simulation.cbtc.data.vo;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.conversation.Conversation;
import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroup;
import club.joylink.rtss.simulation.cbtc.conversation.ConversationMessage;
import club.joylink.rtss.simulation.cbtc.discriminate.ParamExtractResult;
import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
import lombok.Getter;
import java.util.List;
import java.util.stream.Collectors;
@Getter
public class ConversationGroupSocketMessageVO {
private Long id;
/**
* 群组名称
*/
private String name;
/**
* 创建人
*/
private String creatorId;
/**
* 群主
*/
private String leaderId;
/**
* 成员列表
*/
private List<ConversationMemberVO> memberList;
/**
* 消息体
*/
private ConversationGroupMessageVO message;
/**
* 消息类型
*/
private MessageType messageType;
public enum MessageType {
/**
* 会话组创建
*/
CREATE {
@Override
public ConversationGroupSocketMessageVO generateMessageVO(ConversationGroup group, ConversationGroupMessageVO message) {
ConversationGroupSocketMessageVO messageVO = new ConversationGroupSocketMessageVO();
messageVO.id = group.getId();
messageVO.name = group.getName();
messageVO.creatorId = group.getCreator() != null ? group.getCreator().getId() : null;
messageVO.leaderId = group.getLeader() != null ? group.getLeader().getId() : null;
messageVO.memberList = group.getMemberList().stream().map(ConversationMemberVO::new).collect(Collectors.toList());
messageVO.messageType = MessageType.CREATE;
return messageVO;
}
},
/**
* 会话组更新
*/
UPDATE {
@Override
public ConversationGroupSocketMessageVO generateMessageVO(ConversationGroup group, ConversationGroupMessageVO message) {
ConversationGroupSocketMessageVO messageVO = new ConversationGroupSocketMessageVO();
messageVO.id = group.getId();
messageVO.name = group.getName();
messageVO.leaderId = group.getLeader() != null ? group.getLeader().getId() : null;
messageVO.memberList = group.getMemberList().stream().map(ConversationMemberVO::new).collect(Collectors.toList());
messageVO.messageType = MessageType.UPDATE;
return messageVO;
}
},
/** 会话组邀请 */
INVITE {
@Override
public ConversationGroupSocketMessageVO generateMessageVO(ConversationGroup group, ConversationGroupMessageVO message) {
return null;
}
},
/** 成员发送消息 */
MESSAGE {
@Override
public ConversationGroupSocketMessageVO generateMessageVO(ConversationGroup group, ConversationGroupMessageVO message) {
return null;
}
},
/** 会话结束 */
EXIT {
@Override
public ConversationGroupSocketMessageVO generateMessageVO(ConversationGroup group, ConversationGroupMessageVO message) {
return null;
}
};
public abstract ConversationGroupSocketMessageVO generateMessageVO(ConversationGroup group, ConversationGroupMessageVO message);
}
}

View File

@ -2,6 +2,7 @@ package club.joylink.rtss.simulation.cbtc.data.vo;
import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroup; import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroup;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -10,10 +11,13 @@ import java.util.List;
@Getter @Getter
@Setter @Setter
@NoArgsConstructor
public class ConversationGroupVO { public class ConversationGroupVO {
private Long id; private Long id;
private String name;
private String creatorId; private String creatorId;
private List<ConversationMemberVO> memberList; private List<ConversationMemberVO> memberList;
@ -22,6 +26,7 @@ public class ConversationGroupVO {
public ConversationGroupVO(ConversationGroup conversation) { public ConversationGroupVO(ConversationGroup conversation) {
this.id = conversation.getId(); this.id = conversation.getId();
this.name = conversation.getName();
if (conversation.getCreator() != null) { if (conversation.getCreator() != null) {
this.creatorId = conversation.getCreator().getId(); this.creatorId = conversation.getCreator().getId();
} }
@ -29,6 +34,20 @@ public class ConversationGroupVO {
this.messageList = ConversationGroupMessageVO.convert2VO(conversation.getMessageList()); this.messageList = ConversationGroupMessageVO.convert2VO(conversation.getMessageList());
} }
/**
* 生成不带消息的VO对象
* @param conversation
*/
public void generateConversationGroupVOWithOutMessage(ConversationGroup conversation) {
this.id = conversation.getId();
this.name = conversation.getName();
if (conversation.getCreator() != null) {
this.creatorId = conversation.getCreator().getId();
}
this.memberList = ConversationMemberVO.convert2VOList(conversation.getMemberList());
}
public static List<ConversationGroupVO> convert2VOList(List<ConversationGroup> list) { public static List<ConversationGroupVO> convert2VOList(List<ConversationGroup> list) {
List<ConversationGroupVO> voList = new ArrayList<>(); List<ConversationGroupVO> voList = new ArrayList<>();
if (!CollectionUtils.isEmpty(list)) { if (!CollectionUtils.isEmpty(list)) {

View File

@ -0,0 +1,20 @@
package club.joylink.rtss.simulation.cbtc.event.conversation;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroup;
import club.joylink.rtss.simulation.cbtc.event.AbstractSimulationEvent;
import lombok.Getter;
/**
* 群组创建成功
*/
@Getter
public class SimulationConversationGroupCreateEvent extends AbstractSimulationEvent {
private ConversationGroup conversationGroup;
public SimulationConversationGroupCreateEvent(Object source, Simulation simulation, ConversationGroup conversationGroup) {
super(source, simulation);
this.conversationGroup = conversationGroup;
}
}

View File

@ -0,0 +1,20 @@
package club.joylink.rtss.simulation.cbtc.event.conversation;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroup;
import club.joylink.rtss.simulation.cbtc.event.AbstractSimulationEvent;
import lombok.Getter;
/**
* 群组退群事件
*/
@Getter
public class SimulationConversationGroupDissolveEvent extends AbstractSimulationEvent {
private ConversationGroup conversationGroup;
public SimulationConversationGroupDissolveEvent(Object source, Simulation simulation, ConversationGroup conversationGroup) {
super(source, simulation);
this.conversationGroup = conversationGroup;
}
}

View File

@ -0,0 +1,27 @@
package club.joylink.rtss.simulation.cbtc.event.conversation;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroup;
import club.joylink.rtss.simulation.cbtc.event.AbstractSimulationEvent;
import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
import lombok.Getter;
/**
* 群组退群事件
*/
@Getter
public class SimulationConversationGroupExitEvent extends AbstractSimulationEvent {
private ConversationGroup conversationGroup;
/**
* 退群用户
*/
private SimulationMember member;
public SimulationConversationGroupExitEvent(Object source, Simulation simulation, ConversationGroup conversationGroup, SimulationMember member) {
super(source, simulation);
this.conversationGroup = conversationGroup;
this.member = member;
}
}

View File

@ -0,0 +1,35 @@
package club.joylink.rtss.simulation.cbtc.event.conversation;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroup;
import club.joylink.rtss.simulation.cbtc.event.AbstractSimulationEvent;
import lombok.Getter;
import java.util.List;
/**
* 群组信息变更事件
*/
@Getter
public class SimulationConversationGroupInviteEvent extends AbstractSimulationEvent {
private ConversationGroup conversationGroup;
/**
* 原有群组组员
*/
private List<String> groupMemberIds;
/**
* 新加入的组员
*/
private List<String> newGroupMemberIds;
public SimulationConversationGroupInviteEvent(Object source, Simulation simulation, ConversationGroup conversationGroup
, List<String> groupMemberIds, List<String> newGroupMemberIds) {
super(source, simulation);
this.conversationGroup = conversationGroup;
this.groupMemberIds = groupMemberIds;
this.newGroupMemberIds = newGroupMemberIds;
}
}

View File

@ -0,0 +1,30 @@
package club.joylink.rtss.simulation.cbtc.event.conversation;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroup;
import club.joylink.rtss.simulation.cbtc.event.AbstractSimulationEvent;
import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
import lombok.Getter;
import java.util.List;
/**
* 群组人员移除事件
*/
@Getter
public class SimulationConversationGroupRemoveEvent extends AbstractSimulationEvent {
private ConversationGroup conversationGroup;
/**
* 被移除的用户ID
*/
private List<SimulationMember> removeGroupMember;
public SimulationConversationGroupRemoveEvent(Object source, Simulation simulation, ConversationGroup conversationGroup
, List<SimulationMember> removeGroupMember) {
super(source, simulation);
this.conversationGroup = conversationGroup;
this.removeGroupMember = removeGroupMember;
}
}

View File

@ -0,0 +1,20 @@
package club.joylink.rtss.simulation.cbtc.event.conversation;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.conversation.ConversationGroup;
import club.joylink.rtss.simulation.cbtc.event.AbstractSimulationEvent;
import lombok.Getter;
/**
* 群组信息变更事件
*/
@Getter
public class SimulationConversationGroupUpdateEvent extends AbstractSimulationEvent {
private ConversationGroup conversationGroup;
public SimulationConversationGroupUpdateEvent(Object source, Simulation simulation, ConversationGroup conversationGroup) {
super(source, simulation);
this.conversationGroup = conversationGroup;
}
}