mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-14 06:03:42 +08:00
Merge pull request #132 from lingyufei/fix/errors-in-summary-and-at
fix: 修复文本消息校验@用户的bug & 用户消息同步更新UserSummary
This commit is contained in:
@@ -29,6 +29,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description: 普通文本消息
|
* Description: 普通文本消息
|
||||||
@@ -68,9 +69,12 @@ public class TextMsgHandler extends AbstractMsgHandler {
|
|||||||
AssertUtil.equal(replyMsg.getRoomId(), request.getRoomId(), "只能回复相同会话内的消息");
|
AssertUtil.equal(replyMsg.getRoomId(), request.getRoomId(), "只能回复相同会话内的消息");
|
||||||
}
|
}
|
||||||
if (CollectionUtil.isNotEmpty(body.getAtUidList())) {
|
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);
|
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);
|
boolean atAll = body.getAtUidList().contains(0L);
|
||||||
if (atAll) {
|
if (atAll) {
|
||||||
AssertUtil.isTrue(iRoleService.hasPower(uid, RoleEnum.CHAT_MANAGER), "没有权限");
|
AssertUtil.isTrue(iRoleService.hasPower(uid, RoleEnum.CHAT_MANAGER), "没有权限");
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ public class UserCache {
|
|||||||
private RoleDao roleDao;
|
private RoleDao roleDao;
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserRoleDao userRoleDao;
|
private UserRoleDao userRoleDao;
|
||||||
|
@Autowired
|
||||||
|
private UserSummaryCache userSummaryCache;
|
||||||
|
|
||||||
public Long getOnlineNum() {
|
public Long getOnlineNum() {
|
||||||
String onlineKey = RedisKey.getKey(RedisKey.ONLINE_UID_ZET);
|
String onlineKey = RedisKey.getKey(RedisKey.ONLINE_UID_ZET);
|
||||||
@@ -137,6 +139,8 @@ public class UserCache {
|
|||||||
|
|
||||||
public void userInfoChange(Long uid) {
|
public void userInfoChange(Long uid) {
|
||||||
delUserInfo(uid);
|
delUserInfo(uid);
|
||||||
|
//删除UserSummaryCache,前端下次懒加载的时候可以获取到最新的数据
|
||||||
|
userSummaryCache.delete(uid);
|
||||||
refreshUserModifyTime(uid);
|
refreshUserModifyTime(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user