@@ -15,11 +15,11 @@ class ChannelDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
ChannelDao(MoorChatDatabase db) : super(db);
|
||||
|
||||
/// Get channel by cid
|
||||
Future<ChannelModel> getChannelByCid(String cid) async =>
|
||||
Future<ChannelModel?> getChannelByCid(String cid) async =>
|
||||
(select(channels)..where((c) => c.cid.equals(cid))).join([
|
||||
leftOuterJoin(users, channels.createdById.equalsExp(users.id)),
|
||||
]).map((rows) {
|
||||
final channel = rows.readTableOrNull(channels);
|
||||
final channel = rows.readTable(channels);
|
||||
final createdBy = rows.readTableOrNull(users);
|
||||
return channel.toChannelModel(createdBy: createdBy?.toUser());
|
||||
}).getSingleOrNull();
|
||||
@@ -30,7 +30,7 @@ class ChannelDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
/// 1. Channel Reads
|
||||
/// 2. Channel Members
|
||||
/// 3. Channel Messages -> Messages Reactions
|
||||
Future<void> deleteChannelByCids(List<String> cids) async =>
|
||||
Future<int> deleteChannelByCids(List<String> cids) async =>
|
||||
(delete(channels)..where((tbl) => tbl.cid.isIn(cids))).go();
|
||||
|
||||
/// Get the channel cids saved in the storage
|
||||
|
||||
@@ -18,7 +18,7 @@ class ChannelQueryDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
/// Creates a new channel query dao instance
|
||||
ChannelQueryDao(MoorChatDatabase db) : super(db);
|
||||
|
||||
String _computeHash(Map<String, dynamic> filter) {
|
||||
String _computeHash(Map<String, dynamic>? filter) {
|
||||
if (filter == null) {
|
||||
return 'allchannels';
|
||||
}
|
||||
@@ -58,7 +58,7 @@ class ChannelQueryDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
});
|
||||
|
||||
///
|
||||
Future<List<String>> getCachedChannelCids(Map<String, dynamic> filter) {
|
||||
Future<List<String>> getCachedChannelCids(Map<String, dynamic>? filter) {
|
||||
final hash = _computeHash(filter);
|
||||
return (select(channelQueries)..where((c) => c.queryHash.equals(hash)))
|
||||
.map((c) => c.channelCid)
|
||||
@@ -67,9 +67,9 @@ class ChannelQueryDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
|
||||
/// Get list of channels by filter, sort and paginationParams
|
||||
Future<List<ChannelModel>> getChannels({
|
||||
Map<String, dynamic> filter,
|
||||
List<SortOption<ChannelModel>> sort = const [],
|
||||
PaginationParams paginationParams,
|
||||
Map<String, dynamic>? filter,
|
||||
List<SortOption<ChannelModel>>? sort,
|
||||
PaginationParams? paginationParams,
|
||||
}) async {
|
||||
assert(() {
|
||||
if (sort != null && sort.any((it) => it.comparator == null)) {
|
||||
@@ -86,20 +86,21 @@ class ChannelQueryDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
final cachedChannels = await (query.join([
|
||||
leftOuterJoin(users, channels.createdById.equalsExp(users.id)),
|
||||
]).map((row) {
|
||||
final createdByEntity = row.readTable(users);
|
||||
final createdByEntity = row.readTableOrNull(users);
|
||||
final channelEntity = row.readTable(channels);
|
||||
return channelEntity.toChannelModel(createdBy: createdByEntity?.toUser());
|
||||
})).get();
|
||||
|
||||
final possibleSortingFields = cachedChannels.fold<List<String>>(
|
||||
ChannelModel.topLevelFields,
|
||||
(previousValue, element) =>
|
||||
{...previousValue, ...element.extraData.keys}.toList());
|
||||
ChannelModel.topLevelFields, (previousValue, element) {
|
||||
final extraData = element.extraData ?? {};
|
||||
return {...previousValue, ...extraData.keys}.toList();
|
||||
});
|
||||
|
||||
// ignore: parameter_assignments
|
||||
sort = sort
|
||||
?.where((s) => possibleSortingFields.contains(s.field))
|
||||
?.toList(growable: false);
|
||||
.toList(growable: false);
|
||||
|
||||
var chainedComparator = (ChannelModel a, ChannelModel b) {
|
||||
final dateA = a.lastMessageAt ?? a.createdAt;
|
||||
@@ -110,9 +111,9 @@ class ChannelQueryDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
if (sort != null && sort.isNotEmpty) {
|
||||
chainedComparator = (a, b) {
|
||||
int result;
|
||||
for (final comparator in sort.map((it) => it.comparator)) {
|
||||
for (final comparator in sort!.map((it) => it.comparator)) {
|
||||
try {
|
||||
result = comparator(a, b);
|
||||
result = comparator!(a, b);
|
||||
} catch (e) {
|
||||
result = 0;
|
||||
}
|
||||
@@ -125,11 +126,11 @@ class ChannelQueryDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
cachedChannels.sort(chainedComparator);
|
||||
|
||||
if (paginationParams?.offset != null && cachedChannels.isNotEmpty) {
|
||||
cachedChannels.removeRange(0, paginationParams.offset);
|
||||
cachedChannels.removeRange(0, paginationParams!.offset);
|
||||
}
|
||||
|
||||
if (paginationParams?.limit != null) {
|
||||
return cachedChannels.take(paginationParams.limit).toList();
|
||||
return cachedChannels.take(paginationParams!.limit).toList();
|
||||
}
|
||||
|
||||
return cachedChannels;
|
||||
|
||||
@@ -15,19 +15,18 @@ class ConnectionEventDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
ConnectionEventDao(MoorChatDatabase db) : super(db);
|
||||
|
||||
/// Get the latest stored connection event
|
||||
Future<Event> get connectionEvent => select(connectionEvents)
|
||||
Future<Event?> get connectionEvent => select(connectionEvents)
|
||||
.map((eventEntity) => eventEntity.toEvent())
|
||||
.getSingleOrNull();
|
||||
|
||||
/// Get the latest stored lastSyncAt
|
||||
Future<DateTime> get lastSyncAt =>
|
||||
Future<DateTime?> get lastSyncAt =>
|
||||
select(connectionEvents).getSingleOrNull().then((r) => r?.lastSyncAt);
|
||||
|
||||
/// Update stored connection event with latest data
|
||||
Future<void> updateConnectionEvent(Event event) async =>
|
||||
transaction(() async {
|
||||
Future<int> updateConnectionEvent(Event event) => transaction(() async {
|
||||
final connectionInfo = await select(connectionEvents).getSingleOrNull();
|
||||
await into(connectionEvents).insert(
|
||||
return into(connectionEvents).insert(
|
||||
ConnectionEventEntity(
|
||||
id: 1,
|
||||
lastSyncAt: connectionInfo?.lastSyncAt,
|
||||
|
||||
@@ -26,7 +26,7 @@ class MemberDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
.map((row) {
|
||||
final userEntity = row.readTable(users);
|
||||
final memberEntity = row.readTable(members);
|
||||
return memberEntity.toMember(user: userEntity?.toUser());
|
||||
return memberEntity.toMember(user: userEntity.toUser());
|
||||
}).get();
|
||||
|
||||
/// Updates all the members using the new [memberList] data
|
||||
|
||||
@@ -25,7 +25,7 @@ class MessageDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
///
|
||||
/// This will automatically delete the following linked records
|
||||
/// 1. Message Reactions
|
||||
Future<void> deleteMessageByIds(List<String> messageIds) =>
|
||||
Future<int> deleteMessageByIds(List<String> messageIds) =>
|
||||
(delete(messages)..where((tbl) => tbl.id.isIn(messageIds))).go();
|
||||
|
||||
/// Removes all the messages by matching [Messages.channelCid] in [cids]
|
||||
@@ -38,15 +38,16 @@ class MessageDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
Future<Message> _messageFromJoinRow(TypedResult rows) async {
|
||||
final userEntity = rows.readTableOrNull(_users);
|
||||
final pinnedByEntity = rows.readTableOrNull(_pinnedByUsers);
|
||||
final msgEntity = rows.readTableOrNull(messages);
|
||||
final msgEntity = rows.readTable(messages);
|
||||
final latestReactions = await _db.reactionDao.getReactions(msgEntity.id);
|
||||
final ownReactions = await _db.reactionDao.getReactionsByUserId(
|
||||
msgEntity.id,
|
||||
_db.userId,
|
||||
);
|
||||
Message quotedMessage;
|
||||
if (msgEntity.quotedMessageId != null) {
|
||||
quotedMessage = await getMessageById(msgEntity.quotedMessageId);
|
||||
Message? quotedMessage;
|
||||
final quotedMessageId = msgEntity.quotedMessageId;
|
||||
if (quotedMessageId != null) {
|
||||
quotedMessage = await getMessageById(quotedMessageId);
|
||||
}
|
||||
return msgEntity.toMessage(
|
||||
user: userEntity?.toUser(),
|
||||
@@ -58,7 +59,7 @@ class MessageDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
}
|
||||
|
||||
/// Returns a single message by matching the [Messages.id] with [id]
|
||||
Future<Message> getMessageById(String id) async =>
|
||||
Future<Message?> getMessageById(String id) async =>
|
||||
await (select(messages).join([
|
||||
leftOuterJoin(_users, messages.userId.equalsExp(_users.id)),
|
||||
leftOuterJoin(_pinnedByUsers,
|
||||
@@ -86,7 +87,7 @@ class MessageDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
/// [Messages.parentId] with [parentId]
|
||||
Future<List<Message>> getThreadMessagesByParentId(
|
||||
String parentId, {
|
||||
PaginationParams options,
|
||||
PaginationParams? options,
|
||||
}) async {
|
||||
final msgList = await Future.wait(await (select(messages).join([
|
||||
leftOuterJoin(_users, messages.userId.equalsExp(_users.id)),
|
||||
@@ -102,7 +103,7 @@ class MessageDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
if (msgList.isNotEmpty) {
|
||||
if (options?.lessThan != null) {
|
||||
final lessThanIndex = msgList.indexWhere(
|
||||
(m) => m.id == options.lessThan,
|
||||
(m) => m.id == options!.lessThan,
|
||||
);
|
||||
if (lessThanIndex != -1) {
|
||||
msgList.removeRange(lessThanIndex, msgList.length);
|
||||
@@ -110,14 +111,14 @@ class MessageDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
}
|
||||
if (options?.greaterThanOrEqual != null) {
|
||||
final greaterThanIndex = msgList.indexWhere(
|
||||
(m) => m.id == options.greaterThanOrEqual,
|
||||
(m) => m.id == options!.greaterThanOrEqual,
|
||||
);
|
||||
if (greaterThanIndex != -1) {
|
||||
msgList.removeRange(0, greaterThanIndex);
|
||||
}
|
||||
}
|
||||
if (options?.limit != null) {
|
||||
return msgList.take(options.limit).toList();
|
||||
return msgList.take(options!.limit).toList();
|
||||
}
|
||||
}
|
||||
return msgList;
|
||||
@@ -127,7 +128,7 @@ class MessageDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
/// [Messages.channelCid] with [parentId]
|
||||
Future<List<Message>> getMessagesByCid(
|
||||
String cid, {
|
||||
PaginationParams messagePagination,
|
||||
PaginationParams? messagePagination,
|
||||
}) async {
|
||||
final msgList = await Future.wait(await (select(messages).join([
|
||||
leftOuterJoin(_users, messages.userId.equalsExp(_users.id)),
|
||||
@@ -145,7 +146,7 @@ class MessageDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
if (msgList.isNotEmpty) {
|
||||
if (messagePagination?.lessThan != null) {
|
||||
final lessThanIndex = msgList.indexWhere(
|
||||
(m) => m.id == messagePagination.lessThan,
|
||||
(m) => m.id == messagePagination!.lessThan,
|
||||
);
|
||||
if (lessThanIndex != -1) {
|
||||
msgList.removeRange(lessThanIndex, msgList.length);
|
||||
@@ -153,14 +154,14 @@ class MessageDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
}
|
||||
if (messagePagination?.greaterThanOrEqual != null) {
|
||||
final greaterThanIndex = msgList.indexWhere(
|
||||
(m) => m.id == messagePagination.greaterThanOrEqual,
|
||||
(m) => m.id == messagePagination!.greaterThanOrEqual,
|
||||
);
|
||||
if (greaterThanIndex != -1) {
|
||||
msgList.removeRange(0, greaterThanIndex);
|
||||
}
|
||||
}
|
||||
if (messagePagination?.limit != null) {
|
||||
return msgList.take(messagePagination.limit).toList();
|
||||
return msgList.take(messagePagination!.limit).toList();
|
||||
}
|
||||
}
|
||||
return msgList;
|
||||
@@ -168,17 +169,13 @@ 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) async {
|
||||
if (messageList == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
return batch((batch) {
|
||||
batch.insertAll(
|
||||
messages,
|
||||
messageList.map((it) => it.toEntity(cid: cid)).toList(),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
Future<void> updateMessages(String cid, List<Message> messageList) => batch(
|
||||
(batch) {
|
||||
batch.insertAll(
|
||||
messages,
|
||||
messageList.map((it) => it.toEntity(cid: cid)).toList(),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,15 +38,16 @@ class PinnedMessageDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
Future<Message> _messageFromJoinRow(TypedResult rows) async {
|
||||
final userEntity = rows.readTableOrNull(users);
|
||||
final pinnedByEntity = rows.readTableOrNull(_pinnedByUsers);
|
||||
final msgEntity = rows.readTableOrNull(pinnedMessages);
|
||||
final msgEntity = rows.readTable(pinnedMessages);
|
||||
final latestReactions = await _db.reactionDao.getReactions(msgEntity.id);
|
||||
final ownReactions = await _db.reactionDao.getReactionsByUserId(
|
||||
msgEntity.id,
|
||||
_db.userId,
|
||||
);
|
||||
Message quotedMessage;
|
||||
if (msgEntity.quotedMessageId != null) {
|
||||
quotedMessage = await getMessageById(msgEntity.quotedMessageId);
|
||||
Message? quotedMessage;
|
||||
final quotedMessageId = msgEntity.quotedMessageId;
|
||||
if (quotedMessageId != null) {
|
||||
quotedMessage = await getMessageById(quotedMessageId);
|
||||
}
|
||||
return msgEntity.toMessage(
|
||||
user: userEntity?.toUser(),
|
||||
@@ -58,7 +59,7 @@ class PinnedMessageDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
}
|
||||
|
||||
/// Returns a single message by matching the [PinnedMessages.id] with [id]
|
||||
Future<Message> getMessageById(String id) async =>
|
||||
Future<Message?> getMessageById(String id) async =>
|
||||
await (select(pinnedMessages).join([
|
||||
leftOuterJoin(_users, pinnedMessages.userId.equalsExp(_users.id)),
|
||||
leftOuterJoin(_pinnedByUsers,
|
||||
@@ -86,7 +87,7 @@ class PinnedMessageDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
/// [PinnedMessages.parentId] with [parentId]
|
||||
Future<List<Message>> getThreadMessagesByParentId(
|
||||
String parentId, {
|
||||
PaginationParams options,
|
||||
PaginationParams? options,
|
||||
}) async {
|
||||
final msgList = await Future.wait(await (select(pinnedMessages).join([
|
||||
leftOuterJoin(_users, pinnedMessages.userId.equalsExp(_users.id)),
|
||||
@@ -102,7 +103,7 @@ class PinnedMessageDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
if (msgList.isNotEmpty) {
|
||||
if (options?.lessThan != null) {
|
||||
final lessThanIndex = msgList.indexWhere(
|
||||
(m) => m.id == options.lessThan,
|
||||
(m) => m.id == options!.lessThan,
|
||||
);
|
||||
if (lessThanIndex != -1) {
|
||||
msgList.removeRange(lessThanIndex, msgList.length);
|
||||
@@ -110,14 +111,14 @@ class PinnedMessageDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
}
|
||||
if (options?.greaterThanOrEqual != null) {
|
||||
final greaterThanIndex = msgList.indexWhere(
|
||||
(m) => m.id == options.greaterThanOrEqual,
|
||||
(m) => m.id == options!.greaterThanOrEqual,
|
||||
);
|
||||
if (greaterThanIndex != -1) {
|
||||
msgList.removeRange(0, greaterThanIndex);
|
||||
}
|
||||
}
|
||||
if (options?.limit != null) {
|
||||
return msgList.take(options.limit).toList();
|
||||
return msgList.take(options!.limit).toList();
|
||||
}
|
||||
}
|
||||
return msgList;
|
||||
@@ -127,7 +128,7 @@ class PinnedMessageDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
/// [PinnedMessages.channelCid] with [parentId]
|
||||
Future<List<Message>> getMessagesByCid(
|
||||
String cid, {
|
||||
PaginationParams messagePagination,
|
||||
PaginationParams? messagePagination,
|
||||
}) async {
|
||||
final msgList = await Future.wait(await (select(pinnedMessages).join([
|
||||
leftOuterJoin(_users, pinnedMessages.userId.equalsExp(_users.id)),
|
||||
@@ -144,7 +145,7 @@ class PinnedMessageDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
if (msgList.isNotEmpty) {
|
||||
if (messagePagination?.lessThan != null) {
|
||||
final lessThanIndex = msgList.indexWhere(
|
||||
(m) => m.id == messagePagination.lessThan,
|
||||
(m) => m.id == messagePagination!.lessThan,
|
||||
);
|
||||
if (lessThanIndex != -1) {
|
||||
msgList.removeRange(lessThanIndex, msgList.length);
|
||||
@@ -152,14 +153,14 @@ class PinnedMessageDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
}
|
||||
if (messagePagination?.greaterThanOrEqual != null) {
|
||||
final greaterThanIndex = msgList.indexWhere(
|
||||
(m) => m.id == messagePagination.greaterThanOrEqual,
|
||||
(m) => m.id == messagePagination!.greaterThanOrEqual,
|
||||
);
|
||||
if (greaterThanIndex != -1) {
|
||||
msgList.removeRange(0, greaterThanIndex);
|
||||
}
|
||||
}
|
||||
if (messagePagination?.limit != null) {
|
||||
return msgList.take(messagePagination.limit).toList();
|
||||
return msgList.take(messagePagination!.limit).toList();
|
||||
}
|
||||
}
|
||||
return msgList;
|
||||
@@ -167,17 +168,13 @@ 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) async {
|
||||
if (messageList == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
return batch((batch) {
|
||||
batch.insertAll(
|
||||
pinnedMessages,
|
||||
messageList.map((it) => it.toPinnedEntity(cid: cid)).toList(),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
Future<void> updateMessages(String cid, List<Message> messageList) => batch(
|
||||
(batch) {
|
||||
batch.insertAll(
|
||||
pinnedMessages,
|
||||
messageList.map((it) => it.toPinnedEntity(cid: cid)).toList(),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class ReactionDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
..orderBy([OrderingTerm.asc(reactions.createdAt)]))
|
||||
.map((rows) {
|
||||
final userEntity = rows.readTableOrNull(users);
|
||||
final reactionEntity = rows.readTableOrNull(reactions);
|
||||
final reactionEntity = rows.readTable(reactions);
|
||||
return reactionEntity.toReaction(user: userEntity?.toUser());
|
||||
}).get();
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class ReadDao extends DatabaseAccessor<MoorChatDatabase> with _$ReadDaoMixin {
|
||||
.map((row) {
|
||||
final userEntity = row.readTable(users);
|
||||
final readEntity = row.readTable(reads);
|
||||
return readEntity.toRead(user: userEntity?.toUser());
|
||||
return readEntity.toRead(user: userEntity.toUser());
|
||||
}).get();
|
||||
|
||||
/// Updates the read data of a particular channel with
|
||||
|
||||
@@ -72,6 +72,13 @@ class MoorChatDatabase extends _$MoorChatDatabase {
|
||||
},
|
||||
);
|
||||
|
||||
/// Deletes all the tables
|
||||
Future<void> flush() => batch((batch) {
|
||||
allTables.forEach((table) {
|
||||
delete(table).go();
|
||||
});
|
||||
});
|
||||
|
||||
/// Closes the database instance
|
||||
Future<void> disconnect() => close();
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ class ChannelEntity extends DataClass implements Insertable<ChannelEntity> {
|
||||
final String cid;
|
||||
|
||||
/// The channel configuration data
|
||||
final Map<String, Object> config;
|
||||
final Map<String, dynamic> config;
|
||||
|
||||
/// True if this channel entity is frozen
|
||||
final bool frozen;
|
||||
@@ -125,7 +125,7 @@ class ChannelEntity extends DataClass implements Insertable<ChannelEntity> {
|
||||
id: serializer.fromJson<String>(json['id']),
|
||||
type: serializer.fromJson<String>(json['type']),
|
||||
cid: serializer.fromJson<String>(json['cid']),
|
||||
config: serializer.fromJson<Map<String, Object>>(json['config']),
|
||||
config: serializer.fromJson<Map<String, dynamic>>(json['config']),
|
||||
frozen: serializer.fromJson<bool>(json['frozen']),
|
||||
lastMessageAt: serializer.fromJson<DateTime?>(json['lastMessageAt']),
|
||||
createdAt: serializer.fromJson<DateTime>(json['createdAt']),
|
||||
@@ -143,7 +143,7 @@ class ChannelEntity extends DataClass implements Insertable<ChannelEntity> {
|
||||
'id': serializer.toJson<String>(id),
|
||||
'type': serializer.toJson<String>(type),
|
||||
'cid': serializer.toJson<String>(cid),
|
||||
'config': serializer.toJson<Map<String, Object>>(config),
|
||||
'config': serializer.toJson<Map<String, dynamic>>(config),
|
||||
'frozen': serializer.toJson<bool>(frozen),
|
||||
'lastMessageAt': serializer.toJson<DateTime?>(lastMessageAt),
|
||||
'createdAt': serializer.toJson<DateTime>(createdAt),
|
||||
@@ -159,7 +159,7 @@ class ChannelEntity extends DataClass implements Insertable<ChannelEntity> {
|
||||
{String? id,
|
||||
String? type,
|
||||
String? cid,
|
||||
Map<String, Object>? config,
|
||||
Map<String, dynamic>? config,
|
||||
bool? frozen,
|
||||
Value<DateTime?> lastMessageAt = const Value.absent(),
|
||||
DateTime? createdAt,
|
||||
@@ -247,7 +247,7 @@ class ChannelsCompanion extends UpdateCompanion<ChannelEntity> {
|
||||
final Value<String> id;
|
||||
final Value<String> type;
|
||||
final Value<String> cid;
|
||||
final Value<Map<String, Object>> config;
|
||||
final Value<Map<String, dynamic>> config;
|
||||
final Value<bool> frozen;
|
||||
final Value<DateTime?> lastMessageAt;
|
||||
final Value<DateTime> createdAt;
|
||||
@@ -274,7 +274,7 @@ class ChannelsCompanion extends UpdateCompanion<ChannelEntity> {
|
||||
required String id,
|
||||
required String type,
|
||||
required String cid,
|
||||
required Map<String, Object> config,
|
||||
required Map<String, dynamic> config,
|
||||
this.frozen = const Value.absent(),
|
||||
this.lastMessageAt = const Value.absent(),
|
||||
this.createdAt = const Value.absent(),
|
||||
@@ -291,7 +291,7 @@ class ChannelsCompanion extends UpdateCompanion<ChannelEntity> {
|
||||
Expression<String>? id,
|
||||
Expression<String>? type,
|
||||
Expression<String>? cid,
|
||||
Expression<Map<String, Object>>? config,
|
||||
Expression<Map<String, dynamic>>? config,
|
||||
Expression<bool>? frozen,
|
||||
Expression<DateTime?>? lastMessageAt,
|
||||
Expression<DateTime>? createdAt,
|
||||
@@ -321,7 +321,7 @@ class ChannelsCompanion extends UpdateCompanion<ChannelEntity> {
|
||||
{Value<String>? id,
|
||||
Value<String>? type,
|
||||
Value<String>? cid,
|
||||
Value<Map<String, Object>>? config,
|
||||
Value<Map<String, dynamic>>? config,
|
||||
Value<bool>? frozen,
|
||||
Value<DateTime?>? lastMessageAt,
|
||||
Value<DateTime>? createdAt,
|
||||
@@ -634,8 +634,8 @@ class $ChannelsTable extends Channels
|
||||
return $ChannelsTable(_db, alias);
|
||||
}
|
||||
|
||||
static TypeConverter<Map<String, Object>, String> $converter0 =
|
||||
MapConverter<Object>();
|
||||
static TypeConverter<Map<String, dynamic>, String> $converter0 =
|
||||
MapConverter();
|
||||
static TypeConverter<Map<String, Object>, String> $converter1 =
|
||||
MapConverter<Object>();
|
||||
}
|
||||
@@ -3382,7 +3382,7 @@ class UserEntity extends DataClass implements Insertable<UserEntity> {
|
||||
final bool banned;
|
||||
|
||||
/// Map of custom user extraData
|
||||
final Map<String, Object>? extraData;
|
||||
final Map<String, Object> extraData;
|
||||
UserEntity(
|
||||
{required this.id,
|
||||
this.role,
|
||||
@@ -3391,7 +3391,7 @@ class UserEntity extends DataClass implements Insertable<UserEntity> {
|
||||
this.lastActive,
|
||||
required this.online,
|
||||
required this.banned,
|
||||
this.extraData});
|
||||
required this.extraData});
|
||||
factory UserEntity.fromData(Map<String, dynamic> data, GeneratedDatabase db,
|
||||
{String? prefix}) {
|
||||
final effectivePrefix = prefix ?? '';
|
||||
@@ -3412,7 +3412,7 @@ class UserEntity extends DataClass implements Insertable<UserEntity> {
|
||||
banned:
|
||||
boolType.mapFromDatabaseResponse(data['${effectivePrefix}banned'])!,
|
||||
extraData: $UsersTable.$converter0.mapToDart(stringType
|
||||
.mapFromDatabaseResponse(data['${effectivePrefix}extra_data'])),
|
||||
.mapFromDatabaseResponse(data['${effectivePrefix}extra_data']))!,
|
||||
);
|
||||
}
|
||||
@override
|
||||
@@ -3429,9 +3429,9 @@ class UserEntity extends DataClass implements Insertable<UserEntity> {
|
||||
}
|
||||
map['online'] = Variable<bool>(online);
|
||||
map['banned'] = Variable<bool>(banned);
|
||||
if (!nullToAbsent || extraData != null) {
|
||||
{
|
||||
final converter = $UsersTable.$converter0;
|
||||
map['extra_data'] = Variable<String?>(converter.mapToSql(extraData));
|
||||
map['extra_data'] = Variable<String>(converter.mapToSql(extraData)!);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
@@ -3447,7 +3447,7 @@ class UserEntity extends DataClass implements Insertable<UserEntity> {
|
||||
lastActive: serializer.fromJson<DateTime?>(json['lastActive']),
|
||||
online: serializer.fromJson<bool>(json['online']),
|
||||
banned: serializer.fromJson<bool>(json['banned']),
|
||||
extraData: serializer.fromJson<Map<String, Object>?>(json['extraData']),
|
||||
extraData: serializer.fromJson<Map<String, Object>>(json['extraData']),
|
||||
);
|
||||
}
|
||||
@override
|
||||
@@ -3461,7 +3461,7 @@ class UserEntity extends DataClass implements Insertable<UserEntity> {
|
||||
'lastActive': serializer.toJson<DateTime?>(lastActive),
|
||||
'online': serializer.toJson<bool>(online),
|
||||
'banned': serializer.toJson<bool>(banned),
|
||||
'extraData': serializer.toJson<Map<String, Object>?>(extraData),
|
||||
'extraData': serializer.toJson<Map<String, Object>>(extraData),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3473,7 +3473,7 @@ class UserEntity extends DataClass implements Insertable<UserEntity> {
|
||||
Value<DateTime?> lastActive = const Value.absent(),
|
||||
bool? online,
|
||||
bool? banned,
|
||||
Value<Map<String, Object>?> extraData = const Value.absent()}) =>
|
||||
Map<String, Object>? extraData}) =>
|
||||
UserEntity(
|
||||
id: id ?? this.id,
|
||||
role: role.present ? role.value : this.role,
|
||||
@@ -3482,7 +3482,7 @@ class UserEntity extends DataClass implements Insertable<UserEntity> {
|
||||
lastActive: lastActive.present ? lastActive.value : this.lastActive,
|
||||
online: online ?? this.online,
|
||||
banned: banned ?? this.banned,
|
||||
extraData: extraData.present ? extraData.value : this.extraData,
|
||||
extraData: extraData ?? this.extraData,
|
||||
);
|
||||
@override
|
||||
String toString() {
|
||||
@@ -3534,7 +3534,7 @@ class UsersCompanion extends UpdateCompanion<UserEntity> {
|
||||
final Value<DateTime?> lastActive;
|
||||
final Value<bool> online;
|
||||
final Value<bool> banned;
|
||||
final Value<Map<String, Object>?> extraData;
|
||||
final Value<Map<String, Object>> extraData;
|
||||
const UsersCompanion({
|
||||
this.id = const Value.absent(),
|
||||
this.role = const Value.absent(),
|
||||
@@ -3553,8 +3553,9 @@ class UsersCompanion extends UpdateCompanion<UserEntity> {
|
||||
this.lastActive = const Value.absent(),
|
||||
this.online = const Value.absent(),
|
||||
this.banned = const Value.absent(),
|
||||
this.extraData = const Value.absent(),
|
||||
}) : id = Value(id);
|
||||
required Map<String, Object> extraData,
|
||||
}) : id = Value(id),
|
||||
extraData = Value(extraData);
|
||||
static Insertable<UserEntity> custom({
|
||||
Expression<String>? id,
|
||||
Expression<String?>? role,
|
||||
@@ -3563,7 +3564,7 @@ class UsersCompanion extends UpdateCompanion<UserEntity> {
|
||||
Expression<DateTime?>? lastActive,
|
||||
Expression<bool>? online,
|
||||
Expression<bool>? banned,
|
||||
Expression<Map<String, Object>?>? extraData,
|
||||
Expression<Map<String, Object>>? extraData,
|
||||
}) {
|
||||
return RawValuesInsertable({
|
||||
if (id != null) 'id': id,
|
||||
@@ -3585,7 +3586,7 @@ class UsersCompanion extends UpdateCompanion<UserEntity> {
|
||||
Value<DateTime?>? lastActive,
|
||||
Value<bool>? online,
|
||||
Value<bool>? banned,
|
||||
Value<Map<String, Object>?>? extraData}) {
|
||||
Value<Map<String, Object>>? extraData}) {
|
||||
return UsersCompanion(
|
||||
id: id ?? this.id,
|
||||
role: role ?? this.role,
|
||||
@@ -3625,7 +3626,7 @@ class UsersCompanion extends UpdateCompanion<UserEntity> {
|
||||
if (extraData.present) {
|
||||
final converter = $UsersTable.$converter0;
|
||||
map['extra_data'] =
|
||||
Variable<String?>(converter.mapToSql(extraData.value));
|
||||
Variable<String>(converter.mapToSql(extraData.value)!);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
@@ -3722,7 +3723,7 @@ class $UsersTable extends Users with TableInfo<$UsersTable, UserEntity> {
|
||||
return GeneratedTextColumn(
|
||||
'extra_data',
|
||||
$tableName,
|
||||
true,
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4851,7 +4852,7 @@ class ConnectionEventEntity extends DataClass
|
||||
final int id;
|
||||
|
||||
/// User object of the current user
|
||||
final Map<String, Object>? ownUser;
|
||||
final Map<String, dynamic>? ownUser;
|
||||
|
||||
/// The number of unread messages for current user
|
||||
final int? totalUnreadCount;
|
||||
@@ -4920,7 +4921,7 @@ class ConnectionEventEntity extends DataClass
|
||||
serializer ??= moorRuntimeOptions.defaultSerializer;
|
||||
return ConnectionEventEntity(
|
||||
id: serializer.fromJson<int>(json['id']),
|
||||
ownUser: serializer.fromJson<Map<String, Object>?>(json['ownUser']),
|
||||
ownUser: serializer.fromJson<Map<String, dynamic>?>(json['ownUser']),
|
||||
totalUnreadCount: serializer.fromJson<int?>(json['totalUnreadCount']),
|
||||
unreadChannels: serializer.fromJson<int?>(json['unreadChannels']),
|
||||
lastEventAt: serializer.fromJson<DateTime?>(json['lastEventAt']),
|
||||
@@ -4932,7 +4933,7 @@ class ConnectionEventEntity extends DataClass
|
||||
serializer ??= moorRuntimeOptions.defaultSerializer;
|
||||
return <String, dynamic>{
|
||||
'id': serializer.toJson<int>(id),
|
||||
'ownUser': serializer.toJson<Map<String, Object>?>(ownUser),
|
||||
'ownUser': serializer.toJson<Map<String, dynamic>?>(ownUser),
|
||||
'totalUnreadCount': serializer.toJson<int?>(totalUnreadCount),
|
||||
'unreadChannels': serializer.toJson<int?>(unreadChannels),
|
||||
'lastEventAt': serializer.toJson<DateTime?>(lastEventAt),
|
||||
@@ -4942,7 +4943,7 @@ class ConnectionEventEntity extends DataClass
|
||||
|
||||
ConnectionEventEntity copyWith(
|
||||
{int? id,
|
||||
Value<Map<String, Object>?> ownUser = const Value.absent(),
|
||||
Value<Map<String, dynamic>?> ownUser = const Value.absent(),
|
||||
Value<int?> totalUnreadCount = const Value.absent(),
|
||||
Value<int?> unreadChannels = const Value.absent(),
|
||||
Value<DateTime?> lastEventAt = const Value.absent(),
|
||||
@@ -4994,7 +4995,7 @@ class ConnectionEventEntity extends DataClass
|
||||
|
||||
class ConnectionEventsCompanion extends UpdateCompanion<ConnectionEventEntity> {
|
||||
final Value<int> id;
|
||||
final Value<Map<String, Object>?> ownUser;
|
||||
final Value<Map<String, dynamic>?> ownUser;
|
||||
final Value<int?> totalUnreadCount;
|
||||
final Value<int?> unreadChannels;
|
||||
final Value<DateTime?> lastEventAt;
|
||||
@@ -5017,7 +5018,7 @@ class ConnectionEventsCompanion extends UpdateCompanion<ConnectionEventEntity> {
|
||||
});
|
||||
static Insertable<ConnectionEventEntity> custom({
|
||||
Expression<int>? id,
|
||||
Expression<Map<String, Object>?>? ownUser,
|
||||
Expression<Map<String, dynamic>?>? ownUser,
|
||||
Expression<int?>? totalUnreadCount,
|
||||
Expression<int?>? unreadChannels,
|
||||
Expression<DateTime?>? lastEventAt,
|
||||
@@ -5035,7 +5036,7 @@ class ConnectionEventsCompanion extends UpdateCompanion<ConnectionEventEntity> {
|
||||
|
||||
ConnectionEventsCompanion copyWith(
|
||||
{Value<int>? id,
|
||||
Value<Map<String, Object>?>? ownUser,
|
||||
Value<Map<String, dynamic>?>? ownUser,
|
||||
Value<int?>? totalUnreadCount,
|
||||
Value<int?>? unreadChannels,
|
||||
Value<DateTime?>? lastEventAt,
|
||||
@@ -5222,8 +5223,8 @@ class $ConnectionEventsTable extends ConnectionEvents
|
||||
return $ConnectionEventsTable(_db, alias);
|
||||
}
|
||||
|
||||
static TypeConverter<Map<String, Object>, String> $converter0 =
|
||||
MapConverter<Object>();
|
||||
static TypeConverter<Map<String, dynamic>, String> $converter0 =
|
||||
MapConverter();
|
||||
}
|
||||
|
||||
abstract class _$MoorChatDatabase extends GeneratedDatabase {
|
||||
|
||||
@@ -15,7 +15,7 @@ class Channels extends Table {
|
||||
TextColumn get cid => text()();
|
||||
|
||||
/// The channel configuration data
|
||||
TextColumn get config => text().map(MapConverter<Object>())();
|
||||
TextColumn get config => text().map(MapConverter())();
|
||||
|
||||
/// True if this channel entity is frozen
|
||||
BoolColumn get frozen => boolean().withDefault(const Constant(false))();
|
||||
|
||||
@@ -9,7 +9,7 @@ class ConnectionEvents extends Table {
|
||||
IntColumn get id => integer()();
|
||||
|
||||
/// User object of the current user
|
||||
TextColumn get ownUser => text().nullable().map(MapConverter<Object>())();
|
||||
TextColumn get ownUser => text().nullable().map(MapConverter())();
|
||||
|
||||
/// The number of unread messages for current user
|
||||
IntColumn get totalUnreadCount => integer().nullable()();
|
||||
|
||||
@@ -27,7 +27,7 @@ class Users extends Table {
|
||||
BoolColumn get banned => boolean().withDefault(const Constant(false))();
|
||||
|
||||
/// Map of custom user extraData
|
||||
TextColumn get extraData => text().nullable().map(MapConverter<Object>())();
|
||||
TextColumn get extraData => text().map(MapConverter<Object>())();
|
||||
|
||||
@override
|
||||
Set<Column> get primaryKey => {id};
|
||||
|
||||
@@ -4,8 +4,8 @@ import 'package:stream_chat_persistence/src/db/moor_chat_database.dart';
|
||||
/// Useful mapping functions for [ChannelEntity]
|
||||
extension ChannelEntityX on ChannelEntity {
|
||||
/// Maps a [ChannelEntity] into [ChannelModel]
|
||||
ChannelModel toChannelModel({User createdBy}) {
|
||||
final config = ChannelConfig.fromJson(this.config ?? {});
|
||||
ChannelModel toChannelModel({User? createdBy}) {
|
||||
final config = ChannelConfig.fromJson(this.config);
|
||||
return ChannelModel(
|
||||
id: id,
|
||||
config: config,
|
||||
@@ -24,11 +24,11 @@ extension ChannelEntityX on ChannelEntity {
|
||||
|
||||
/// Maps a [ChannelEntity] into [ChannelState]
|
||||
ChannelState toChannelState({
|
||||
User createdBy,
|
||||
List<Member> members,
|
||||
List<Read> reads,
|
||||
List<Message> messages,
|
||||
List<Message> pinnedMessages,
|
||||
User? createdBy,
|
||||
List<Member> members = const [],
|
||||
List<Read> reads = const [],
|
||||
List<Message> messages = const [],
|
||||
List<Message> pinnedMessages = const [],
|
||||
}) =>
|
||||
ChannelState(
|
||||
members: members,
|
||||
@@ -46,7 +46,7 @@ extension ChannelModelX on ChannelModel {
|
||||
id: id,
|
||||
type: type,
|
||||
cid: cid,
|
||||
config: config?.toJson(),
|
||||
config: config.toJson(),
|
||||
frozen: frozen,
|
||||
lastMessageAt: lastMessageAt,
|
||||
createdAt: createdAt,
|
||||
|
||||
@@ -5,7 +5,7 @@ import 'package:stream_chat_persistence/src/db/moor_chat_database.dart';
|
||||
extension ConnectionEventX on ConnectionEventEntity {
|
||||
/// Maps a [ConnectionEventEntity] into [Event]
|
||||
Event toEvent() => Event(
|
||||
me: ownUser != null ? OwnUser.fromJson(ownUser) : null,
|
||||
me: ownUser != null ? OwnUser.fromJson(ownUser!) : null,
|
||||
totalUnreadCount: totalUnreadCount,
|
||||
unreadChannels: unreadChannels,
|
||||
);
|
||||
|
||||
@@ -4,7 +4,7 @@ import 'package:stream_chat_persistence/src/db/moor_chat_database.dart';
|
||||
/// Useful mapping functions for [MemberEntity]
|
||||
extension MemberEntityX on MemberEntity {
|
||||
/// Maps a [MemberEntity] into [Member]
|
||||
Member toMember({User user}) => Member(
|
||||
Member toMember({User? user}) => Member(
|
||||
user: user,
|
||||
userId: userId,
|
||||
banned: banned,
|
||||
@@ -22,8 +22,8 @@ extension MemberEntityX on MemberEntity {
|
||||
/// Useful mapping functions for [Member]
|
||||
extension MemberX on Member {
|
||||
/// Maps a [Member] into [MemberEntity]
|
||||
MemberEntity toEntity({String cid}) => MemberEntity(
|
||||
userId: user?.id,
|
||||
MemberEntity toEntity({required String cid}) => MemberEntity(
|
||||
userId: user!.id,
|
||||
banned: banned,
|
||||
shadowBanned: shadowBanned,
|
||||
channelCid: cid,
|
||||
|
||||
@@ -7,22 +7,22 @@ import 'package:stream_chat_persistence/src/db/moor_chat_database.dart';
|
||||
extension MessageEntityX on MessageEntity {
|
||||
/// Maps a [MessageEntity] into [Message]
|
||||
Message toMessage({
|
||||
User user,
|
||||
User pinnedBy,
|
||||
List<Reaction> latestReactions,
|
||||
List<Reaction> ownReactions,
|
||||
Message quotedMessage,
|
||||
User? user,
|
||||
User? pinnedBy,
|
||||
List<Reaction>? latestReactions,
|
||||
List<Reaction>? ownReactions,
|
||||
Message? quotedMessage,
|
||||
}) =>
|
||||
Message(
|
||||
shadowed: shadowed,
|
||||
latestReactions: latestReactions,
|
||||
ownReactions: ownReactions,
|
||||
attachments: attachments?.map((it) {
|
||||
attachments: attachments.map((it) {
|
||||
final json = jsonDecode(it);
|
||||
return Attachment.fromData(json);
|
||||
})?.toList(),
|
||||
}).toList(),
|
||||
createdAt: createdAt,
|
||||
extraData: extraData,
|
||||
extraData: extraData ?? <String, Object>{},
|
||||
updatedAt: updatedAt,
|
||||
id: id,
|
||||
type: type,
|
||||
@@ -48,10 +48,9 @@ extension MessageEntityX on MessageEntity {
|
||||
/// Useful mapping functions for [Message]
|
||||
extension MessageX on Message {
|
||||
/// Maps a [Message] into [MessageEntity]
|
||||
MessageEntity toEntity({String cid}) => MessageEntity(
|
||||
MessageEntity toEntity({String? cid}) => MessageEntity(
|
||||
id: id,
|
||||
attachments:
|
||||
attachments?.map((it) => jsonEncode(it.toData()))?.toList(),
|
||||
attachments: attachments.map((it) => jsonEncode(it.toData())).toList(),
|
||||
channelCid: cid,
|
||||
type: type,
|
||||
parentId: parentId,
|
||||
@@ -63,6 +62,7 @@ extension MessageX on Message {
|
||||
replyCount: replyCount,
|
||||
reactionScores: reactionScores,
|
||||
reactionCounts: reactionCounts,
|
||||
mentionedUsers: mentionedUsers.map(jsonEncode).toList(),
|
||||
status: status,
|
||||
updatedAt: updatedAt,
|
||||
extraData: extraData,
|
||||
|
||||
@@ -7,22 +7,22 @@ import 'package:stream_chat_persistence/src/db/moor_chat_database.dart';
|
||||
extension PinnedMessageEntityX on PinnedMessageEntity {
|
||||
/// Maps a [PinnedMessageEntity] into [Message]
|
||||
Message toMessage({
|
||||
User user,
|
||||
User pinnedBy,
|
||||
List<Reaction> latestReactions,
|
||||
List<Reaction> ownReactions,
|
||||
Message quotedMessage,
|
||||
User? user,
|
||||
User? pinnedBy,
|
||||
List<Reaction>? latestReactions,
|
||||
List<Reaction>? ownReactions,
|
||||
Message? quotedMessage,
|
||||
}) =>
|
||||
Message(
|
||||
shadowed: shadowed,
|
||||
latestReactions: latestReactions,
|
||||
ownReactions: ownReactions,
|
||||
attachments: attachments?.map((it) {
|
||||
attachments: attachments.map((it) {
|
||||
final json = jsonDecode(it);
|
||||
return Attachment.fromData(json);
|
||||
})?.toList(),
|
||||
}).toList(),
|
||||
createdAt: createdAt,
|
||||
extraData: extraData,
|
||||
extraData: extraData ?? <String, Object>{},
|
||||
updatedAt: updatedAt,
|
||||
id: id,
|
||||
type: type,
|
||||
@@ -48,10 +48,9 @@ extension PinnedMessageEntityX on PinnedMessageEntity {
|
||||
/// Useful mapping functions for [Message]
|
||||
extension PMessageX on Message {
|
||||
/// Maps a [Message] into [PinnedMessageEntity]
|
||||
PinnedMessageEntity toPinnedEntity({String cid}) => PinnedMessageEntity(
|
||||
PinnedMessageEntity toPinnedEntity({String? cid}) => PinnedMessageEntity(
|
||||
id: id,
|
||||
attachments:
|
||||
attachments?.map((it) => jsonEncode(it.toData()))?.toList(),
|
||||
attachments: attachments.map((it) => jsonEncode(it.toData())).toList(),
|
||||
channelCid: cid,
|
||||
type: type,
|
||||
parentId: parentId,
|
||||
@@ -63,6 +62,7 @@ extension PMessageX on Message {
|
||||
replyCount: replyCount,
|
||||
reactionScores: reactionScores,
|
||||
reactionCounts: reactionCounts,
|
||||
mentionedUsers: mentionedUsers.map(jsonEncode).toList(),
|
||||
status: status,
|
||||
updatedAt: updatedAt,
|
||||
extraData: extraData,
|
||||
|
||||
@@ -4,7 +4,7 @@ import 'package:stream_chat_persistence/src/db/moor_chat_database.dart';
|
||||
/// Useful mapping functions for [ReactionEntity]
|
||||
extension ReactionEntityX on ReactionEntity {
|
||||
/// Maps a [ReactionEntity] into [Reaction]
|
||||
Reaction toReaction({User user}) => Reaction(
|
||||
Reaction toReaction({User? user}) => Reaction(
|
||||
extraData: extraData,
|
||||
type: type,
|
||||
createdAt: createdAt,
|
||||
@@ -22,8 +22,8 @@ extension ReactionX on Reaction {
|
||||
extraData: extraData,
|
||||
type: type,
|
||||
createdAt: createdAt,
|
||||
userId: userId,
|
||||
messageId: messageId,
|
||||
userId: userId!,
|
||||
messageId: messageId!,
|
||||
score: score,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import 'package:stream_chat_persistence/src/db/moor_chat_database.dart';
|
||||
/// Useful mapping functions for [ReadEntity]
|
||||
extension ReadEntityX on ReadEntity {
|
||||
/// Maps a [ReadEntity] into [Read]
|
||||
Read toRead({User user}) => Read(
|
||||
Read toRead({required User user}) => Read(
|
||||
user: user,
|
||||
lastRead: lastRead,
|
||||
unreadMessages: unreadMessages,
|
||||
@@ -14,9 +14,9 @@ extension ReadEntityX on ReadEntity {
|
||||
/// Useful mapping functions for [Read]
|
||||
extension ReadX on Read {
|
||||
/// Maps a [Read] into [ReadEntity]
|
||||
ReadEntity toEntity({String cid}) => ReadEntity(
|
||||
ReadEntity toEntity({required String cid}) => ReadEntity(
|
||||
lastRead: lastRead,
|
||||
userId: user?.id,
|
||||
userId: user.id,
|
||||
channelCid: cid,
|
||||
unreadMessages: unreadMessages,
|
||||
);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:logging/logging.dart' show LogRecord;
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:mutex/mutex.dart';
|
||||
@@ -53,15 +54,20 @@ class StreamChatPersistenceClient extends ChatPersistenceClient {
|
||||
if (record.stackTrace != null) print(record.stackTrace);
|
||||
}
|
||||
|
||||
Future<T> _readProtected<T>(Future<T> Function() f) async {
|
||||
T ret;
|
||||
await _mutex.protectRead(() async {
|
||||
Future<T> _readProtected<T>(AsyncValueGetter<T> func) =>
|
||||
_mutex.protectRead(func);
|
||||
|
||||
bool get _debugIsConnected {
|
||||
assert(() {
|
||||
if (db == null) {
|
||||
return;
|
||||
throw StateError('''
|
||||
$runtimeType hasn't been connected yet or used after `disconnect`
|
||||
was called. Consider calling `connect` to create a connection.
|
||||
''');
|
||||
}
|
||||
ret = await f();
|
||||
});
|
||||
return ret;
|
||||
return true;
|
||||
}(), '');
|
||||
return true;
|
||||
}
|
||||
|
||||
MoorChatDatabase _defaultDatabaseProvider(
|
||||
@@ -86,239 +92,281 @@ class StreamChatPersistenceClient extends ChatPersistenceClient {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Event> getConnectionInfo() => _readProtected(() {
|
||||
_logger.info('getConnectionInfo');
|
||||
return db.connectionEventDao.connectionEvent;
|
||||
});
|
||||
Future<Event?> getConnectionInfo() {
|
||||
assert(_debugIsConnected, '');
|
||||
_logger.info('getConnectionInfo');
|
||||
return _readProtected(() => db!.connectionEventDao.connectionEvent);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateConnectionInfo(Event event) => _readProtected(() {
|
||||
_logger.info('updateConnectionInfo');
|
||||
return db.connectionEventDao.updateConnectionEvent(event);
|
||||
});
|
||||
Future<void> updateConnectionInfo(Event event) {
|
||||
assert(_debugIsConnected, '');
|
||||
_logger.info('updateConnectionInfo');
|
||||
return _readProtected(
|
||||
() => db!.connectionEventDao.updateConnectionEvent(event),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateLastSyncAt(DateTime lastSyncAt) => _readProtected(() {
|
||||
_logger.info('updateLastSyncAt');
|
||||
return db.connectionEventDao.updateLastSyncAt(lastSyncAt);
|
||||
});
|
||||
Future<void> updateLastSyncAt(DateTime lastSyncAt) {
|
||||
assert(_debugIsConnected, '');
|
||||
_logger.info('updateLastSyncAt');
|
||||
return _readProtected(
|
||||
() => db!.connectionEventDao.updateLastSyncAt(lastSyncAt),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<DateTime> getLastSyncAt() => _readProtected(() {
|
||||
_logger.info('getLastSyncAt');
|
||||
return db.connectionEventDao.lastSyncAt;
|
||||
});
|
||||
Future<DateTime?> getLastSyncAt() {
|
||||
assert(_debugIsConnected, '');
|
||||
_logger.info('getLastSyncAt');
|
||||
return _readProtected(() => db!.connectionEventDao.lastSyncAt);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteChannels(List<String> cids) => _readProtected(() {
|
||||
_logger.info('deleteChannels');
|
||||
return db.channelDao.deleteChannelByCids(cids);
|
||||
});
|
||||
Future<void> deleteChannels(List<String> cids) {
|
||||
assert(_debugIsConnected, '');
|
||||
_logger.info('deleteChannels');
|
||||
return _readProtected(() => db!.channelDao.deleteChannelByCids(cids));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<String>> getChannelCids() => _readProtected(() {
|
||||
_logger.info('getChannelCids');
|
||||
return db.channelDao.cids;
|
||||
});
|
||||
Future<List<String>> getChannelCids() {
|
||||
assert(_debugIsConnected, '');
|
||||
_logger.info('getChannelCids');
|
||||
return _readProtected(() => db!.channelDao.cids);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteMessageByIds(List<String> messageIds) =>
|
||||
_readProtected(() {
|
||||
_logger.info('deleteMessageByIds');
|
||||
return db.messageDao.deleteMessageByIds(messageIds);
|
||||
});
|
||||
Future<void> deleteMessageByIds(List<String> messageIds) {
|
||||
assert(_debugIsConnected, '');
|
||||
_logger.info('deleteMessageByIds');
|
||||
return _readProtected(() => db!.messageDao.deleteMessageByIds(messageIds));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deletePinnedMessageByIds(List<String> messageIds) =>
|
||||
_readProtected(() {
|
||||
_logger.info('deletePinnedMessageByIds');
|
||||
return db.pinnedMessageDao.deleteMessageByIds(messageIds);
|
||||
});
|
||||
Future<void> deletePinnedMessageByIds(List<String> messageIds) {
|
||||
assert(_debugIsConnected, '');
|
||||
_logger.info('deletePinnedMessageByIds');
|
||||
return _readProtected(
|
||||
() => db!.pinnedMessageDao.deleteMessageByIds(messageIds),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteMessageByCids(List<String> cids) => _readProtected(() {
|
||||
_logger.info('deleteMessageByCids');
|
||||
return db.messageDao.deleteMessageByCids(cids);
|
||||
});
|
||||
Future<void> deleteMessageByCids(List<String> cids) {
|
||||
assert(_debugIsConnected, '');
|
||||
_logger.info('deleteMessageByCids');
|
||||
return _readProtected(() => db!.messageDao.deleteMessageByCids(cids));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deletePinnedMessageByCids(List<String> cids) =>
|
||||
_readProtected(() {
|
||||
_logger.info('deletePinnedMessageByCids');
|
||||
return db.pinnedMessageDao.deleteMessageByCids(cids);
|
||||
});
|
||||
Future<void> deletePinnedMessageByCids(List<String> cids) {
|
||||
assert(_debugIsConnected, '');
|
||||
_logger.info('deletePinnedMessageByCids');
|
||||
return _readProtected(() => db!.pinnedMessageDao.deleteMessageByCids(cids));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Member>> getMembersByCid(String cid) => _readProtected(() {
|
||||
_logger.info('getMembersByCid');
|
||||
return db.memberDao.getMembersByCid(cid);
|
||||
});
|
||||
Future<List<Member>> getMembersByCid(String cid) {
|
||||
assert(_debugIsConnected, '');
|
||||
_logger.info('getMembersByCid');
|
||||
return _readProtected(() => db!.memberDao.getMembersByCid(cid));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ChannelModel> getChannelByCid(String cid) => _readProtected(() {
|
||||
_logger.info('getChannelByCid');
|
||||
return db.channelDao.getChannelByCid(cid);
|
||||
});
|
||||
Future<ChannelModel?> getChannelByCid(String cid) {
|
||||
assert(_debugIsConnected, '');
|
||||
_logger.info('getChannelByCid');
|
||||
return _readProtected(() => db!.channelDao.getChannelByCid(cid));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Message>> getMessagesByCid(
|
||||
String cid, {
|
||||
PaginationParams messagePagination,
|
||||
}) =>
|
||||
_readProtected(() {
|
||||
_logger.info('getMessagesByCid');
|
||||
return db.messageDao.getMessagesByCid(
|
||||
cid,
|
||||
messagePagination: messagePagination,
|
||||
);
|
||||
});
|
||||
PaginationParams? messagePagination,
|
||||
}) {
|
||||
assert(_debugIsConnected, '');
|
||||
_logger.info('getMessagesByCid');
|
||||
return _readProtected(
|
||||
() => db!.messageDao.getMessagesByCid(
|
||||
cid,
|
||||
messagePagination: messagePagination,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Message>> getPinnedMessagesByCid(
|
||||
String cid, {
|
||||
PaginationParams messagePagination,
|
||||
}) =>
|
||||
_readProtected(() {
|
||||
_logger.info('getPinnedMessagesByCid');
|
||||
return db.pinnedMessageDao.getMessagesByCid(
|
||||
cid,
|
||||
messagePagination: messagePagination,
|
||||
);
|
||||
});
|
||||
PaginationParams? messagePagination,
|
||||
}) {
|
||||
assert(_debugIsConnected, '');
|
||||
_logger.info('getPinnedMessagesByCid');
|
||||
return _readProtected(
|
||||
() => db!.pinnedMessageDao.getMessagesByCid(
|
||||
cid,
|
||||
messagePagination: messagePagination,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Read>> getReadsByCid(String cid) => _readProtected(() {
|
||||
_logger.info('getReadsByCid');
|
||||
return db.readDao.getReadsByCid(cid);
|
||||
});
|
||||
Future<List<Read>> getReadsByCid(String cid) {
|
||||
assert(_debugIsConnected, '');
|
||||
_logger.info('getReadsByCid');
|
||||
return _readProtected(() => db!.readDao.getReadsByCid(cid));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Map<String, List<Message>>> getChannelThreads(String cid) async =>
|
||||
_readProtected(() async {
|
||||
_logger.info('getChannelThreads');
|
||||
final messages = await db.messageDao.getThreadMessages(cid);
|
||||
final messageByParentIdDictionary = <String, List<Message>>{};
|
||||
for (final message in messages) {
|
||||
final parentId = message.parentId;
|
||||
messageByParentIdDictionary[parentId] = [
|
||||
...messageByParentIdDictionary[parentId] ?? [],
|
||||
message
|
||||
];
|
||||
}
|
||||
return messageByParentIdDictionary;
|
||||
});
|
||||
Future<Map<String, List<Message>>> getChannelThreads(String cid) {
|
||||
assert(_debugIsConnected, '');
|
||||
_logger.info('getChannelThreads');
|
||||
return _readProtected(() async {
|
||||
final messages = await db!.messageDao.getThreadMessages(cid);
|
||||
final messageByParentIdDictionary = <String, List<Message>>{};
|
||||
for (final message in messages) {
|
||||
final parentId = message.parentId!;
|
||||
messageByParentIdDictionary[parentId] = [
|
||||
...messageByParentIdDictionary[parentId] ?? [],
|
||||
message
|
||||
];
|
||||
}
|
||||
return messageByParentIdDictionary;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Message>> getReplies(
|
||||
String parentId, {
|
||||
PaginationParams options,
|
||||
}) =>
|
||||
_readProtected(() async {
|
||||
_logger.info('getReplies');
|
||||
return db.messageDao.getThreadMessagesByParentId(
|
||||
parentId,
|
||||
options: options,
|
||||
);
|
||||
});
|
||||
PaginationParams? options,
|
||||
}) {
|
||||
assert(_debugIsConnected, '');
|
||||
_logger.info('getReplies');
|
||||
return _readProtected(
|
||||
() => db!.messageDao.getThreadMessagesByParentId(
|
||||
parentId,
|
||||
options: options,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<ChannelState>> getChannelStates({
|
||||
Map<String, dynamic> filter,
|
||||
List<SortOption<ChannelModel>> sort = const [],
|
||||
PaginationParams paginationParams,
|
||||
}) async =>
|
||||
_readProtected(() async {
|
||||
_logger.info('getChannelStates');
|
||||
final channels = await db.channelQueryDao.getChannels(
|
||||
Map<String, dynamic>? filter,
|
||||
List<SortOption<ChannelModel>>? sort,
|
||||
PaginationParams? paginationParams,
|
||||
}) {
|
||||
assert(_debugIsConnected, '');
|
||||
_logger.info('getChannelStates');
|
||||
return _readProtected(
|
||||
() async {
|
||||
final channels = await db!.channelQueryDao.getChannels(
|
||||
filter: filter,
|
||||
sort: sort,
|
||||
paginationParams: paginationParams,
|
||||
);
|
||||
return Future.wait(channels.map((e) => getChannelStateByCid(e.cid)));
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateChannelQueries(
|
||||
Map<String, dynamic> filter,
|
||||
List<String> cids, {
|
||||
bool clearQueryCache = false,
|
||||
}) =>
|
||||
_readProtected(() async {
|
||||
_logger.info('updateChannelQueries');
|
||||
return db.channelQueryDao.updateChannelQueries(
|
||||
filter,
|
||||
cids,
|
||||
clearQueryCache: clearQueryCache,
|
||||
);
|
||||
});
|
||||
}) {
|
||||
assert(_debugIsConnected, '');
|
||||
_logger.info('updateChannelQueries');
|
||||
return _readProtected(
|
||||
() => db!.channelQueryDao.updateChannelQueries(
|
||||
filter,
|
||||
cids,
|
||||
clearQueryCache: clearQueryCache,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateChannels(List<ChannelModel> channels) =>
|
||||
_readProtected(() async {
|
||||
_logger.info('updateChannels');
|
||||
return db.channelDao.updateChannels(channels);
|
||||
});
|
||||
Future<void> updateChannels(List<ChannelModel> channels) {
|
||||
assert(_debugIsConnected, '');
|
||||
_logger.info('updateChannels');
|
||||
return _readProtected(() => db!.channelDao.updateChannels(channels));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateMembers(String cid, List<Member> members) =>
|
||||
_readProtected(() async {
|
||||
_logger.info('updateMembers');
|
||||
return db.memberDao.updateMembers(cid, members);
|
||||
});
|
||||
Future<void> updateMembers(String cid, List<Member> members) {
|
||||
assert(_debugIsConnected, '');
|
||||
_logger.info('updateMembers');
|
||||
return _readProtected(() => db!.memberDao.updateMembers(cid, members));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateMessages(String cid, List<Message> messages) =>
|
||||
_readProtected(() async {
|
||||
_logger.info('updateMessages');
|
||||
return db.messageDao.updateMessages(cid, messages);
|
||||
});
|
||||
Future<void> updateMessages(String cid, List<Message> messages) {
|
||||
assert(_debugIsConnected, '');
|
||||
_logger.info('updateMessages');
|
||||
return _readProtected(() => db!.messageDao.updateMessages(cid, messages));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updatePinnedMessages(String cid, List<Message> messages) =>
|
||||
_readProtected(() async {
|
||||
_logger.info('updatePinnedMessages');
|
||||
return db.pinnedMessageDao.updateMessages(cid, messages);
|
||||
});
|
||||
Future<void> updatePinnedMessages(String cid, List<Message> messages) {
|
||||
assert(_debugIsConnected, '');
|
||||
_logger.info('updatePinnedMessages');
|
||||
return _readProtected(
|
||||
() => db!.pinnedMessageDao.updateMessages(cid, messages),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateReactions(List<Reaction> reactions) =>
|
||||
_readProtected(() async {
|
||||
_logger.info('updateReactions');
|
||||
return db.reactionDao.updateReactions(reactions);
|
||||
});
|
||||
Future<void> updateReactions(List<Reaction> reactions) {
|
||||
assert(_debugIsConnected, '');
|
||||
_logger.info('updateReactions');
|
||||
return _readProtected(() => db!.reactionDao.updateReactions(reactions));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateReads(String cid, List<Read> reads) =>
|
||||
_readProtected(() async {
|
||||
_logger.info('updateReads');
|
||||
return db.readDao.updateReads(cid, reads);
|
||||
});
|
||||
Future<void> updateReads(String cid, List<Read> reads) {
|
||||
assert(_debugIsConnected, '');
|
||||
_logger.info('updateReads');
|
||||
return _readProtected(() => db!.readDao.updateReads(cid, reads));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateUsers(List<User> users) => _readProtected(() async {
|
||||
_logger.info('updateUsers');
|
||||
return db.userDao.updateUsers(users);
|
||||
});
|
||||
Future<void> updateUsers(List<User> users) {
|
||||
assert(_debugIsConnected, '');
|
||||
_logger.info('updateUsers');
|
||||
return _readProtected(() => db!.userDao.updateUsers(users));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteReactionsByMessageId(List<String> messageIds) =>
|
||||
_readProtected(() async {
|
||||
_logger.info('deleteReactionsByMessageId');
|
||||
return db.reactionDao.deleteReactionsByMessageIds(messageIds);
|
||||
});
|
||||
Future<void> deleteReactionsByMessageId(List<String> messageIds) {
|
||||
assert(_debugIsConnected, '');
|
||||
_logger.info('deleteReactionsByMessageId');
|
||||
return _readProtected(
|
||||
() => db!.reactionDao.deleteReactionsByMessageIds(messageIds),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteMembersByCids(List<String> cids) =>
|
||||
_readProtected(() async {
|
||||
_logger.info('deleteMembersByCids');
|
||||
return db.memberDao.deleteMemberByCids(cids);
|
||||
});
|
||||
Future<void> deleteMembersByCids(List<String> cids) {
|
||||
assert(_debugIsConnected, '');
|
||||
_logger.info('deleteMembersByCids');
|
||||
return _readProtected(() => db!.memberDao.deleteMemberByCids(cids));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateChannelStates(List<ChannelState> channelStates) =>
|
||||
_readProtected(() async => db.transaction(() async {
|
||||
await super.updateChannelStates(channelStates);
|
||||
}));
|
||||
Future<void> updateChannelStates(List<ChannelState> channelStates) {
|
||||
assert(_debugIsConnected, '');
|
||||
_logger.info('updateChannelStates');
|
||||
return _readProtected(
|
||||
() async => db!.transaction(
|
||||
() async {
|
||||
await super.updateChannelStates(channelStates);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> disconnect({bool flush = false}) async =>
|
||||
@@ -328,11 +376,7 @@ class StreamChatPersistenceClient extends ChatPersistenceClient {
|
||||
_logger.info('Disconnecting');
|
||||
if (flush) {
|
||||
_logger.info('Flushing');
|
||||
await db!.batch((batch) {
|
||||
db!.allTables.forEach((table) {
|
||||
db!.delete(table).go();
|
||||
});
|
||||
});
|
||||
await db!.flush();
|
||||
}
|
||||
await db!.disconnect();
|
||||
db = null;
|
||||
|
||||
Reference in New Issue
Block a user