Commit 0319f9a1 by Future

bug fix: 成员被踢出群聊后还能往群发消息问题修复

parent 9c20ba54
......@@ -78,7 +78,7 @@ public class NormalChatAction {
@ActionMapping("/normal/send")
public void sendMsg(ActionRequest request, ChatContentVo data, String reqId) {
if (log.isDebugEnabled()) {
log.debug("接收到参数,reqId: {},\n data: {}, ", data);
log.debug("接收到参数,reqId: {},\n data: {}, ", reqId, data);
}
//查看接收的群属性,是否万人群
......@@ -120,7 +120,9 @@ public class NormalChatAction {
return;
}
}
if (beKickOut(reqId, imClientSender, membersList, request.getSenderChannel())) {
return;
}
ImMessageOnlineSend imMessageOnlineSend = assembleImMessageOnlineSend(data, imClientSender, imApplication.getId());
// 再给所有人发 todo 需要改成批量
......@@ -298,4 +300,23 @@ public class NormalChatAction {
}
return false;
}
private boolean beKickOut(String reqId, ImClient imClientSender, List<ImConversationMembers> membersList, Channel channel) {
Long senderId = imClientSender.getId();
// 判断是否被踢出
boolean beKickOut = membersList.stream().anyMatch(c -> c.getFkClientId().equals(imClientSender.getId()));
if (!beKickOut) {
log.info("发送方: {}, 已被踢出会话", senderId);
// 响应发送方
WsResponse<HashMap<String, Long>> responseModel = new WsResponse<>();
ApiResult<Boolean> result = ApiResult.result(ApiCode.IS_BE_KICK_OUT);
responseModel.setCmd(WsResponseCmdEnum.RES.getCmdCode());
responseModel.setCode(result.getCode());
responseModel.setMsg(result.getMessage());
responseModel.setReqId(reqId);
channelSender.sendMsgLocal((NioSocketChannel)channel, responseModel);
return true;
}
return false;
}
}
......@@ -140,7 +140,7 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
// 如果存在重复单聊类型会话,则不会为空
ImConversation repetitionConversationInfo = imConversationMapper.getRepetitionConversationSingle(createClient.getId(), client2.getId());
if (repetitionConversationInfo != null) {
log.info("repetitionConversation != 0");
log.info("存在重复的单聊会话,返回已存在的单聊类型会话id: {}", repetitionConversationInfo.getId());
// 返回已存在的单聊类型会话id
ImConversationCreateVo imConversationCreateVo = new ImConversationCreateVo();
imConversationCreateVo.setId(repetitionConversationInfo.getId());
......@@ -256,16 +256,17 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
// 将他人添加到会话
for (String id : imClientToConversation.getClientIds()) {
ImClient client2 = imClientService.getOne(new QueryWrapper<ImClient>().lambda()
ImClient clientToConversation = imClientService.getOne(new QueryWrapper<ImClient>().lambda()
.eq(ImClient::getFkAppid, imApplication.getId())
.eq(ImClient::getClientId, id));
if (clientToConversation == null) {
return ApiResult.fail(ApiCode.CLIENT_NOT_FOUNT, null);
}
// 判断用户是否已经在该会话
ImConversationMembers members = imConversationMembersService.getOne(new QueryWrapper<ImConversationMembers>().lambda()
.eq(ImConversationMembers::getFkAppid, imApplication.getId())
.eq(ImConversationMembers::getFkConversationId, imClientToConversation.getConversationId())
.eq(ImConversationMembers::getFkClientId, client2.getId())
.eq(ImConversationMembers::getFkClientId, clientToConversation.getId())
);
// 已经在该会话 则跳过
......@@ -279,7 +280,7 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
imConversationMembers2.setCreateTime(new Date());
imConversationMembers2.setFkAppid(imApplication.getId());
imConversationMembers2.setFkConversationId(imClientToConversation.getConversationId());
imConversationMembers2.setFkClientId(client2.getId());
imConversationMembers2.setFkClientId(clientToConversation.getId());
imConversationMembersService.save(imConversationMembers2);
needAddCount++;
......@@ -293,7 +294,7 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
Map<String, Object> content = new HashMap<>();
content.put("operator", imClientSender.getClientId()); //操作的client ID
content.put("passivityOperator", client2.getClientId()); //被操作的client ID
content.put("passivityOperator", clientToConversation.getClientId()); //被操作的client ID
content.put("type", MsgTypeEnum.INVITE_CLIENT_JOIN_CONVERSATION.getUriCode()); //xx邀请xx加入会话 -1007
imMessage.setContent(JsonUtils.encodeJson(content));
......@@ -331,7 +332,7 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
// 操作的client ID
contentMap.put("operator", imClientSender.getClientId());
// 被操作的client ID
contentMap.put("passivityOperator", client2.getClientId());
contentMap.put("passivityOperator", clientToConversation.getClientId());
imMessageOnlineSend.setContent(contentMap);
imMessageOnlineSend.setConversationId(conversationMembers.getFkConversationId());
imMessageOnlineSend.setWithdraw(Boolean.FALSE);
......
......@@ -124,6 +124,12 @@ public enum ApiCode {
* 你把对方拉黑
*/
IS_TO_BLACK(6013, "api.response.code.IS_TO_BLACK"),
/**
* 已被踢出会话
*/
IS_BE_KICK_OUT(6014, "api.response.code.IS_BE_KICK_OUT"),
;
private final int code;
......
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