Commit 2c5287a9b2c9fe8afb008a0bf1c4d9cc473f3304

Authored by YunaiV
1 parent f1731e44

【修复】IM:基于 offset 读取不到消息时,报 NPE 问题

yudao-module-im/yudao-module-im-api/src/main/java/cn/iocoder/yudao/module/im/enums/message/ImMessageContentTypeEnum.java
@@ -33,10 +33,13 @@ public enum ImMessageContentTypeEnum implements IntArrayValuable { @@ -33,10 +33,13 @@ public enum ImMessageContentTypeEnum implements IntArrayValuable {
33 QUOTE(114, "引用消息"), 33 QUOTE(114, "引用消息"),
34 FACE(115, "表情消息"), 34 FACE(115, "表情消息"),
35 ADVANCED_REVOKE(118, "高级撤回消息"), 35 ADVANCED_REVOKE(118, "高级撤回消息"),
  36 +
36 // ========== 好友通知 1200-1299 =========== 37 // ========== 好友通知 1200-1299 ===========
37 FRIEND_ADDED(1201, "双方成为好友通知"), 38 FRIEND_ADDED(1201, "双方成为好友通知"),
  39 +
38 // ========== 系统通知 1400 ========== 40 // ========== 系统通知 1400 ==========
39 OA_NOTIFICATION(1400, "系统通知"), 41 OA_NOTIFICATION(1400, "系统通知"),
  42 +
40 // ========== 群相关 1500-1599 ========== 43 // ========== 群相关 1500-1599 ==========
41 GROUP_CREATED(1501, "群创建通知"), 44 GROUP_CREATED(1501, "群创建通知"),
42 GROUP_INFO_CHANGED(1502, "群信息改变通知"), 45 GROUP_INFO_CHANGED(1502, "群信息改变通知"),
@@ -53,6 +56,7 @@ public enum ImMessageContentTypeEnum implements IntArrayValuable { @@ -53,6 +56,7 @@ public enum ImMessageContentTypeEnum implements IntArrayValuable {
53 GROUP_ANNOUNCEMENT_UPDATED(1519, "群公告改变通知"), 56 GROUP_ANNOUNCEMENT_UPDATED(1519, "群公告改变通知"),
54 GROUP_NAME_UPDATED(1520, "群名称改变通知"), 57 GROUP_NAME_UPDATED(1520, "群名称改变通知"),
55 58
  59 + // TODO 芋艿:其它
56 BURN_CHANGE(1701, "阅后即焚开启或关闭通知"), 60 BURN_CHANGE(1701, "阅后即焚开启或关闭通知"),
57 REVOKE(2101, "撤回消息通知");; 61 REVOKE(2101, "撤回消息通知");;
58 62
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/service/message/ImMessageServiceImpl.java
1 package cn.iocoder.yudao.module.im.service.message; 1 package cn.iocoder.yudao.module.im.service.message;
2 2
3 import cn.hutool.core.bean.BeanUtil; 3 import cn.hutool.core.bean.BeanUtil;
  4 +import cn.hutool.core.collection.CollUtil;
4 import cn.iocoder.yudao.module.im.controller.admin.message.vo.ImMessageListReqVO; 5 import cn.iocoder.yudao.module.im.controller.admin.message.vo.ImMessageListReqVO;
5 import cn.iocoder.yudao.module.im.controller.admin.message.vo.ImMessageSendReqVO; 6 import cn.iocoder.yudao.module.im.controller.admin.message.vo.ImMessageSendReqVO;
6 import cn.iocoder.yudao.module.im.dal.dataobject.group.ImGroupMemberDO; 7 import cn.iocoder.yudao.module.im.dal.dataobject.group.ImGroupMemberDO;
@@ -19,6 +20,7 @@ import org.dromara.hutool.core.date.TimeUtil; @@ -19,6 +20,7 @@ import org.dromara.hutool.core.date.TimeUtil;
19 import org.springframework.stereotype.Service; 20 import org.springframework.stereotype.Service;
20 import org.springframework.validation.annotation.Validated; 21 import org.springframework.validation.annotation.Validated;
21 22
  23 +import java.util.Collections;
22 import java.util.List; 24 import java.util.List;
23 25
24 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 26 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@@ -57,6 +59,9 @@ public class ImMessageServiceImpl implements ImMessageService { @@ -57,6 +59,9 @@ public class ImMessageServiceImpl implements ImMessageService {
57 @Override 59 @Override
58 public List<ImMessageDO> pullMessageList(Long userId, Long sequence, Integer size) { 60 public List<ImMessageDO> pullMessageList(Long userId, Long sequence, Integer size) {
59 List<Long> messageIds = imInboxService.selectMessageIdsByUserIdAndSequence(userId, sequence, size); 61 List<Long> messageIds = imInboxService.selectMessageIdsByUserIdAndSequence(userId, sequence, size);
  62 + if (CollUtil.isEmpty(messageIds)) {
  63 + return Collections.emptyList();
  64 + }
60 return imMessageMapper.selectBatchIds(messageIds); 65 return imMessageMapper.selectBatchIds(messageIds);
61 } 66 }
62 67
@@ -70,6 +75,7 @@ public class ImMessageServiceImpl implements ImMessageService { @@ -70,6 +75,7 @@ public class ImMessageServiceImpl implements ImMessageService {
70 } 75 }
71 76
72 private ImMessageDO saveMessage(Long fromUserId, ImMessageSendReqVO message) { 77 private ImMessageDO saveMessage(Long fromUserId, ImMessageSendReqVO message) {
  78 + // TODO 芋艿:消息格式的校验
73 // 1. 校验接收人是否存在 79 // 1. 校验接收人是否存在
74 validateReceiverIdExists(message); 80 validateReceiverIdExists(message);
75 // 2. 查询发送人信息 81 // 2. 查询发送人信息