Commit ae35ab17 by Future

群拓展属性

parent ceea5097
...@@ -766,10 +766,6 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap ...@@ -766,10 +766,6 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
imMessage.setSystemFlag(false); imMessage.setSystemFlag(false);
imMessage.setSendStatus(2); imMessage.setSendStatus(2);
imMessage.setFkConversationId(conversationId); imMessage.setFkConversationId(conversationId);
Long appId = currentClient.getFkAppid();
String sender = currentClient.getClientId();
// 遍历发送给已在群内的成员 // 遍历发送给已在群内的成员
for (String key : chatRoomMembers.keySet()) { for (String key : chatRoomMembers.keySet()) {
Long fkClientId = Long.valueOf(key.split(RedisUtils.SPLIT)[0]); Long fkClientId = Long.valueOf(key.split(RedisUtils.SPLIT)[0]);
...@@ -1051,30 +1047,24 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap ...@@ -1051,30 +1047,24 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
public void saveOrUpdateAttr(ImConversationAttrUpdate imConversationAttrUpdate) { public void saveOrUpdateAttr(ImConversationAttrUpdate imConversationAttrUpdate) {
// 获取当前client // 获取当前client
ImClient currentClient = contextService.getImClientIfNotNullOrThrow(); ImClient currentClient = contextService.getImClientIfNotNullOrThrow();
// 根据appId查询application
ImApplication imApplication = contextService.getImApplicationIfNotNullOrThrow(currentClient.getFkAppid());
ImConversation imConversationById = imConversationService.getById(imConversationAttrUpdate.getConversationId()); ImConversation imConversationById = imConversationService.getById(imConversationAttrUpdate.getConversationId());
// 判断是否为群主
// if (imConversationById == null || !imConversationById.getCreator().equals(imClientSender.getId())) {
// return ApiResult.result(false);
// }
// 查询该会话所有成员
List<ImConversationMembers> membersList = imConversationMembersService.list(
new QueryWrapper<ImConversationMembers>().lambda()
.eq(ImConversationMembers::getFkAppid, imApplication.getId())
.eq(ImConversationMembers::getFkConversationId, imConversationAttrUpdate.getConversationId())
.ne(ImConversationMembers::getFkClientId, currentClient.getId())
);
imConversationById.setAttributes(imConversationAttrUpdate.getAttributes()); imConversationById.setAttributes(imConversationAttrUpdate.getAttributes());
boolean b = imConversationService.updateById(imConversationById); boolean b = imConversationService.updateById(imConversationById);
// 删除redis中该会话的缓存 // 删除redis中该会话的缓存
deleteCacheImConversationById(imConversationAttrUpdate.getConversationId()); deleteCacheImConversationById(imConversationAttrUpdate.getConversationId());
if (b) { if (b) {
if (ChatTypeEnum.CHAT_ROOM.getCode().equals(imConversationById.getChatType())) {
// 聊天室事件发送逻辑
chatRoomAttrChanged(imConversationById, currentClient);
return;
}
// 查询该会话所有成员
List<ImConversationMembers> membersList = imConversationMembersService.list(
new QueryWrapper<ImConversationMembers>().lambda()
.eq(ImConversationMembers::getFkAppid, currentClient.getFkAppid())
.eq(ImConversationMembers::getFkConversationId, imConversationAttrUpdate.getConversationId())
.ne(ImConversationMembers::getFkClientId, currentClient.getId())
);
// ws下发拓展字段变动事件 // ws下发拓展字段变动事件
HashMap<String, String> content = Maps.newHashMap(); HashMap<String, String> content = Maps.newHashMap();
content.put("attributes", imConversationById.getAttributes()); content.put("attributes", imConversationById.getAttributes());
...@@ -1090,7 +1080,40 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap ...@@ -1090,7 +1080,40 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
} else { } else {
throw new BusinessException("修改错误"); throw new BusinessException("修改错误");
} }
}
/**
* 解散聊天室
* @param imConversation
* @param currentClient
*/
private void chatRoomAttrChanged(ImConversation imConversation, ImClient currentClient) {
Map<String, String> chatRoomMembers = chatRoomCacheManager.findOnlineClientsByChatRoomId(imConversation.getId());
if (chatRoomMembers.isEmpty()) {
throw new BusinessException("聊天室成员列为空");
}
// 保存事件消息
ImMessage imMessage = new ImMessage();
HashMap<String, String> content = Maps.newHashMap();
content.put("attributes", imConversation.getAttributes());
imMessage.setContent(JsonUtils.encodeJson(content));
imMessage.setId(SnowflakeUtil.getId());
imMessage.setMsgType(MsgTypeEnum.CONVERSATION_EXPAND_FIELD_CHANGE.getUriCode());
imMessage.setCreateTime(new Date());
imMessage.setFkAppid(currentClient.getFkAppid());
imMessage.setSender(currentClient.getId());
imMessage.setWithdraw(false);
imMessage.setEvent(true);
imMessage.setSystemFlag(false);
imMessage.setSendStatus(2);
imMessage.setFkConversationId(imConversation.getId());
// 遍历发送给已在群内的成员
for (String key : chatRoomMembers.keySet()) {
Long fkClientId = Long.valueOf(key.split(RedisUtils.SPLIT)[0]);
sendEventMsgToMember(imConversation.getId(), currentClient.getFkAppid(), currentClient.getClientId(),
fkClientId, null, imMessage);
}
} }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment