fix: updateChannelStates invocation sequence as per foreign keys relations.

Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
Sahil Kumar
2021-09-06 19:21:28 +05:30
committed by xsahil03x
parent 442b22a007
commit 7e0997838e
14 changed files with 240 additions and 204 deletions
@@ -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));
}
}