mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-13 21:53:41 +08:00
单聊群聊功能提交
This commit is contained in:
@@ -25,5 +25,5 @@ public interface ContactService {
|
||||
|
||||
Integer getMsgUnReadCount(Message message);
|
||||
|
||||
Map<Long, MsgReadInfoDTO> getMsgReadInfo(List<Message> messages);
|
||||
Map<Long, MsgReadInfoDTO> getMsgReadInfo(List<Message> messages, boolean needUnread);
|
||||
}
|
||||
|
||||
@@ -51,17 +51,23 @@ public class ContactServiceImpl implements ContactService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, MsgReadInfoDTO> getMsgReadInfo(List<Message> messages) {
|
||||
public Map<Long, MsgReadInfoDTO> getMsgReadInfo(List<Message> messages, boolean needUnread) {
|
||||
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 = contactDao.getTotalCount(roomId);
|
||||
Integer totalCount = null;
|
||||
if (needUnread) {
|
||||
totalCount = contactDao.getTotalCount(roomId);
|
||||
}
|
||||
Integer finalTotalCount = totalCount;
|
||||
return messages.stream().map(message -> {
|
||||
MsgReadInfoDTO readInfoDTO = new MsgReadInfoDTO();
|
||||
readInfoDTO.setMsgId(message.getId());
|
||||
Integer readCount = contactDao.getReadCount(message);
|
||||
readInfoDTO.setReadCount(readCount);
|
||||
readInfoDTO.setUnReadCount(totalCount - readCount);
|
||||
if (needUnread) {
|
||||
readInfoDTO.setUnReadCount(finalTotalCount - readCount);
|
||||
}
|
||||
return readInfoDTO;
|
||||
}).collect(Collectors.toMap(MsgReadInfoDTO::getMsgId, Function.identity()));
|
||||
}
|
||||
|
||||
@@ -22,4 +22,6 @@ public class ChatMessageReadInfoReq {
|
||||
@ApiModelProperty("消息id集合(只查本人)")
|
||||
@Size(max = 20)
|
||||
private List<Long> msgIds;
|
||||
@ApiModelProperty("是否需要查未读数")
|
||||
private boolean needUnread;
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ public class ChatServiceImpl implements ChatService {
|
||||
messages.forEach(message -> {
|
||||
AssertUtil.equal(uid, message.getFromUid(), "只能查询自己发送的消息");
|
||||
});
|
||||
return contactService.getMsgReadInfo(messages).values();
|
||||
return contactService.getMsgReadInfo(messages, request.isNeedUnread()).values();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user