fix: updateChannelStates invocation sequence as per foreign keys relations.
Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
@@ -30,13 +30,19 @@ class MemberDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
}).get();
|
||||
|
||||
/// Updates all the members using the new [memberList] data
|
||||
Future<void> updateMembers(String cid, List<Member> memberList) async =>
|
||||
batch(
|
||||
(it) => it.insertAllOnConflictUpdate(
|
||||
members,
|
||||
memberList.map((m) => m.toEntity(cid: cid)).toList(),
|
||||
),
|
||||
);
|
||||
Future<void> updateMembers(String cid, List<Member> memberList) =>
|
||||
bulkUpdateMembers({cid: memberList});
|
||||
|
||||
/// Bulk updates the members data of multiple channels
|
||||
Future<void> bulkUpdateMembers(Map<String, List<Member>> channelWithMembers) {
|
||||
final entities = channelWithMembers.entries
|
||||
.map((entry) => entry.value.map(
|
||||
(member) => member.toEntity(cid: entry.key),
|
||||
))
|
||||
.expand((it) => it)
|
||||
.toList(growable: false);
|
||||
return batch((batch) => batch.insertAllOnConflictUpdate(members, entities));
|
||||
}
|
||||
|
||||
/// Deletes all the members whose [Members.channelCid] is present in [cids]
|
||||
Future<void> deleteMemberByCids(List<String> cids) async => batch((it) {
|
||||
|
||||
@@ -169,12 +169,21 @@ class MessageDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
|
||||
/// Updates the message data of a particular channel with
|
||||
/// the new [messageList] data
|
||||
Future<void> updateMessages(String cid, List<Message> messageList) => batch(
|
||||
(batch) {
|
||||
batch.insertAllOnConflictUpdate(
|
||||
messages,
|
||||
messageList.map((it) => it.toEntity(cid: cid)).toList(),
|
||||
);
|
||||
},
|
||||
);
|
||||
Future<void> updateMessages(String cid, List<Message> messageList) =>
|
||||
bulkUpdateMessages({cid: messageList});
|
||||
|
||||
/// Bulk updates the message data of multiple channels
|
||||
Future<void> bulkUpdateMessages(
|
||||
Map<String, List<Message>> channelWithMessages,
|
||||
) {
|
||||
final entities = channelWithMessages.entries
|
||||
.map((entry) => entry.value.map(
|
||||
(message) => message.toEntity(cid: entry.key),
|
||||
))
|
||||
.expand((it) => it)
|
||||
.toList(growable: false);
|
||||
return batch(
|
||||
(batch) => batch.insertAllOnConflictUpdate(messages, entities),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,12 +170,21 @@ class PinnedMessageDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
|
||||
/// Updates the message data of a particular channel with
|
||||
/// the new [messageList] data
|
||||
Future<void> updateMessages(String cid, List<Message> messageList) => batch(
|
||||
(batch) {
|
||||
batch.insertAllOnConflictUpdate(
|
||||
pinnedMessages,
|
||||
messageList.map((it) => it.toPinnedEntity(cid: cid)).toList(),
|
||||
);
|
||||
},
|
||||
);
|
||||
Future<void> updateMessages(String cid, List<Message> messageList) =>
|
||||
bulkUpdateMessages({cid: messageList});
|
||||
|
||||
/// Bulk updates the message data of multiple channels
|
||||
Future<void> bulkUpdateMessages(
|
||||
Map<String, List<Message>> channelWithMessages,
|
||||
) {
|
||||
final entities = channelWithMessages.entries
|
||||
.map((entry) => entry.value.map(
|
||||
(message) => message.toPinnedEntity(cid: entry.key),
|
||||
))
|
||||
.expand((it) => it)
|
||||
.toList(growable: false);
|
||||
return batch(
|
||||
(batch) => batch.insertAllOnConflictUpdate(pinnedMessages, entities),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,10 +29,17 @@ class ReadDao extends DatabaseAccessor<MoorChatDatabase> with _$ReadDaoMixin {
|
||||
|
||||
/// Updates the read data of a particular channel with
|
||||
/// the new [readList] data
|
||||
Future<void> updateReads(String cid, List<Read> readList) => batch(
|
||||
(it) => it.insertAllOnConflictUpdate(
|
||||
reads,
|
||||
readList.map((r) => r.toEntity(cid: cid)).toList(),
|
||||
),
|
||||
);
|
||||
Future<void> updateReads(String cid, List<Read> readList) =>
|
||||
bulkUpdateReads({cid: readList});
|
||||
|
||||
/// Bulk updates the reads data of multiple channels
|
||||
Future<void> bulkUpdateReads(Map<String, List<Read>> channelWithReads) {
|
||||
final entities = channelWithReads.entries
|
||||
.map((entry) => entry.value.map(
|
||||
(read) => read.toEntity(cid: entry.key),
|
||||
))
|
||||
.expand((it) => it)
|
||||
.toList(growable: false);
|
||||
return batch((batch) => batch.insertAllOnConflictUpdate(reads, entities));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user