feat(llc): add crud for pinned message reactions

Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
Sahil Kumar
2021-08-31 15:50:25 +05:30
committed by xsahil03x
parent 5db0efadba
commit b369f18922
2 changed files with 35 additions and 0 deletions
@@ -170,9 +170,15 @@ abstract class ChatPersistenceClient {
/// Updates the reactions data with the new [reactions] data
Future<void> updateReactions(List<Reaction> reactions);
/// Updates the pinned message reactions data with the new [reactions] data
Future<void> updatePinnedMessageReactions(List<Reaction> reactions);
/// Deletes all the reactions by [messageIds]
Future<void> deleteReactionsByMessageId(List<String> messageIds);
/// Deletes all the pinned messages reactions by [messageIds]
Future<void> deletePinnedMessageReactionsByMessageId(List<String> messageIds);
/// Deletes all the members by channel [cids]
Future<void> deleteMembersByCids(List<String> 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),
),
]);
}
}
@@ -38,6 +38,11 @@ class TestPersistenceClient extends ChatPersistenceClient {
Future<void> deleteReactionsByMessageId(List<String> messageIds) =>
Future.value();
@override
Future<void> deletePinnedMessageReactionsByMessageId(
List<String> messageIds) =>
Future.value();
@override
Future<void> disconnect({bool flush = false}) => throw UnimplementedError();
@@ -116,6 +121,10 @@ class TestPersistenceClient extends ChatPersistenceClient {
@override
Future<void> updateReactions(List<Reaction> reactions) => Future.value();
@override
Future<void> updatePinnedMessageReactions(List<Reaction> reactions) =>
Future.value();
@override
Future<void> updateReads(String cid, List<Read> reads) => Future.value();