Merge pull request #132 from lingyufei/fix/errors-in-summary-and-at

fix: 修复文本消息校验@用户的bug & 用户消息同步更新UserSummary
This commit is contained in:
zongzibinbin
2023-09-20 23:20:22 +08:00
committed by GitHub
2 changed files with 10 additions and 2 deletions

View File

@@ -29,6 +29,7 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* Description: 普通文本消息
@@ -68,9 +69,12 @@ public class TextMsgHandler extends AbstractMsgHandler {
AssertUtil.equal(replyMsg.getRoomId(), request.getRoomId(), "只能回复相同会话内的消息");
}
if (CollectionUtil.isNotEmpty(body.getAtUidList())) {
List<Long> atUidList = body.getAtUidList();
//前端传入的@用户列表可能会重复,需要去重
List<Long> atUidList = body.getAtUidList().stream().distinct().collect(Collectors.toList());
Map<Long, User> batch = userInfoCache.getBatch(atUidList);
AssertUtil.equal(atUidList.size(), batch.values().size(), "@用户不存在");
//如果@用户不存在userInfoCache 返回的map中依然存在该key但是value为null需要过滤掉再校验
long batchCount = batch.values().stream().filter(Objects::nonNull).count();
AssertUtil.equal((long)atUidList.size(), batchCount, "@用户不存在");
boolean atAll = body.getAtUidList().contains(0L);
if (atAll) {
AssertUtil.isTrue(iRoleService.hasPower(uid, RoleEnum.CHAT_MANAGER), "没有权限");

View File

@@ -39,6 +39,8 @@ public class UserCache {
private RoleDao roleDao;
@Autowired
private UserRoleDao userRoleDao;
@Autowired
private UserSummaryCache userSummaryCache;
public Long getOnlineNum() {
String onlineKey = RedisKey.getKey(RedisKey.ONLINE_UID_ZET);
@@ -137,6 +139,8 @@ public class UserCache {
public void userInfoChange(Long uid) {
delUserInfo(uid);
//删除UserSummaryCache前端下次懒加载的时候可以获取到最新的数据
userSummaryCache.delete(uid);
refreshUserModifyTime(uid);
}