Commit 11234900 by Future

群禁言增加事件下发

parent 7385ca57
......@@ -3,6 +3,7 @@ package com.wecloud.im.controller;
import com.alibaba.fastjson.JSON;
import com.wecloud.im.param.DisbandConversationParam;
import com.wecloud.im.param.ImConversationQueryParam;
import com.wecloud.im.param.MutedGroupMemberParam;
import com.wecloud.im.param.MutedGroupParam;
import com.wecloud.im.param.SetAdminsParam;
import com.wecloud.im.param.TransferOwnerParam;
......@@ -161,7 +162,7 @@ public class ImConversationController extends BaseController {
*/
@PostMapping("/mutedGroupMember")
@ApiOperation(value = "选择禁言", notes = "权限:群主和管理员有权限操作")
public ApiResult<Boolean> mutedGroupMember(@RequestBody @Validated MutedGroupParam param) {
public ApiResult<Boolean> mutedGroupMember(@RequestBody @Validated MutedGroupMemberParam param) {
log.info("选择禁言入参 {}", JSON.toJSONString(param));
if (CollectionUtils.isEmpty(param.getClientIds())) {
return ApiResult.fail(ApiCode.PARAMETER_EXCEPTION, null);
......
package com.wecloud.im.param;
import io.geekidea.springbootplus.framework.common.entity.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* @Author wenzhida
* @Date 2022/2/17 15:58
* @Description 群成员禁言入参
*/
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "群成员禁言入参")
public class MutedGroupMemberParam extends BaseEntity {
private static final long serialVersionUID = 7572911152462759853L;
@NotNull
@ApiModelProperty("会话id")
private Long conversationId;
@ApiModelProperty("禁言指定群成员列表 - 群禁言无需入参")
private List<String> clientIds;
@NotNull
@ApiModelProperty("禁言类型 1-取消禁言 2-禁言")
private Integer mutedType;
}
package com.wecloud.im.param;
import com.wecloud.im.enums.MutedEnum;
import io.geekidea.springbootplus.framework.common.entity.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
......@@ -7,7 +8,6 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* @Author wenzhida
......@@ -25,9 +25,10 @@ public class MutedGroupParam extends BaseEntity {
@ApiModelProperty("会话id")
private Long conversationId;
@ApiModelProperty("禁言指定群成员列表 - 群禁言无需入参")
private List<String> clientIds;
/**
* 禁言类型
* @see com.wecloud.im.enums.MutedEnum
*/
@NotNull
@ApiModelProperty("禁言类型 1-取消禁言 2-禁言")
private Integer mutedType;
......
......@@ -6,6 +6,7 @@ import com.wecloud.im.param.DisbandConversationParam;
import com.wecloud.im.param.ImConversationPageParam;
import com.wecloud.im.param.ImConversationQueryParam;
import com.wecloud.im.param.ImConversationQueryVo;
import com.wecloud.im.param.MutedGroupMemberParam;
import com.wecloud.im.param.MutedGroupParam;
import com.wecloud.im.param.SetAdminsParam;
import com.wecloud.im.param.TransferOwnerParam;
......@@ -106,7 +107,7 @@ public interface ImConversationService extends BaseService<ImConversation> {
* @param param
* @return
*/
Boolean mutedGroupMember(@RequestBody MutedGroupParam param);
Boolean mutedGroupMember(@RequestBody MutedGroupMemberParam param);
/**
* 判断当前操作人是否为指定角色成员
......
......@@ -24,6 +24,7 @@ import com.wecloud.im.param.ImConversationPageParam;
import com.wecloud.im.param.ImConversationQueryParam;
import com.wecloud.im.param.ImConversationQueryVo;
import com.wecloud.im.param.ListConversationMembersParam;
import com.wecloud.im.param.MutedGroupMemberParam;
import com.wecloud.im.param.MutedGroupParam;
import com.wecloud.im.param.SetAdminsParam;
import com.wecloud.im.param.TransferOwnerParam;
......@@ -783,11 +784,78 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
muteGroupParam.setMuted(param.getMutedType());
imConversationMapper.updateById(muteGroupParam);
deleteCacheImConversationById(param.getConversationId());
// 下发事件通知 开启、取消 群禁言
// 查询该会话所有成员
List<ImConversationMembers> membersList = imConversationMembersService.list(
new QueryWrapper<ImConversationMembers>().lambda()
.eq(ImConversationMembers::getFkAppid, currentClient.getFkAppid())
.eq(ImConversationMembers::getFkConversationId, param.getConversationId())
.notIn(ImConversationMembers::getId, currentClient.getId())
);
if (membersList.isEmpty()) {
throw new BusinessException("群聊成员列表为空");
}
for (ImConversationMembers member : membersList) {
// 不关心事件是否发送成功
try {
// 保存事件消息
ImMessage imMessage = new ImMessage();
Map<String, Object> content = new HashMap<>();
content.put("operator", currentClient.getClientId());
content.put("passivityOperator", member.getClientId());
imMessage.setContent(JsonUtils.encodeJson(content));
// 保存消息至消息表
imMessage.setId(SnowflakeUtil.getId());
Integer msgType = MutedEnum.NO.getCode().equals(param.getMutedType()) ?
MsgTypeEnum.CONVERSATION_MUTED_CANCEL.getUriCode()
: MsgTypeEnum.CONVERSATION_MUTED.getUriCode();
imMessage.setMsgType(msgType);
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(param.getConversationId());
imMessageService.save(imMessage);
// 给所有成员下发事件消息
ImClient imClientReceiver = imClientService.getOne(new QueryWrapper<ImClient>().lambda()
.eq(ImClient::getFkAppid, currentClient.getFkAppid())
.eq(ImClient::getId, member.getFkClientId()));
if (imClientReceiver == null) {
continue;
}
// 封装响应的实体
ImMessageOnlineSend imMessageOnlineSend = new ImMessageOnlineSend();
imMessageOnlineSend.setMsgId(imMessage.getId());
imMessageOnlineSend.setCreateTime(new Date());
imMessageOnlineSend.setType(imMessage.getMsgType());
imMessageOnlineSend.setSender(currentClient.getClientId());
imMessageOnlineSend.setContent(content);
imMessageOnlineSend.setConversationId(param.getConversationId());
imMessageOnlineSend.setWithdraw(Boolean.FALSE);
imMessageOnlineSend.setEvent(Boolean.TRUE);
// 向接收方推送
WsResponse<ImMessageOnlineSend> responseModel = new WsResponse<>();
responseModel.setCmd(WsResponseCmdEnum.CONVERSATION_EVENT_MSG.getCmdCode());
ApiResult<Boolean> result = ApiResult.result(ApiCode.SUCCESS);
responseModel.setCode(result.getCode());
responseModel.setMsg(result.getMessage());
responseModel.setData(imMessageOnlineSend);
responseModel.setReqId(null);
channelSender.sendMsg(responseModel, imClientReceiver.getId());
} catch (Exception e) {
log.info("下发群禁言事件失败,接收人 {}", JSON.toJSONString(member));
}
}
return true;
}
@Override
public Boolean mutedGroupMember(MutedGroupParam param) {
public Boolean mutedGroupMember(MutedGroupMemberParam param) {
ImClient currentClient = imClientService.getCurrentClient();
if (!imConversationService.isBelongToRole(currentClient.getClientId(), param.getConversationId(),
Lists.newArrayList(GroupRoleEnum.OWNER.getCode(), GroupRoleEnum.ADMIN.getCode()))) {
......
......@@ -45,6 +45,12 @@ public enum MsgTypeEnum {
// 解散群聊 -1018
CONVERSATION_DISBAND(-1018),
// 群聊禁言 -1019
CONVERSATION_MUTED(-1019),
// 群聊取消禁言 -1020
CONVERSATION_MUTED_CANCEL(-1020),
;
private final int uriCode;
......
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