From c293fecedf66ffba4758f9de0f90160b3278ca7f Mon Sep 17 00:00:00 2001 From: JamesChenX Date: Thu, 28 Nov 2024 07:26:33 +0800 Subject: [PATCH] Fix cannot unset specific conversation settings #1576 --- .../repository/ConversationSettingsRepository.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/turms-service/src/main/java/im/turms/service/domain/conversation/repository/ConversationSettingsRepository.java b/turms-service/src/main/java/im/turms/service/domain/conversation/repository/ConversationSettingsRepository.java index 3e49847ad9..45d54270bd 100644 --- a/turms-service/src/main/java/im/turms/service/domain/conversation/repository/ConversationSettingsRepository.java +++ b/turms-service/src/main/java/im/turms/service/domain/conversation/repository/ConversationSettingsRepository.java @@ -17,8 +17,10 @@ package im.turms.service.domain.conversation.repository; +import java.util.ArrayList; import java.util.Collection; import java.util.Date; +import java.util.List; import java.util.Map; import jakarta.annotation.Nullable; @@ -55,7 +57,7 @@ public Mono upsertSettings( Long ownerId, Long targetId, Map settings) { - Filter filter = Filter.newBuilder(2) + Filter filter = Filter.newBuilder(1) .eq(DomainFieldName.ID, new ConversationSettings.Key(ownerId, targetId)); Update update = Update.newBuilder(settings.size() + 1) .set(ConversationSettings.Fields.LAST_UPDATED_DATE, new Date()); @@ -76,8 +78,12 @@ public Mono unsetSettings( filter = Filter.newBuilder(1) .eq(ConversationSettings.Fields.ID_OWNER_ID, ownerId); } else { + List keys = new ArrayList<>(targetIds.size()); + for (Long targetId : targetIds) { + keys.add(new ConversationSettings.Key(ownerId, targetId)); + } filter = Filter.newBuilder(1) - .in(DomainFieldName.ID, targetIds); + .in(DomainFieldName.ID, keys); } Update update = Update.newBuilder(1) .set(ConversationSettings.Fields.LAST_UPDATED_DATE, new Date()); @@ -90,7 +96,7 @@ public Mono unsetSettings( + settingName); } } - return mongoClient.updateOne(entityClass, filter, update); + return mongoClient.updateMany(entityClass, filter, update); } public Flux findByIdAndSettingNames(