1.未读数优化
This commit is contained in:
zhongzb
2023-08-20 18:55:22 +08:00
parent 68a4296b7b
commit cf707a4473
4 changed files with 5 additions and 13 deletions

View File

@@ -25,5 +25,5 @@ public interface ContactService {
Integer getMsgUnReadCount(Message message);
Map<Long, MsgReadInfoDTO> getMsgReadInfo(List<Message> messages, boolean needUnread);
Map<Long, MsgReadInfoDTO> getMsgReadInfo(List<Message> messages);
}

View File

@@ -51,23 +51,17 @@ public class ContactServiceImpl implements ContactService {
}
@Override
public Map<Long, MsgReadInfoDTO> getMsgReadInfo(List<Message> messages, boolean needUnread) {
public Map<Long, MsgReadInfoDTO> getMsgReadInfo(List<Message> messages) {
Map<Long, List<Message>> roomGroup = messages.stream().collect(Collectors.groupingBy(Message::getRoomId));
AssertUtil.equal(roomGroup.size(), 1, "只能查相同房间下的消息");
Long roomId = roomGroup.keySet().iterator().next();
Integer totalCount = null;
if (needUnread) {
totalCount = contactDao.getTotalCount(roomId);
}
Integer finalTotalCount = totalCount;
Integer totalCount = contactDao.getTotalCount(roomId);
return messages.stream().map(message -> {
MsgReadInfoDTO readInfoDTO = new MsgReadInfoDTO();
readInfoDTO.setMsgId(message.getId());
Integer readCount = contactDao.getReadCount(message);
readInfoDTO.setReadCount(readCount);
if (needUnread) {
readInfoDTO.setUnReadCount(finalTotalCount - readCount - 1);
}
readInfoDTO.setUnReadCount(totalCount - readCount - 1);
return readInfoDTO;
}).collect(Collectors.toMap(MsgReadInfoDTO::getMsgId, Function.identity()));
}

View File

@@ -22,6 +22,4 @@ public class ChatMessageReadInfoReq {
@ApiModelProperty("消息id集合只查本人")
@Size(max = 20)
private List<Long> msgIds;
@ApiModelProperty("是否需要查未读数")
private boolean needUnread;
}

View File

@@ -250,7 +250,7 @@ public class ChatServiceImpl implements ChatService {
messages.forEach(message -> {
AssertUtil.equal(uid, message.getFromUid(), "只能查询自己发送的消息");
});
return contactService.getMsgReadInfo(messages, request.isNeedUnread()).values();
return contactService.getMsgReadInfo(messages).values();
}
@Override