Skip to content

Commit

Permalink
Merge pull request #144 from Re-4aliens/#143_chat-summary-aggregate-i…
Browse files Browse the repository at this point in the history
…ssue

Fix/#143 채팅 요약 정보가 제대로 집계되지 않는 문제 수정
  • Loading branch information
coke98 authored Aug 22, 2024
2 parents d31a3c7 + 264aa00 commit e3b3c2d
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ public List<Message> findMessages(Long chatRoomID, String lastMessageId) {
public List<ChatMessageSummary> aggregateMessageSummaries(List<Long> chatRoomIds, Long memberId) {
AggregationOperation match = Aggregation.match(Criteria.where("roomId").in(chatRoomIds));
AggregationOperation group = Aggregation.group("roomId")
.last("roomId").as("roomId")
.last("content").as("lastMessageContent")
.last("sendTime").as("lastMessageTime")
.sum(ConditionalOperators.when(Criteria.where("receiverId").is(memberId).and("isRead").is(false)).then(1).otherwise(0)).as("unreadCount");
.sum(ConditionalOperators.when(Criteria.where("receiverId").is(memberId).and("isRead").is(false)).then(1).otherwise(0)).as("numberOfUnreadMessages");
Aggregation aggregation = Aggregation.newAggregation(match, group);
AggregationResults<ChatMessageSummary> results = mongoTemplate.aggregate(aggregation, "message", ChatMessageSummary.class);
return new ArrayList<>(results.getMappedResults());
Expand Down

0 comments on commit e3b3c2d

Please sign in to comment.