From b369f189224f922d17994fbf7d9aa3a072d787ba Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Mon, 30 Aug 2021 16:22:36 +0530 Subject: [PATCH] feat(llc): add crud for pinned message reactions Signed-off-by: xsahil03x --- .../lib/src/db/chat_persistence_client.dart | 26 +++++++++++++++++++ .../src/db/chat_persistence_client_test.dart | 9 +++++++ 2 files changed, 35 insertions(+) diff --git a/packages/stream_chat/lib/src/db/chat_persistence_client.dart b/packages/stream_chat/lib/src/db/chat_persistence_client.dart index 2470e403..bf2ef3a8 100644 --- a/packages/stream_chat/lib/src/db/chat_persistence_client.dart +++ b/packages/stream_chat/lib/src/db/chat_persistence_client.dart @@ -170,9 +170,15 @@ abstract class ChatPersistenceClient { /// Updates the reactions data with the new [reactions] data Future updateReactions(List reactions); + /// Updates the pinned message reactions data with the new [reactions] data + Future updatePinnedMessageReactions(List reactions); + /// Deletes all the reactions by [messageIds] Future deleteReactionsByMessageId(List messageIds); + /// Deletes all the pinned messages reactions by [messageIds] + Future deletePinnedMessageReactionsByMessageId(List messageIds); + /// Deletes all the members by channel [cids] Future deleteMembersByCids(List cids); @@ -187,6 +193,12 @@ abstract class ChatPersistenceClient { .map((m) => m.id) .toList(growable: false)); + final deletePinnedMessageReactions = + deletePinnedMessageReactionsByMessageId(channelStates + .expand((it) => it.pinnedMessages) + .map((m) => m.id) + .toList(growable: false)); + final cleanedChannelStates = channelStates.where((it) => it.channel != null); @@ -196,6 +208,7 @@ abstract class ChatPersistenceClient { await Future.wait([ deleteReactions, + deletePinnedMessageReactions, deleteMembers, ]); @@ -211,6 +224,16 @@ abstract class ChatPersistenceClient { ]) .withNullifyer; + final pinnedMessageReactions = cleanedChannelStates + .expand((it) => it.pinnedMessages) + .expand((it) => [ + if (it.ownReactions != null) + ...it.ownReactions!.where((r) => r.userId != null), + if (it.latestReactions != null) + ...it.latestReactions!.where((r) => r.userId != null), + ]) + .withNullifyer; + final users = cleanedChannelStates .map((cs) => [ cs.channel?.createdBy, @@ -261,6 +284,9 @@ abstract class ChatPersistenceClient { updateUsers(users.toList(growable: false)), updateChannels(channels.toList(growable: false)), updateReactions(reactions.toList(growable: false)), + updatePinnedMessageReactions( + pinnedMessageReactions.toList(growable: false), + ), ]); } } diff --git a/packages/stream_chat/test/src/db/chat_persistence_client_test.dart b/packages/stream_chat/test/src/db/chat_persistence_client_test.dart index 22aee1a9..d7de4745 100644 --- a/packages/stream_chat/test/src/db/chat_persistence_client_test.dart +++ b/packages/stream_chat/test/src/db/chat_persistence_client_test.dart @@ -38,6 +38,11 @@ class TestPersistenceClient extends ChatPersistenceClient { Future deleteReactionsByMessageId(List messageIds) => Future.value(); + @override + Future deletePinnedMessageReactionsByMessageId( + List messageIds) => + Future.value(); + @override Future disconnect({bool flush = false}) => throw UnimplementedError(); @@ -116,6 +121,10 @@ class TestPersistenceClient extends ChatPersistenceClient { @override Future updateReactions(List reactions) => Future.value(); + @override + Future updatePinnedMessageReactions(List reactions) => + Future.value(); + @override Future updateReads(String cid, List reads) => Future.value();