Commit bee3337925538407bb582e97c7ba4280689fdc35
1 parent
ac05257e
♻️ refactor(im): 重命名群聊和私聊消息相关方法以提高可读性
重构了 ImGroupMessageController 和 ImPrivateMessageController 中的方法名称, 将 sendMessage、pullMessages、readMessages 和 recallMessage 等方法重命名为 sendGroupMessage、pullGroupMessages、readGroupMessages 和 recallGroupMessage。 同时,更新了相关服务和测试类中的调用,确保一致性和可读性。
Showing
12 changed files
with
71 additions
and
123 deletions
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/controller/admin/message/ImGroupMessageController.java
| 1 | 1 | package cn.iocoder.yudao.module.im.controller.admin.message; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | -import cn.iocoder.yudao.module.im.controller.admin.message.vo.*; | |
| 5 | -import cn.iocoder.yudao.module.im.controller.admin.message.vo.group.ImGroupMessageReadReqVO; | |
| 6 | 4 | import cn.iocoder.yudao.module.im.controller.admin.message.vo.group.ImGroupMessageRespVO; |
| 7 | 5 | import cn.iocoder.yudao.module.im.controller.admin.message.vo.group.ImGroupMessageSendReqVO; |
| 8 | 6 | import cn.iocoder.yudao.module.im.dal.dataobject.message.ImGroupMessageDO; |
| ... | ... | @@ -35,40 +33,35 @@ public class ImGroupMessageController { |
| 35 | 33 | |
| 36 | 34 | @PostMapping("/send") |
| 37 | 35 | @Operation(summary = "发送群聊消息") |
| 38 | - public CommonResult<ImGroupMessageRespVO> sendMessage(@Valid @RequestBody ImGroupMessageSendReqVO reqVO) { | |
| 39 | - ImGroupMessageDO message = imGroupMessageService.sendMessage(getLoginUserId(), reqVO); | |
| 36 | + public CommonResult<ImGroupMessageRespVO> sendGroupMessage(@Valid @RequestBody ImGroupMessageSendReqVO reqVO) { | |
| 37 | + ImGroupMessageDO message = imGroupMessageService.sendGroupMessage(getLoginUserId(), reqVO); | |
| 40 | 38 | return success(toRespVO(message)); |
| 41 | 39 | } |
| 42 | 40 | |
| 43 | - // DONE @AI:需要在评估下,是否需要 nextMinId。结论:需要,前端用 nextMinId 做增量拉取游标 | |
| 44 | 41 | @GetMapping("/pull") |
| 45 | 42 | @Operation(summary = "拉取群聊消息(增量)") |
| 46 | 43 | @Parameter(name = "minId", description = "最小消息 id", required = true, example = "0") |
| 47 | 44 | @Parameter(name = "size", description = "拉取数量", required = true, example = "100") |
| 48 | - public CommonResult<ImMessagePullRespVO<ImGroupMessageRespVO>> pullMessages( | |
| 45 | + public CommonResult<List<ImGroupMessageRespVO>> pullGroupMessages( | |
| 49 | 46 | @RequestParam("minId") Long minId, |
| 50 | 47 | @RequestParam("size") Integer size) { |
| 51 | - List<ImGroupMessageDO> messages = imGroupMessageService.pullMessages(getLoginUserId(), minId, size); | |
| 52 | - ImMessagePullRespVO<ImGroupMessageRespVO> resp = new ImMessagePullRespVO<>(); | |
| 53 | - resp.setList(messages.stream().map(this::toRespVO).collect(Collectors.toList())); | |
| 54 | - resp.setNextMinId(messages.isEmpty() ? minId | |
| 55 | - : messages.get(messages.size() - 1).getId()); | |
| 56 | - return success(resp); | |
| 48 | + List<ImGroupMessageDO> messages = imGroupMessageService.pullGroupMessages(getLoginUserId(), minId, size); | |
| 49 | + return success(messages.stream().map(this::toRespVO).collect(Collectors.toList())); | |
| 57 | 50 | } |
| 58 | 51 | |
| 59 | - // DONE @AI:它是不是不用 VO。结论:需要 ReqVO,承载 groupId 字段并做参数校验 | |
| 60 | 52 | @PutMapping("/read") |
| 61 | 53 | @Operation(summary = "标记群聊消息已读") |
| 62 | - public CommonResult<Boolean> readMessages(@Valid @RequestBody ImGroupMessageReadReqVO reqVO) { | |
| 63 | - imGroupMessageService.readMessages(getLoginUserId(), reqVO.getGroupId()); | |
| 54 | + @Parameter(name = "groupId", description = "群编号", required = true, example = "1") | |
| 55 | + public CommonResult<Boolean> readGroupMessages(@RequestParam("groupId") Long groupId) { | |
| 56 | + imGroupMessageService.readGroupMessages(getLoginUserId(), groupId); | |
| 64 | 57 | return success(true); |
| 65 | 58 | } |
| 66 | 59 | |
| 67 | 60 | @DeleteMapping("/recall") |
| 68 | 61 | @Operation(summary = "撤回群聊消息") |
| 69 | 62 | @Parameter(name = "id", description = "消息编号", required = true, example = "1") |
| 70 | - public CommonResult<Boolean> recallMessage(@RequestParam("id") Long id) { | |
| 71 | - imGroupMessageService.recallMessage(getLoginUserId(), id); | |
| 63 | + public CommonResult<Boolean> recallGroupMessage(@RequestParam("id") Long id) { | |
| 64 | + imGroupMessageService.recallGroupMessage(getLoginUserId(), id); | |
| 72 | 65 | return success(true); |
| 73 | 66 | } |
| 74 | 67 | |
| ... | ... | @@ -77,10 +70,10 @@ public class ImGroupMessageController { |
| 77 | 70 | @Operation(summary = "获取群消息已读用户列表") |
| 78 | 71 | @Parameter(name = "groupId", description = "群编号", required = true, example = "1") |
| 79 | 72 | @Parameter(name = "messageId", description = "消息编号", required = true, example = "1") |
| 80 | - public CommonResult<List<String>> getReadUsers( | |
| 73 | + public CommonResult<List<String>> getGroupReadUsers( | |
| 81 | 74 | @RequestParam("groupId") Long groupId, |
| 82 | 75 | @RequestParam("messageId") Long messageId) { |
| 83 | - List<Long> readUserIds = imGroupMessageService.getReadUsers(getLoginUserId(), groupId, messageId); | |
| 76 | + List<Long> readUserIds = imGroupMessageService.getGroupReadUsers(getLoginUserId(), groupId, messageId); | |
| 84 | 77 | // Long -> String 转换 |
| 85 | 78 | return success(readUserIds.stream().map(String::valueOf).collect(Collectors.toList())); |
| 86 | 79 | } | ... | ... |
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/controller/admin/message/ImPrivateMessageController.java
| ... | ... | @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.im.controller.admin.message; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 5 | -import cn.iocoder.yudao.module.im.controller.admin.message.vo.*; | |
| 6 | 5 | import cn.iocoder.yudao.module.im.controller.admin.message.vo.privates.ImPrivateMessageRespVO; |
| 7 | 6 | import cn.iocoder.yudao.module.im.controller.admin.message.vo.privates.ImPrivateMessageSendReqVO; |
| 8 | 7 | import cn.iocoder.yudao.module.im.dal.dataobject.message.ImPrivateMessageDO; |
| ... | ... | @@ -34,8 +33,8 @@ public class ImPrivateMessageController { |
| 34 | 33 | |
| 35 | 34 | @PostMapping("/send") |
| 36 | 35 | @Operation(summary = "发送私聊消息") |
| 37 | - public CommonResult<ImPrivateMessageRespVO> sendMessage(@Valid @RequestBody ImPrivateMessageSendReqVO reqVO) { | |
| 38 | - ImPrivateMessageDO message = imPrivateMessageService.sendMessage(getLoginUserId(), reqVO); | |
| 36 | + public CommonResult<ImPrivateMessageRespVO> sendPrivateMessage(@Valid @RequestBody ImPrivateMessageSendReqVO reqVO) { | |
| 37 | + ImPrivateMessageDO message = imPrivateMessageService.sendPrivateMessage(getLoginUserId(), reqVO); | |
| 39 | 38 | return success(BeanUtils.toBean(message, ImPrivateMessageRespVO.class)); |
| 40 | 39 | } |
| 41 | 40 | |
| ... | ... | @@ -43,30 +42,25 @@ public class ImPrivateMessageController { |
| 43 | 42 | @Operation(summary = "拉取私聊消息(增量)") |
| 44 | 43 | @Parameter(name = "minId", description = "最小消息 id", required = true, example = "0") |
| 45 | 44 | @Parameter(name = "size", description = "拉取数量", required = true, example = "100") |
| 46 | - public CommonResult<ImMessagePullRespVO<ImPrivateMessageRespVO>> pullMessages( | |
| 47 | - @RequestParam("minId") Long minId, | |
| 48 | - @RequestParam("size") Integer size) { | |
| 49 | - List<ImPrivateMessageDO> messages = imPrivateMessageService.pullMessages(getLoginUserId(), minId, size); | |
| 50 | - ImMessagePullRespVO<ImPrivateMessageRespVO> resp = new ImMessagePullRespVO<>(); | |
| 51 | - resp.setList(BeanUtils.toBean(messages, ImPrivateMessageRespVO.class)); | |
| 52 | - resp.setNextMinId(messages.isEmpty() ? minId | |
| 53 | - : messages.get(messages.size() - 1).getId()); | |
| 54 | - return success(resp); | |
| 45 | + public CommonResult<List<ImPrivateMessageRespVO>> pullPrivateMessages(@RequestParam("minId") Long minId, | |
| 46 | + @RequestParam("size") Integer size) { | |
| 47 | + List<ImPrivateMessageDO> messages = imPrivateMessageService.pullPrivateMessages(getLoginUserId(), minId, size); | |
| 48 | + return success(BeanUtils.toBean(messages, ImPrivateMessageRespVO.class)); | |
| 55 | 49 | } |
| 56 | 50 | |
| 57 | 51 | @PutMapping("/read") |
| 58 | 52 | @Operation(summary = "标记私聊消息已读") |
| 59 | 53 | @Parameter(name = "friendId", description = "好友用户编号", required = true, example = "2") |
| 60 | - public CommonResult<Boolean> readMessages(@RequestParam("friendId") Long friendId) { | |
| 61 | - imPrivateMessageService.readMessages(getLoginUserId(), friendId); | |
| 54 | + public CommonResult<Boolean> readPrivateMessages(@RequestParam("friendId") Long friendId) { | |
| 55 | + imPrivateMessageService.readPrivateMessages(getLoginUserId(), friendId); | |
| 62 | 56 | return success(true); |
| 63 | 57 | } |
| 64 | 58 | |
| 65 | 59 | @DeleteMapping("/recall") |
| 66 | 60 | @Operation(summary = "撤回私聊消息") |
| 67 | 61 | @Parameter(name = "id", description = "消息编号", required = true, example = "1") |
| 68 | - public CommonResult<Boolean> recallMessage(@RequestParam("id") Long id) { | |
| 69 | - imPrivateMessageService.recallMessage(getLoginUserId(), id); | |
| 62 | + public CommonResult<Boolean> recallPrivateMessage(@RequestParam("id") Long id) { | |
| 63 | + imPrivateMessageService.recallPrivateMessage(getLoginUserId(), id); | |
| 70 | 64 | return success(true); |
| 71 | 65 | } |
| 72 | 66 | ... | ... |
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/controller/admin/message/vo/ImMessagePullRespVO.java deleted
| 1 | -package cn.iocoder.yudao.module.im.controller.admin.message.vo; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.Data; | |
| 5 | - | |
| 6 | -import java.util.List; | |
| 7 | - | |
| 8 | -/** | |
| 9 | - * 消息拉取 Response VO | |
| 10 | - */ | |
| 11 | -@Schema(description = "管理后台 - 消息拉取 Response VO") | |
| 12 | -@Data | |
| 13 | -public class ImMessagePullRespVO<T> { | |
| 14 | - | |
| 15 | - @Schema(description = "消息列表") | |
| 16 | - private List<T> list; | |
| 17 | - | |
| 18 | - @Schema(description = "下次拉取的最小 id", example = "100") | |
| 19 | - private Long nextMinId; | |
| 20 | - | |
| 21 | -} |
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/controller/admin/message/vo/group/ImGroupMessageReadReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.im.controller.admin.message.vo.group; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import jakarta.validation.constraints.NotNull; | |
| 5 | -import lombok.Data; | |
| 6 | - | |
| 7 | -/** | |
| 8 | - * 群聊已读 Request VO | |
| 9 | - */ | |
| 10 | -@Schema(description = "管理后台 - 群聊已读 Request VO") | |
| 11 | -@Data | |
| 12 | -public class ImGroupMessageReadReqVO { | |
| 13 | - | |
| 14 | - @Schema(description = "群编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 15 | - @NotNull(message = "群编号不能为空") | |
| 16 | - private Long groupId; | |
| 17 | - | |
| 18 | -} |
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/dal/dataobject/message/ImGroupMessageDO.java
| 1 | 1 | package cn.iocoder.yudao.module.im.dal.dataobject.message; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler; | |
| 4 | 5 | import cn.iocoder.yudao.module.im.dal.dataobject.group.ImGroupDO; |
| 5 | 6 | import cn.iocoder.yudao.module.im.enums.message.ImGroupMessageReceiptStatusEnum; |
| 6 | 7 | import cn.iocoder.yudao.module.im.enums.message.ImMessageStatusEnum; |
| ... | ... | @@ -9,7 +10,6 @@ import com.baomidou.mybatisplus.annotation.KeySequence; |
| 9 | 10 | import com.baomidou.mybatisplus.annotation.TableField; |
| 10 | 11 | import com.baomidou.mybatisplus.annotation.TableId; |
| 11 | 12 | import com.baomidou.mybatisplus.annotation.TableName; |
| 12 | -import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; | |
| 13 | 13 | import lombok.*; |
| 14 | 14 | |
| 15 | 15 | import java.time.LocalDateTime; |
| ... | ... | @@ -77,20 +77,20 @@ public class ImGroupMessageDO extends BaseDO { |
| 77 | 77 | */ |
| 78 | 78 | private LocalDateTime sendTime; |
| 79 | 79 | /** |
| 80 | - * 定向接收用户编号列表 | |
| 80 | + * 定向接收用户编号列表,以逗号分隔 | |
| 81 | 81 | * <p> |
| 82 | 82 | * 为空表示全员可见 |
| 83 | 83 | * |
| 84 | 84 | * 关联 AdminUserDO 的 id 字段 |
| 85 | 85 | */ |
| 86 | - @TableField(typeHandler = JacksonTypeHandler.class) | |
| 86 | + @TableField(typeHandler = LongListTypeHandler.class) | |
| 87 | 87 | private List<Long> receiverUserIds; |
| 88 | 88 | /** |
| 89 | - * @ 目标用户编号列表 | |
| 89 | + * @ 目标用户编号列表,以逗号分隔 | |
| 90 | 90 | * |
| 91 | 91 | * 关联 AdminUserDO 的 id 字段 |
| 92 | 92 | */ |
| 93 | - @TableField(typeHandler = JacksonTypeHandler.class) | |
| 93 | + @TableField(typeHandler = LongListTypeHandler.class) | |
| 94 | 94 | private List<Long> atUserIds; |
| 95 | 95 | /** |
| 96 | 96 | * 回执状态 | ... | ... |
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/service/message/ImGroupMessageService.java
| ... | ... | @@ -19,7 +19,7 @@ public interface ImGroupMessageService { |
| 19 | 19 | * @param reqVO 发送请求 |
| 20 | 20 | * @return 消息 |
| 21 | 21 | */ |
| 22 | - ImGroupMessageDO sendMessage(Long senderId, ImGroupMessageSendReqVO reqVO); | |
| 22 | + ImGroupMessageDO sendGroupMessage(Long senderId, ImGroupMessageSendReqVO reqVO); | |
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * 拉取群聊消息(增量) |
| ... | ... | @@ -29,7 +29,7 @@ public interface ImGroupMessageService { |
| 29 | 29 | * @param size 拉取数量 |
| 30 | 30 | * @return 消息列表 |
| 31 | 31 | */ |
| 32 | - List<ImGroupMessageDO> pullMessages(Long userId, Long minId, Integer size); | |
| 32 | + List<ImGroupMessageDO> pullGroupMessages(Long userId, Long minId, Integer size); | |
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * 标记群聊消息已读 |
| ... | ... | @@ -37,7 +37,7 @@ public interface ImGroupMessageService { |
| 37 | 37 | * @param userId 当前用户编号 |
| 38 | 38 | * @param groupId 群编号 |
| 39 | 39 | */ |
| 40 | - void readMessages(Long userId, Long groupId); | |
| 40 | + void readGroupMessages(Long userId, Long groupId); | |
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * 撤回群聊消息 |
| ... | ... | @@ -45,7 +45,7 @@ public interface ImGroupMessageService { |
| 45 | 45 | * @param userId 当前用户编号 |
| 46 | 46 | * @param messageId 消息编号 |
| 47 | 47 | */ |
| 48 | - void recallMessage(Long userId, Long messageId); | |
| 48 | + void recallGroupMessage(Long userId, Long messageId); | |
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | 51 | * 获取群消息的已读用户列表 |
| ... | ... | @@ -55,6 +55,6 @@ public interface ImGroupMessageService { |
| 55 | 55 | * @param messageId 消息编号 |
| 56 | 56 | * @return 已读用户编号列表 |
| 57 | 57 | */ |
| 58 | - List<Long> getReadUsers(Long userId, Long groupId, Long messageId); | |
| 58 | + List<Long> getGroupReadUsers(Long userId, Long groupId, Long messageId); | |
| 59 | 59 | |
| 60 | 60 | } | ... | ... |
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/service/message/ImGroupMessageServiceImpl.java
| ... | ... | @@ -55,7 +55,7 @@ public class ImGroupMessageServiceImpl implements ImGroupMessageService { |
| 55 | 55 | private WebSocketMessageSender webSocketMessageSender; |
| 56 | 56 | |
| 57 | 57 | @Override |
| 58 | - public ImGroupMessageDO sendMessage(Long senderId, ImGroupMessageSendReqVO reqVO) { | |
| 58 | + public ImGroupMessageDO sendGroupMessage(Long senderId, ImGroupMessageSendReqVO reqVO) { | |
| 59 | 59 | // 1. 幂等校验 |
| 60 | 60 | ImGroupMessageDO existing = imGroupMessageMapper.selectBySenderIdAndClientMessageId( |
| 61 | 61 | senderId, reqVO.getClientMessageId()); |
| ... | ... | @@ -100,7 +100,7 @@ public class ImGroupMessageServiceImpl implements ImGroupMessageService { |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | @Override |
| 103 | - public List<ImGroupMessageDO> pullMessages(Long userId, Long minId, Integer size) { | |
| 103 | + public List<ImGroupMessageDO> pullGroupMessages(Long userId, Long minId, Integer size) { | |
| 104 | 104 | if (size > MAX_PULL_SIZE) { |
| 105 | 105 | throw exception(MESSAGE_PULL_SIZE_EXCEEDED); |
| 106 | 106 | } |
| ... | ... | @@ -145,7 +145,7 @@ public class ImGroupMessageServiceImpl implements ImGroupMessageService { |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | @Override |
| 148 | - public void readMessages(Long userId, Long groupId) { | |
| 148 | + public void readGroupMessages(Long userId, Long groupId) { | |
| 149 | 149 | // 1. 校验用户在群中(权限校验) |
| 150 | 150 | ImGroupMemberDO member = imGroupMemberService.getGroupMember(groupId, userId); |
| 151 | 151 | if (member == null || CommonStatusEnum.DISABLE.getStatus().equals(member.getStatus())) { |
| ... | ... | @@ -173,7 +173,7 @@ public class ImGroupMessageServiceImpl implements ImGroupMessageService { |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | @Override |
| 176 | - public void recallMessage(Long userId, Long messageId) { | |
| 176 | + public void recallGroupMessage(Long userId, Long messageId) { | |
| 177 | 177 | // 1. 校验消息存在 |
| 178 | 178 | ImGroupMessageDO message = imGroupMessageMapper.selectById(messageId); |
| 179 | 179 | if (message == null) { |
| ... | ... | @@ -210,7 +210,7 @@ public class ImGroupMessageServiceImpl implements ImGroupMessageService { |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | @Override |
| 213 | - public List<Long> getReadUsers(Long userId, Long groupId, Long messageId) { | |
| 213 | + public List<Long> getGroupReadUsers(Long userId, Long groupId, Long messageId) { | |
| 214 | 214 | // 1. 校验用户在群中(权限校验) |
| 215 | 215 | ImGroupMemberDO currentMember = imGroupMemberService.getGroupMember(groupId, userId); |
| 216 | 216 | if (currentMember == null || CommonStatusEnum.DISABLE.getStatus().equals(currentMember.getStatus())) { | ... | ... |
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/service/message/ImPrivateMessageService.java
| ... | ... | @@ -19,7 +19,7 @@ public interface ImPrivateMessageService { |
| 19 | 19 | * @param reqVO 发送请求 |
| 20 | 20 | * @return 消息 |
| 21 | 21 | */ |
| 22 | - ImPrivateMessageDO sendMessage(Long senderId, ImPrivateMessageSendReqVO reqVO); | |
| 22 | + ImPrivateMessageDO sendPrivateMessage(Long senderId, ImPrivateMessageSendReqVO reqVO); | |
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * 拉取私聊消息(增量) |
| ... | ... | @@ -29,7 +29,7 @@ public interface ImPrivateMessageService { |
| 29 | 29 | * @param size 拉取数量 |
| 30 | 30 | * @return 消息列表 |
| 31 | 31 | */ |
| 32 | - List<ImPrivateMessageDO> pullMessages(Long userId, Long minId, Integer size); | |
| 32 | + List<ImPrivateMessageDO> pullPrivateMessages(Long userId, Long minId, Integer size); | |
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * 标记私聊消息已读 |
| ... | ... | @@ -37,7 +37,7 @@ public interface ImPrivateMessageService { |
| 37 | 37 | * @param userId 当前用户编号 |
| 38 | 38 | * @param friendId 好友用户编号 |
| 39 | 39 | */ |
| 40 | - void readMessages(Long userId, Long friendId); | |
| 40 | + void readPrivateMessages(Long userId, Long friendId); | |
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * 撤回私聊消息 |
| ... | ... | @@ -45,6 +45,6 @@ public interface ImPrivateMessageService { |
| 45 | 45 | * @param userId 当前用户编号 |
| 46 | 46 | * @param messageId 消息编号 |
| 47 | 47 | */ |
| 48 | - void recallMessage(Long userId, Long messageId); | |
| 48 | + void recallPrivateMessage(Long userId, Long messageId); | |
| 49 | 49 | |
| 50 | 50 | } | ... | ... |
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/service/message/ImPrivateMessageServiceImpl.java
| ... | ... | @@ -50,7 +50,7 @@ public class ImPrivateMessageServiceImpl implements ImPrivateMessageService { |
| 50 | 50 | private WebSocketMessageSender webSocketMessageSender; |
| 51 | 51 | |
| 52 | 52 | @Override |
| 53 | - public ImPrivateMessageDO sendMessage(Long senderId, ImPrivateMessageSendReqVO reqVO) { | |
| 53 | + public ImPrivateMessageDO sendPrivateMessage(Long senderId, ImPrivateMessageSendReqVO reqVO) { | |
| 54 | 54 | // 1.1 幂等校验:根据 senderId + clientMessageId 查重 |
| 55 | 55 | ImPrivateMessageDO existing = imPrivateMessageMapper.selectBySenderIdAndClientMessageId( |
| 56 | 56 | senderId, reqVO.getClientMessageId()); |
| ... | ... | @@ -80,7 +80,7 @@ public class ImPrivateMessageServiceImpl implements ImPrivateMessageService { |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | @Override |
| 83 | - public List<ImPrivateMessageDO> pullMessages(Long userId, Long minId, Integer size) { | |
| 83 | + public List<ImPrivateMessageDO> pullPrivateMessages(Long userId, Long minId, Integer size) { | |
| 84 | 84 | if (size > MAX_PULL_SIZE) { |
| 85 | 85 | throw exception(MESSAGE_PULL_SIZE_EXCEEDED); |
| 86 | 86 | } |
| ... | ... | @@ -89,7 +89,7 @@ public class ImPrivateMessageServiceImpl implements ImPrivateMessageService { |
| 89 | 89 | |
| 90 | 90 | // DONE @芋艿:已 review,逻辑正确 |
| 91 | 91 | @Override |
| 92 | - public void readMessages(Long userId, Long friendId) { | |
| 92 | + public void readPrivateMessages(Long userId, Long friendId) { | |
| 93 | 93 | // 1. 批量更新消息状态为已读 |
| 94 | 94 | int updated = imPrivateMessageMapper.updateStatusToRead(userId, friendId); |
| 95 | 95 | if (updated == 0) { |
| ... | ... | @@ -114,7 +114,7 @@ public class ImPrivateMessageServiceImpl implements ImPrivateMessageService { |
| 114 | 114 | |
| 115 | 115 | // DONE @芋艿:已 review,逻辑正确 |
| 116 | 116 | @Override |
| 117 | - public void recallMessage(Long userId, Long messageId) { | |
| 117 | + public void recallPrivateMessage(Long userId, Long messageId) { | |
| 118 | 118 | // 1.1 校验消息存在 |
| 119 | 119 | ImPrivateMessageDO message = imPrivateMessageMapper.selectById(messageId); |
| 120 | 120 | if (message == null) { | ... | ... |
yudao-module-im/yudao-module-im-biz/src/test/java/cn/iocoder/yudao/module/im/service/message/ImGroupMessageServiceImplTest.java
| ... | ... | @@ -96,7 +96,7 @@ public class ImGroupMessageServiceImplTest { |
| 96 | 96 | }); |
| 97 | 97 | |
| 98 | 98 | // 调用 |
| 99 | - ImGroupMessageDO result = groupMessageService.sendMessage(1L, reqVO); | |
| 99 | + ImGroupMessageDO result = groupMessageService.sendGroupMessage(1L, reqVO); | |
| 100 | 100 | |
| 101 | 101 | // 断言 |
| 102 | 102 | assertNotNull(result); |
| ... | ... | @@ -121,7 +121,7 @@ public class ImGroupMessageServiceImplTest { |
| 121 | 121 | .thenReturn(existing); |
| 122 | 122 | |
| 123 | 123 | // 调用 |
| 124 | - ImGroupMessageDO result = groupMessageService.sendMessage(1L, reqVO); | |
| 124 | + ImGroupMessageDO result = groupMessageService.sendGroupMessage(1L, reqVO); | |
| 125 | 125 | |
| 126 | 126 | // 断言 |
| 127 | 127 | assertEquals(100L, result.getId()); |
| ... | ... | @@ -141,7 +141,7 @@ public class ImGroupMessageServiceImplTest { |
| 141 | 141 | |
| 142 | 142 | // 调用并断言 |
| 143 | 143 | ServiceException exception = assertThrows(ServiceException.class, |
| 144 | - () -> groupMessageService.sendMessage(1L, reqVO)); | |
| 144 | + () -> groupMessageService.sendGroupMessage(1L, reqVO)); | |
| 145 | 145 | assertEquals(GROUP_MEMBER_NOT_IN_GROUP.getCode(), exception.getCode()); |
| 146 | 146 | } |
| 147 | 147 | |
| ... | ... | @@ -168,7 +168,7 @@ public class ImGroupMessageServiceImplTest { |
| 168 | 168 | .thenReturn(List.of(beforeJoin, afterJoin)); |
| 169 | 169 | |
| 170 | 170 | // 调用 |
| 171 | - List<ImGroupMessageDO> result = groupMessageService.pullMessages(1L, 0L, 100); | |
| 171 | + List<ImGroupMessageDO> result = groupMessageService.pullGroupMessages(1L, 0L, 100); | |
| 172 | 172 | |
| 173 | 173 | // 断言:入群前消息不可见 |
| 174 | 174 | assertEquals(1, result.size()); |
| ... | ... | @@ -197,7 +197,7 @@ public class ImGroupMessageServiceImplTest { |
| 197 | 197 | .thenReturn(List.of(beforeQuit, afterQuit)); |
| 198 | 198 | |
| 199 | 199 | // 调用 |
| 200 | - List<ImGroupMessageDO> result = groupMessageService.pullMessages(1L, 0L, 100); | |
| 200 | + List<ImGroupMessageDO> result = groupMessageService.pullGroupMessages(1L, 0L, 100); | |
| 201 | 201 | |
| 202 | 202 | // 断言:退群后消息不可见 |
| 203 | 203 | assertEquals(1, result.size()); |
| ... | ... | @@ -216,7 +216,7 @@ public class ImGroupMessageServiceImplTest { |
| 216 | 216 | // 定向接收消息:只给用户 2 和 3 |
| 217 | 217 | ImGroupMessageDO directedMsg = ImGroupMessageDO.builder() |
| 218 | 218 | .id(1L).groupId(10L).senderId(5L) |
| 219 | - .receiverUserIds("2,3") | |
| 219 | + .receiverUserIds(List.of(2L, 3L)) | |
| 220 | 220 | .sendTime(LocalDateTime.of(2026, 4, 12, 10, 0, 0)).build(); |
| 221 | 221 | // 全员消息 |
| 222 | 222 | ImGroupMessageDO allMsg = ImGroupMessageDO.builder() |
| ... | ... | @@ -226,7 +226,7 @@ public class ImGroupMessageServiceImplTest { |
| 226 | 226 | .thenReturn(List.of(directedMsg, allMsg)); |
| 227 | 227 | |
| 228 | 228 | // 调用 |
| 229 | - List<ImGroupMessageDO> result = groupMessageService.pullMessages(1L, 0L, 100); | |
| 229 | + List<ImGroupMessageDO> result = groupMessageService.pullGroupMessages(1L, 0L, 100); | |
| 230 | 230 | |
| 231 | 231 | // 断言:定向接收的消息用户 1 看不到,只能看到全员消息 |
| 232 | 232 | assertEquals(1, result.size()); |
| ... | ... | @@ -244,17 +244,17 @@ public class ImGroupMessageServiceImplTest { |
| 244 | 244 | |
| 245 | 245 | ImGroupMessageDO atMsg = ImGroupMessageDO.builder() |
| 246 | 246 | .id(1L).groupId(10L).senderId(2L) |
| 247 | - .atUserIds("1,3") | |
| 247 | + .atUserIds(List.of(1L, 3L)) | |
| 248 | 248 | .sendTime(LocalDateTime.of(2026, 4, 12, 10, 0, 0)).build(); |
| 249 | 249 | when(imGroupMessageMapper.selectListByMinId(List.of(10L), 0L, 100)) |
| 250 | 250 | .thenReturn(List.of(atMsg)); |
| 251 | 251 | |
| 252 | 252 | // 调用 |
| 253 | - List<ImGroupMessageDO> result = groupMessageService.pullMessages(1L, 0L, 100); | |
| 253 | + List<ImGroupMessageDO> result = groupMessageService.pullGroupMessages(1L, 0L, 100); | |
| 254 | 254 | |
| 255 | 255 | // 断言:@ 字段正确返回 |
| 256 | 256 | assertEquals(1, result.size()); |
| 257 | - assertEquals("1,3", result.get(0).getAtUserIds()); | |
| 257 | + assertEquals(List.of(1L, 3L), result.get(0).getAtUserIds()); | |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | // ========== 撤回测试 ========== |
| ... | ... | @@ -279,7 +279,7 @@ public class ImGroupMessageServiceImplTest { |
| 279 | 279 | when(imGroupMemberService.selectByGroupId(10L)).thenReturn(members); |
| 280 | 280 | |
| 281 | 281 | // 调用 |
| 282 | - groupMessageService.recallMessage(1L, 50L); | |
| 282 | + groupMessageService.recallGroupMessage(1L, 50L); | |
| 283 | 283 | |
| 284 | 284 | // 断言:只给 2 个活跃成员发送 RECALL 事件(userId=3 已退群) |
| 285 | 285 | verify(webSocketMessageSender, times(2)).sendObject(anyInt(), anyLong(), anyString(), any()); |
| ... | ... | @@ -294,7 +294,7 @@ public class ImGroupMessageServiceImplTest { |
| 294 | 294 | |
| 295 | 295 | // 调用并断言:越权校验 |
| 296 | 296 | ServiceException exception = assertThrows(ServiceException.class, |
| 297 | - () -> groupMessageService.readMessages(1L, 10L)); | |
| 297 | + () -> groupMessageService.readGroupMessages(1L, 10L)); | |
| 298 | 298 | assertEquals(GROUP_MEMBER_NOT_IN_GROUP.getCode(), exception.getCode()); |
| 299 | 299 | } |
| 300 | 300 | |
| ... | ... | @@ -340,7 +340,7 @@ public class ImGroupMessageServiceImplTest { |
| 340 | 340 | when(groupReadPositionRedisDAO.getAllReadPositions(10L)).thenReturn(positions); |
| 341 | 341 | |
| 342 | 342 | // 调用:查询 messageId=80 的已读用户 |
| 343 | - List<Long> readUsers = groupMessageService.getReadUsers(1L, 10L, 80L); | |
| 343 | + List<Long> readUsers = groupMessageService.getGroupReadUsers(1L, 10L, 80L); | |
| 344 | 344 | |
| 345 | 345 | // 断言: |
| 346 | 346 | // 用户 1: 可见 + readMaxId=100>=80 → 已读 ✓(但排除发送者?不是发送者,所以算入) |
| ... | ... | @@ -361,7 +361,7 @@ public class ImGroupMessageServiceImplTest { |
| 361 | 361 | |
| 362 | 362 | // 调用并断言:越权校验 |
| 363 | 363 | ServiceException exception = assertThrows(ServiceException.class, |
| 364 | - () -> groupMessageService.getReadUsers(99L, 10L, 80L)); | |
| 364 | + () -> groupMessageService.getGroupReadUsers(99L, 10L, 80L)); | |
| 365 | 365 | assertEquals(GROUP_MEMBER_NOT_IN_GROUP.getCode(), exception.getCode()); |
| 366 | 366 | } |
| 367 | 367 | ... | ... |
yudao-module-im/yudao-module-im-biz/src/test/java/cn/iocoder/yudao/module/im/service/message/ImPrivateMessageServiceImplTest.java
| ... | ... | @@ -66,7 +66,7 @@ public class ImPrivateMessageServiceImplTest { |
| 66 | 66 | }); |
| 67 | 67 | |
| 68 | 68 | // 调用 |
| 69 | - ImPrivateMessageDO result = privateMessageService.sendMessage(1L, reqVO); | |
| 69 | + ImPrivateMessageDO result = privateMessageService.sendPrivateMessage(1L, reqVO); | |
| 70 | 70 | |
| 71 | 71 | // 断言 |
| 72 | 72 | assertNotNull(result); |
| ... | ... | @@ -95,7 +95,7 @@ public class ImPrivateMessageServiceImplTest { |
| 95 | 95 | .thenReturn(existingMessage); |
| 96 | 96 | |
| 97 | 97 | // 调用 |
| 98 | - ImPrivateMessageDO result = privateMessageService.sendMessage(1L, reqVO); | |
| 98 | + ImPrivateMessageDO result = privateMessageService.sendPrivateMessage(1L, reqVO); | |
| 99 | 99 | |
| 100 | 100 | // 断言:返回已存在的消息 |
| 101 | 101 | assertEquals(100L, result.getId()); |
| ... | ... | @@ -114,7 +114,7 @@ public class ImPrivateMessageServiceImplTest { |
| 114 | 114 | |
| 115 | 115 | // 调用并断言 |
| 116 | 116 | ServiceException exception = assertThrows(ServiceException.class, |
| 117 | - () -> privateMessageService.sendMessage(1L, reqVO)); | |
| 117 | + () -> privateMessageService.sendPrivateMessage(1L, reqVO)); | |
| 118 | 118 | assertEquals(FRIEND_NOT_FRIEND.getCode(), exception.getCode()); |
| 119 | 119 | } |
| 120 | 120 | |
| ... | ... | @@ -130,7 +130,7 @@ public class ImPrivateMessageServiceImplTest { |
| 130 | 130 | when(imPrivateMessageMapper.selectListByMinId(1L, 0L, 100)).thenReturn(mockMessages); |
| 131 | 131 | |
| 132 | 132 | // 调用 |
| 133 | - List<ImPrivateMessageDO> result = privateMessageService.pullMessages(1L, 0L, 100); | |
| 133 | + List<ImPrivateMessageDO> result = privateMessageService.pullPrivateMessages(1L, 0L, 100); | |
| 134 | 134 | |
| 135 | 135 | // 断言 |
| 136 | 136 | assertEquals(2, result.size()); |
| ... | ... | @@ -140,7 +140,7 @@ public class ImPrivateMessageServiceImplTest { |
| 140 | 140 | public void testPullMessages_sizeExceeded() { |
| 141 | 141 | // 调用并断言 |
| 142 | 142 | ServiceException exception = assertThrows(ServiceException.class, |
| 143 | - () -> privateMessageService.pullMessages(1L, 0L, 1001)); | |
| 143 | + () -> privateMessageService.pullPrivateMessages(1L, 0L, 1001)); | |
| 144 | 144 | assertEquals(MESSAGE_PULL_SIZE_EXCEEDED.getCode(), exception.getCode()); |
| 145 | 145 | } |
| 146 | 146 | |
| ... | ... | @@ -152,7 +152,7 @@ public class ImPrivateMessageServiceImplTest { |
| 152 | 152 | when(imPrivateMessageMapper.updateStatusToRead(1L, 2L)).thenReturn(3); |
| 153 | 153 | |
| 154 | 154 | // 调用 |
| 155 | - privateMessageService.readMessages(1L, 2L); | |
| 155 | + privateMessageService.readPrivateMessages(1L, 2L); | |
| 156 | 156 | |
| 157 | 157 | // 断言:发送了 READ 和 RECEIPT 事件 |
| 158 | 158 | verify(webSocketMessageSender, times(2)).sendObject(anyInt(), anyLong(), anyString(), any()); |
| ... | ... | @@ -170,7 +170,7 @@ public class ImPrivateMessageServiceImplTest { |
| 170 | 170 | when(imPrivateMessageMapper.updateById(any(ImPrivateMessageDO.class))).thenReturn(1); |
| 171 | 171 | |
| 172 | 172 | // 调用 |
| 173 | - privateMessageService.recallMessage(1L, 10L); | |
| 173 | + privateMessageService.recallPrivateMessage(1L, 10L); | |
| 174 | 174 | |
| 175 | 175 | // 断言 |
| 176 | 176 | verify(imPrivateMessageMapper).updateById(any(ImPrivateMessageDO.class)); |
| ... | ... | @@ -188,7 +188,7 @@ public class ImPrivateMessageServiceImplTest { |
| 188 | 188 | |
| 189 | 189 | // 调用并断言 |
| 190 | 190 | ServiceException exception = assertThrows(ServiceException.class, |
| 191 | - () -> privateMessageService.recallMessage(1L, 10L)); | |
| 191 | + () -> privateMessageService.recallPrivateMessage(1L, 10L)); | |
| 192 | 192 | assertEquals(MESSAGE_RECALL_DENIED.getCode(), exception.getCode()); |
| 193 | 193 | } |
| 194 | 194 | |
| ... | ... | @@ -202,7 +202,7 @@ public class ImPrivateMessageServiceImplTest { |
| 202 | 202 | |
| 203 | 203 | // 调用并断言 |
| 204 | 204 | ServiceException exception = assertThrows(ServiceException.class, |
| 205 | - () -> privateMessageService.recallMessage(1L, 10L)); | |
| 205 | + () -> privateMessageService.recallPrivateMessage(1L, 10L)); | |
| 206 | 206 | assertEquals(MESSAGE_ALREADY_RECALLED.getCode(), exception.getCode()); |
| 207 | 207 | } |
| 208 | 208 | ... | ... |
yudao-module-im/yudao-module-im-biz/src/test/java/cn/iocoder/yudao/module/im/service/message/ImWebSocketEventTest.java
| ... | ... | @@ -60,7 +60,7 @@ public class ImWebSocketEventTest { |
| 60 | 60 | }); |
| 61 | 61 | |
| 62 | 62 | // 调用 |
| 63 | - privateMessageService.sendMessage(1L, reqVO); | |
| 63 | + privateMessageService.sendPrivateMessage(1L, reqVO); | |
| 64 | 64 | |
| 65 | 65 | // 捕获 WebSocket 调用 |
| 66 | 66 | ArgumentCaptor<String> typeCaptor = ArgumentCaptor.forClass(String.class); |
| ... | ... | @@ -87,7 +87,7 @@ public class ImWebSocketEventTest { |
| 87 | 87 | when(imPrivateMessageMapper.updateStatusToRead(1L, 2L)).thenReturn(1); |
| 88 | 88 | |
| 89 | 89 | // 调用 |
| 90 | - privateMessageService.readMessages(1L, 2L); | |
| 90 | + privateMessageService.readPrivateMessages(1L, 2L); | |
| 91 | 91 | |
| 92 | 92 | // 捕获 |
| 93 | 93 | ArgumentCaptor<String> typeCaptor = ArgumentCaptor.forClass(String.class); |
| ... | ... | @@ -112,7 +112,7 @@ public class ImWebSocketEventTest { |
| 112 | 112 | when(imPrivateMessageMapper.updateById(any(ImPrivateMessageDO.class))).thenReturn(1); |
| 113 | 113 | |
| 114 | 114 | // 调用 |
| 115 | - privateMessageService.recallMessage(1L, 10L); | |
| 115 | + privateMessageService.recallPrivateMessage(1L, 10L); | |
| 116 | 116 | |
| 117 | 117 | // 捕获 |
| 118 | 118 | ArgumentCaptor<String> typeCaptor = ArgumentCaptor.forClass(String.class); | ... | ... |