@@ -620,7 +620,7 @@ class Channel {
|
||||
Future<SendReactionResponse> sendReaction(
|
||||
Message message,
|
||||
String type, {
|
||||
Map<String, dynamic> extraData = const {},
|
||||
Map<String, Object> extraData = const {},
|
||||
bool enforceUnique = false,
|
||||
}) async {
|
||||
_checkInitialized();
|
||||
|
||||
@@ -209,7 +209,7 @@ class GetMessageResponse extends _BaseResponse {
|
||||
final res = _$GetMessageResponseFromJson(json);
|
||||
final jsonChannel = res.message.extraData.remove('channel');
|
||||
if (jsonChannel != null) {
|
||||
res.channel = ChannelModel.fromJson(jsonChannel);
|
||||
res.channel = ChannelModel.fromJson(jsonChannel as Map<String, dynamic>);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -24,10 +24,10 @@ abstract class ChatPersistenceClient {
|
||||
});
|
||||
|
||||
/// Get stored connection event
|
||||
Future<Event> getConnectionInfo();
|
||||
Future<Event?> getConnectionInfo();
|
||||
|
||||
/// Get stored lastSyncAt
|
||||
Future<DateTime> getLastSyncAt();
|
||||
Future<DateTime?> getLastSyncAt();
|
||||
|
||||
/// Update stored connection event
|
||||
Future<void> updateConnectionInfo(Event event);
|
||||
@@ -39,7 +39,7 @@ abstract class ChatPersistenceClient {
|
||||
Future<List<String>> getChannelCids();
|
||||
|
||||
/// Get stored [ChannelModel]s by providing channel [cid]
|
||||
Future<ChannelModel> getChannelByCid(String cid);
|
||||
Future<ChannelModel?> getChannelByCid(String cid);
|
||||
|
||||
/// Get stored channel [Member]s by providing channel [cid]
|
||||
Future<List<Member>> getMembersByCid(String cid);
|
||||
@@ -90,7 +90,7 @@ abstract class ChatPersistenceClient {
|
||||
/// for filtering out states.
|
||||
Future<List<ChannelState>> getChannelStates({
|
||||
Map<String, dynamic>? filter,
|
||||
List<SortOption<ChannelModel>>? sort = const [],
|
||||
List<SortOption<ChannelModel>>? sort,
|
||||
PaginationParams? paginationParams,
|
||||
});
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ class Attachment extends Equatable {
|
||||
|
||||
/// Map of custom channel extraData
|
||||
@JsonKey(includeIfNull: false)
|
||||
final Map<String, dynamic>? extraData;
|
||||
final Map<String, Object>? extraData;
|
||||
|
||||
/// The attachment ID.
|
||||
///
|
||||
@@ -180,7 +180,7 @@ class Attachment extends Equatable {
|
||||
List<Action>? actions,
|
||||
AttachmentFile? file,
|
||||
UploadState? uploadState,
|
||||
Map<String, dynamic>? extraData,
|
||||
Map<String, Object>? extraData,
|
||||
}) =>
|
||||
Attachment(
|
||||
id: id ?? this.id,
|
||||
|
||||
@@ -30,7 +30,9 @@ Attachment _$AttachmentFromJson(Map<String, dynamic> json) {
|
||||
?.map((e) => Action.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[],
|
||||
extraData: json['extra_data'] as Map<String, dynamic>?,
|
||||
extraData: (json['extra_data'] as Map<String, dynamic>?)?.map(
|
||||
(k, e) => MapEntry(k, e as Object),
|
||||
),
|
||||
file: json['file'] == null
|
||||
? null
|
||||
: AttachmentFile.fromJson(json['file'] as Map<String, dynamic>),
|
||||
|
||||
@@ -84,7 +84,7 @@ class ChannelModel {
|
||||
|
||||
/// Map of custom channel extraData
|
||||
@JsonKey(includeIfNull: false)
|
||||
final Map<String, dynamic>? extraData;
|
||||
final Map<String, Object>? extraData;
|
||||
|
||||
/// The team the channel belongs to
|
||||
@JsonKey(includeIfNull: false, toJson: Serialization.readOnly)
|
||||
@@ -108,8 +108,9 @@ class ChannelModel {
|
||||
];
|
||||
|
||||
/// Shortcut for channel name
|
||||
String? get name =>
|
||||
extraData?.containsKey('name') == true ? extraData!['name'] : cid;
|
||||
String get name => extraData?.containsKey('name') == true
|
||||
? extraData!['name'] as String
|
||||
: cid;
|
||||
|
||||
/// Serialize to json
|
||||
Map<String, dynamic> toJson() => Serialization.moveFromExtraDataToRoot(
|
||||
@@ -129,7 +130,7 @@ class ChannelModel {
|
||||
DateTime? updatedAt,
|
||||
DateTime? deletedAt,
|
||||
int? memberCount,
|
||||
Map<String, dynamic>? extraData,
|
||||
Map<String, Object>? extraData,
|
||||
String? team,
|
||||
}) =>
|
||||
ChannelModel(
|
||||
|
||||
@@ -31,7 +31,9 @@ ChannelModel _$ChannelModelFromJson(Map<String, dynamic> json) {
|
||||
? null
|
||||
: DateTime.parse(json['deleted_at'] as String),
|
||||
memberCount: json['member_count'] as int? ?? 0,
|
||||
extraData: json['extra_data'] as Map<String, dynamic>?,
|
||||
extraData: (json['extra_data'] as Map<String, dynamic>?)?.map(
|
||||
(k, e) => MapEntry(k, e as Object),
|
||||
),
|
||||
team: json['team'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ class Event {
|
||||
|
||||
/// Map of custom channel extraData
|
||||
@JsonKey(defaultValue: {})
|
||||
final Map<String, dynamic> extraData;
|
||||
final Map<String, Object> extraData;
|
||||
|
||||
/// Known top level fields.
|
||||
/// Useful for [Serialization] methods.
|
||||
@@ -140,7 +140,7 @@ class Event {
|
||||
int? unreadChannels,
|
||||
bool? online,
|
||||
String? parentId,
|
||||
Map<String, dynamic>? extraData,
|
||||
Map<String, Object>? extraData,
|
||||
}) =>
|
||||
Event(
|
||||
type: type ?? this.type,
|
||||
@@ -180,7 +180,7 @@ class EventChannel extends ChannelModel {
|
||||
required DateTime updatedAt,
|
||||
DateTime? deletedAt,
|
||||
required int memberCount,
|
||||
Map<String, dynamic>? extraData,
|
||||
Map<String, Object>? extraData,
|
||||
}) : super(
|
||||
id: id,
|
||||
type: type,
|
||||
|
||||
@@ -38,7 +38,10 @@ Event _$EventFromJson(Map<String, dynamic> json) {
|
||||
channelId: json['channel_id'] as String?,
|
||||
channelType: json['channel_type'] as String?,
|
||||
parentId: json['parent_id'] as String?,
|
||||
extraData: json['extra_data'] as Map<String, dynamic>? ?? {},
|
||||
extraData: (json['extra_data'] as Map<String, dynamic>?)?.map(
|
||||
(k, e) => MapEntry(k, e as Object),
|
||||
) ??
|
||||
{},
|
||||
isLocal: json['is_local'] as bool? ?? false,
|
||||
);
|
||||
}
|
||||
@@ -86,7 +89,9 @@ EventChannel _$EventChannelFromJson(Map<String, dynamic> json) {
|
||||
? null
|
||||
: DateTime.parse(json['deleted_at'] as String),
|
||||
memberCount: json['member_count'] as int? ?? 0,
|
||||
extraData: json['extra_data'] as Map<String, dynamic>?,
|
||||
extraData: (json['extra_data'] as Map<String, dynamic>?)?.map(
|
||||
(k, e) => MapEntry(k, e as Object),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -208,7 +208,7 @@ class Message extends Equatable {
|
||||
includeIfNull: false,
|
||||
defaultValue: {},
|
||||
)
|
||||
final Map<String, dynamic> extraData;
|
||||
final Map<String, Object> extraData;
|
||||
|
||||
/// True if the message is a system info
|
||||
bool get isSystem => type == 'system';
|
||||
@@ -289,7 +289,7 @@ class Message extends Equatable {
|
||||
DateTime? pinnedAt,
|
||||
Object? pinExpires = _pinExpires,
|
||||
User? pinnedBy,
|
||||
Map<String, dynamic>? extraData,
|
||||
Map<String, Object>? extraData,
|
||||
MessageSendingStatus? status,
|
||||
bool? skipPush,
|
||||
}) {
|
||||
|
||||
@@ -63,7 +63,10 @@ Message _$MessageFromJson(Map<String, dynamic> json) {
|
||||
pinnedBy: json['pinned_by'] == null
|
||||
? null
|
||||
: User.fromJson(json['pinned_by'] as Map<String, dynamic>),
|
||||
extraData: json['extra_data'] as Map<String, dynamic>? ?? {},
|
||||
extraData: (json['extra_data'] as Map<String, dynamic>?)?.map(
|
||||
(k, e) => MapEntry(k, e as Object),
|
||||
) ??
|
||||
{},
|
||||
deletedAt: json['deleted_at'] == null
|
||||
? null
|
||||
: DateTime.parse(json['deleted_at'] as String),
|
||||
|
||||
@@ -23,7 +23,7 @@ class OwnUser extends User {
|
||||
DateTime? updatedAt,
|
||||
DateTime? lastActive,
|
||||
bool online = false,
|
||||
Map<String, dynamic> extraData = const {},
|
||||
Map<String, Object> extraData = const {},
|
||||
bool banned = false,
|
||||
}) : super(
|
||||
id: id,
|
||||
|
||||
@@ -34,7 +34,9 @@ OwnUser _$OwnUserFromJson(Map<String, dynamic> json) {
|
||||
? null
|
||||
: DateTime.parse(json['last_active'] as String),
|
||||
online: json['online'] as bool? ?? false,
|
||||
extraData: json['extra_data'] as Map<String, dynamic>,
|
||||
extraData: (json['extra_data'] as Map<String, dynamic>).map(
|
||||
(k, e) => MapEntry(k, e as Object),
|
||||
),
|
||||
banned: json['banned'] as bool? ?? false,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ class Reaction {
|
||||
|
||||
/// Reaction custom extraData
|
||||
@JsonKey(includeIfNull: false)
|
||||
final Map<String, dynamic>? extraData;
|
||||
final Map<String, Object>? extraData;
|
||||
|
||||
/// Map of custom user extraData
|
||||
static const topLevelFields = [
|
||||
@@ -75,7 +75,7 @@ class Reaction {
|
||||
User? user,
|
||||
String? userId,
|
||||
int? score,
|
||||
Map<String, dynamic>? extraData,
|
||||
Map<String, Object>? extraData,
|
||||
}) =>
|
||||
Reaction(
|
||||
messageId: messageId ?? this.messageId,
|
||||
|
||||
@@ -18,7 +18,9 @@ Reaction _$ReactionFromJson(Map<String, dynamic> json) {
|
||||
: User.fromJson(json['user'] as Map<String, dynamic>),
|
||||
userId: json['user_id'] as String?,
|
||||
score: json['score'] as int? ?? 0,
|
||||
extraData: json['extra_data'] as Map<String, dynamic>?,
|
||||
extraData: (json['extra_data'] as Map<String, dynamic>?)?.map(
|
||||
(k, e) => MapEntry(k, e as Object),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -75,16 +75,19 @@ class User {
|
||||
|
||||
/// Map of custom user extraData
|
||||
@JsonKey(includeIfNull: false)
|
||||
final Map<String, dynamic> extraData;
|
||||
final Map<String, Object> extraData;
|
||||
|
||||
@override
|
||||
int get hashCode => id.hashCode;
|
||||
|
||||
/// Shortcut for user name
|
||||
String? get name =>
|
||||
(extraData.containsKey('name') == true && extraData['name'] != '')
|
||||
? extraData['name']
|
||||
: id;
|
||||
String get name {
|
||||
if (extraData.containsKey('name')) {
|
||||
final name = extraData['name'] as String;
|
||||
if (name.isNotEmpty) return name;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
@@ -104,7 +107,7 @@ class User {
|
||||
DateTime? updatedAt,
|
||||
DateTime? lastActive,
|
||||
bool? online,
|
||||
Map<String, dynamic>? extraData,
|
||||
Map<String, Object>? extraData,
|
||||
bool? banned,
|
||||
List<String>? teams,
|
||||
}) =>
|
||||
|
||||
@@ -20,7 +20,9 @@ User _$UserFromJson(Map<String, dynamic> json) {
|
||||
? null
|
||||
: DateTime.parse(json['last_active'] as String),
|
||||
online: json['online'] as bool? ?? false,
|
||||
extraData: json['extra_data'] as Map<String, dynamic>,
|
||||
extraData: (json['extra_data'] as Map<String, dynamic>).map(
|
||||
(k, e) => MapEntry(k, e as Object),
|
||||
),
|
||||
banned: json['banned'] as bool? ?? false,
|
||||
teams:
|
||||
(json['teams'] as List<dynamic>?)?.map((e) => e as String).toList() ??
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
analyzer:
|
||||
exclude:
|
||||
exclude:
|
||||
- lib/**/*.g.dart
|
||||
- lib/**/*.freezed.dart
|
||||
- example/*
|
||||
- test/*
|
||||
linter:
|
||||
rules:
|
||||
linter:
|
||||
rules:
|
||||
- always_use_package_imports
|
||||
- avoid_empty_else
|
||||
- avoid_relative_lib_imports
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -5,8 +5,6 @@ version: 1.5.1
|
||||
repository: https://github.com/GetStream/stream-chat-flutter
|
||||
issue_tracker: https://github.com/GetStream/stream-chat-flutter/issues
|
||||
|
||||
publish_to: none
|
||||
|
||||
environment:
|
||||
sdk: ">=2.12.0 <3.0.0"
|
||||
|
||||
|
||||
@@ -3,53 +3,59 @@ import 'package:stream_chat_persistence/src/dao/dao.dart';
|
||||
import 'package:stream_chat_persistence/src/db/moor_chat_database.dart';
|
||||
|
||||
class MockChatDatabase extends Mock implements MoorChatDatabase {
|
||||
UserDao _userDao;
|
||||
UserDao? _userDao;
|
||||
|
||||
@override
|
||||
UserDao get userDao => _userDao ??= MockUserDao();
|
||||
|
||||
ChannelDao _channelDao;
|
||||
ChannelDao? _channelDao;
|
||||
|
||||
@override
|
||||
ChannelDao get channelDao => _channelDao ??= MockChannelDao();
|
||||
|
||||
MessageDao _messageDao;
|
||||
MessageDao? _messageDao;
|
||||
|
||||
@override
|
||||
MessageDao get messageDao => _messageDao ??= MockMessageDao();
|
||||
|
||||
PinnedMessageDao _pinnedMessageDao;
|
||||
PinnedMessageDao? _pinnedMessageDao;
|
||||
|
||||
@override
|
||||
PinnedMessageDao get pinnedMessageDao =>
|
||||
_pinnedMessageDao ??= MockPinnedMessageDao();
|
||||
|
||||
MemberDao _memberDao;
|
||||
MemberDao? _memberDao;
|
||||
|
||||
@override
|
||||
MemberDao get memberDao => _memberDao ??= MockMemberDao();
|
||||
|
||||
ReactionDao _reactionDao;
|
||||
ReactionDao? _reactionDao;
|
||||
|
||||
@override
|
||||
ReactionDao get reactionDao => _reactionDao ??= MockReactionDao();
|
||||
|
||||
ReadDao _readDao;
|
||||
ReadDao? _readDao;
|
||||
|
||||
@override
|
||||
ReadDao get readDao => _readDao ??= MockReadDao();
|
||||
|
||||
ChannelQueryDao _channelQueryDao;
|
||||
ChannelQueryDao? _channelQueryDao;
|
||||
|
||||
@override
|
||||
ChannelQueryDao get channelQueryDao =>
|
||||
_channelQueryDao ??= MockChannelQueryDao();
|
||||
|
||||
ConnectionEventDao _connectionEventDao;
|
||||
ConnectionEventDao? _connectionEventDao;
|
||||
|
||||
@override
|
||||
ConnectionEventDao get connectionEventDao =>
|
||||
_connectionEventDao ??= MockConnectionEventDao();
|
||||
|
||||
@override
|
||||
Future<void> flush() => Future.value();
|
||||
|
||||
@override
|
||||
Future<void> disconnect() => Future.value();
|
||||
}
|
||||
|
||||
class MockUserDao extends Mock implements UserDao {}
|
||||
|
||||
@@ -32,7 +32,7 @@ void main() {
|
||||
test('should return list of String if json data list is provided', () {
|
||||
final data = ['data1', 'data2', 'data3'];
|
||||
final res = listConverter.mapToDart(jsonEncode(data));
|
||||
expect(res.length, data.length);
|
||||
expect(res!.length, data.length);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import 'package:stream_chat_persistence/src/db/moor_chat_database.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
ChannelDao channelDao;
|
||||
MoorChatDatabase database;
|
||||
late ChannelDao channelDao;
|
||||
late MoorChatDatabase database;
|
||||
|
||||
setUp(() {
|
||||
database = MoorChatDatabase.testable('testUserId');
|
||||
@@ -32,7 +32,8 @@ void main() {
|
||||
|
||||
// Should match the dummy channel
|
||||
final updatedChannel = await channelDao.getChannelByCid(cid);
|
||||
expect(updatedChannel.id, id);
|
||||
expect(updatedChannel, isNotNull);
|
||||
expect(updatedChannel!.id, id);
|
||||
expect(updatedChannel.cid, cid);
|
||||
expect(updatedChannel.type, type);
|
||||
});
|
||||
@@ -53,7 +54,8 @@ void main() {
|
||||
|
||||
// Should match the dummy channel
|
||||
final updatedChannel = await channelDao.getChannelByCid(cid);
|
||||
expect(updatedChannel.id, id);
|
||||
expect(updatedChannel, isNotNull);
|
||||
expect(updatedChannel!.id, id);
|
||||
expect(updatedChannel.cid, cid);
|
||||
expect(updatedChannel.type, type);
|
||||
|
||||
@@ -108,7 +110,8 @@ void main() {
|
||||
|
||||
// Should match the dummy channel
|
||||
final updatedChannel = await channelDao.getChannelByCid(cid);
|
||||
expect(updatedChannel.id, id);
|
||||
expect(updatedChannel, isNotNull);
|
||||
expect(updatedChannel!.id, id);
|
||||
expect(updatedChannel.cid, cid);
|
||||
expect(updatedChannel.type, type);
|
||||
|
||||
@@ -119,7 +122,8 @@ void main() {
|
||||
|
||||
// Should match the new channel
|
||||
final newUpdatedChannel = await channelDao.getChannelByCid(cid);
|
||||
expect(newUpdatedChannel.id, id);
|
||||
expect(newUpdatedChannel, isNotNull);
|
||||
expect(newUpdatedChannel!.id, id);
|
||||
expect(newUpdatedChannel.cid, cid);
|
||||
expect(newUpdatedChannel.type, newType);
|
||||
});
|
||||
|
||||
@@ -8,8 +8,8 @@ import 'package:test/test.dart';
|
||||
import '../utils/date_matcher.dart';
|
||||
|
||||
void main() {
|
||||
MoorChatDatabase database;
|
||||
ChannelQueryDao channelQueryDao;
|
||||
late MoorChatDatabase database;
|
||||
late ChannelQueryDao channelQueryDao;
|
||||
|
||||
setUp(() {
|
||||
database = MoorChatDatabase.testable('testUserId');
|
||||
@@ -147,7 +147,7 @@ void main() {
|
||||
// Should match lastMessageAt date
|
||||
expect(
|
||||
updatedChannel.lastMessageAt,
|
||||
isSameDateAs(insertedChannel.lastMessageAt),
|
||||
isSameDateAs(insertedChannel.lastMessageAt!),
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -160,10 +160,7 @@ void main() {
|
||||
const pagination = PaginationParams(offset: offset, limit: limit);
|
||||
|
||||
// Inserting test data for get channels
|
||||
final insertedChannels = await _insertTestDataForGetChannel(
|
||||
filter,
|
||||
count: 30,
|
||||
);
|
||||
await _insertTestDataForGetChannel(filter, count: 30);
|
||||
|
||||
// Should match with the inserted channels
|
||||
final updatedChannels = await channelQueryDao.getChannels(
|
||||
@@ -210,7 +207,7 @@ void main() {
|
||||
// Should match lastMessageAt date
|
||||
expect(
|
||||
updatedChannel.lastMessageAt,
|
||||
isSameDateAs(insertedChannel.lastMessageAt),
|
||||
isSameDateAs(insertedChannel.lastMessageAt!),
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -226,8 +223,8 @@ void main() {
|
||||
|
||||
test('should return sorted channels using custom field', () async {
|
||||
int sortComparator(ChannelModel a, ChannelModel b) {
|
||||
final aData = a.extraData['test_custom_field'] as int;
|
||||
final bData = b.extraData['test_custom_field'] as int;
|
||||
final aData = a.extraData!['test_custom_field'] as int;
|
||||
final bData = b.extraData!['test_custom_field'] as int;
|
||||
return bData.compareTo(aData);
|
||||
}
|
||||
|
||||
@@ -261,7 +258,7 @@ void main() {
|
||||
// Should match lastMessageAt date
|
||||
expect(
|
||||
updatedChannel.lastMessageAt,
|
||||
isSameDateAs(insertedChannel.lastMessageAt),
|
||||
isSameDateAs(insertedChannel.lastMessageAt!),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -6,8 +6,8 @@ import 'package:test/test.dart';
|
||||
import '../utils/date_matcher.dart';
|
||||
|
||||
void main() {
|
||||
ConnectionEventDao eventDao;
|
||||
MoorChatDatabase database;
|
||||
late ConnectionEventDao eventDao;
|
||||
late MoorChatDatabase database;
|
||||
|
||||
setUp(() {
|
||||
database = MoorChatDatabase.testable('testUserId');
|
||||
@@ -30,7 +30,8 @@ void main() {
|
||||
|
||||
// Should match the added event
|
||||
final updatedEvent = await eventDao.connectionEvent;
|
||||
expect(updatedEvent.me.id, newEvent.me.id);
|
||||
expect(updatedEvent, isNotNull);
|
||||
expect(updatedEvent!.me!.id, newEvent.me!.id);
|
||||
expect(updatedEvent.totalUnreadCount, newEvent.totalUnreadCount);
|
||||
expect(updatedEvent.unreadChannels, newEvent.unreadChannels);
|
||||
});
|
||||
@@ -70,7 +71,8 @@ void main() {
|
||||
|
||||
// Should match the previously added event
|
||||
final fetchedEvent = await eventDao.connectionEvent;
|
||||
expect(fetchedEvent.me.id, event.me.id);
|
||||
expect(fetchedEvent, isNotNull);
|
||||
expect(fetchedEvent!.me!.id, event.me!.id);
|
||||
expect(fetchedEvent.totalUnreadCount, event.totalUnreadCount);
|
||||
expect(fetchedEvent.unreadChannels, event.unreadChannels);
|
||||
|
||||
@@ -80,7 +82,8 @@ void main() {
|
||||
|
||||
// Should match the updated event
|
||||
final fetchedNewEvent = await eventDao.connectionEvent;
|
||||
expect(fetchedNewEvent.me.id, event.me.id);
|
||||
expect(fetchedNewEvent, isNotNull);
|
||||
expect(fetchedNewEvent!.me!.id, event.me!.id);
|
||||
expect(fetchedNewEvent.totalUnreadCount, event.totalUnreadCount);
|
||||
expect(fetchedNewEvent.unreadChannels, newEvent.unreadChannels);
|
||||
});
|
||||
|
||||
@@ -8,8 +8,8 @@ import 'package:test/test.dart';
|
||||
import '../utils/date_matcher.dart';
|
||||
|
||||
void main() {
|
||||
MemberDao memberDao;
|
||||
MoorChatDatabase database;
|
||||
late MemberDao memberDao;
|
||||
late MoorChatDatabase database;
|
||||
|
||||
setUp(() {
|
||||
database = MoorChatDatabase.testable('testUserId');
|
||||
@@ -53,7 +53,7 @@ void main() {
|
||||
for (var i = 0; i < fetchedMembers.length; i++) {
|
||||
final member = memberList[i];
|
||||
final fetchedMember = fetchedMembers[i];
|
||||
expect(fetchedMember.user.id, member.user.id);
|
||||
expect(fetchedMember.user!.id, member.user!.id);
|
||||
expect(fetchedMember.banned, member.banned);
|
||||
expect(fetchedMember.shadowBanned, member.shadowBanned);
|
||||
expect(fetchedMember.createdAt, isSameDateAs(member.createdAt));
|
||||
@@ -63,7 +63,7 @@ void main() {
|
||||
expect(fetchedMember.updatedAt, isSameDateAs(member.updatedAt));
|
||||
expect(
|
||||
fetchedMember.inviteAcceptedAt,
|
||||
isSameDateAs(member.inviteAcceptedAt),
|
||||
isSameDateAs(member.inviteAcceptedAt!),
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -80,7 +80,7 @@ void main() {
|
||||
for (var i = 0; i < fetchedMembers.length; i++) {
|
||||
final member = memberList[i];
|
||||
final fetchedMember = fetchedMembers[i];
|
||||
expect(fetchedMember.user.id, member.user.id);
|
||||
expect(fetchedMember.user!.id, member.user!.id);
|
||||
expect(fetchedMember.banned, member.banned);
|
||||
expect(fetchedMember.shadowBanned, member.shadowBanned);
|
||||
expect(fetchedMember.createdAt, isSameDateAs(member.createdAt));
|
||||
@@ -90,7 +90,7 @@ void main() {
|
||||
expect(fetchedMember.updatedAt, isSameDateAs(member.updatedAt));
|
||||
expect(
|
||||
fetchedMember.inviteAcceptedAt,
|
||||
isSameDateAs(member.inviteAcceptedAt),
|
||||
isSameDateAs(member.inviteAcceptedAt!),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -118,13 +118,13 @@ void main() {
|
||||
expect(newFetchedMembers.length, fetchedMembers.length + 1);
|
||||
expect(
|
||||
newFetchedMembers
|
||||
.firstWhere((it) => it.user.id == copyMember.user.id)
|
||||
.firstWhere((it) => it.user!.id == copyMember.user!.id)
|
||||
.banned,
|
||||
true,
|
||||
);
|
||||
expect(
|
||||
newFetchedMembers
|
||||
.where((it) => it.user.id == newMember.user.id)
|
||||
.where((it) => it.user!.id == newMember.user!.id)
|
||||
.isNotEmpty,
|
||||
true,
|
||||
);
|
||||
|
||||
@@ -6,8 +6,8 @@ import 'package:stream_chat_persistence/src/db/moor_chat_database.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
MessageDao messageDao;
|
||||
MoorChatDatabase database;
|
||||
late MessageDao messageDao;
|
||||
late MoorChatDatabase database;
|
||||
|
||||
setUp(() {
|
||||
database = MoorChatDatabase.testable('testUserId');
|
||||
@@ -32,7 +32,7 @@ void main() {
|
||||
shadowed: math.Random().nextBool(),
|
||||
replyCount: index,
|
||||
updatedAt: DateTime.now(),
|
||||
extraData: {'extra_test_field': 'extraTestData'},
|
||||
extraData: const {'extra_test_field': 'extraTestData'},
|
||||
text: 'Dummy text #$index',
|
||||
pinned: math.Random().nextBool(),
|
||||
pinnedAt: DateTime.now(),
|
||||
@@ -49,7 +49,7 @@ void main() {
|
||||
shadowed: math.Random().nextBool(),
|
||||
replyCount: index,
|
||||
updatedAt: DateTime.now(),
|
||||
extraData: {'extra_test_field': 'extraTestData'},
|
||||
extraData: const {'extra_test_field': 'extraTestData'},
|
||||
text: 'Dummy text #$index',
|
||||
quotedMessageId: messages[index].id,
|
||||
pinned: math.Random().nextBool(),
|
||||
@@ -69,7 +69,7 @@ void main() {
|
||||
shadowed: math.Random().nextBool(),
|
||||
replyCount: index,
|
||||
updatedAt: DateTime.now(),
|
||||
extraData: {'extra_test_field': 'extraTestData'},
|
||||
extraData: const {'extra_test_field': 'extraTestData'},
|
||||
text: 'Dummy text #$index',
|
||||
pinned: math.Random().nextBool(),
|
||||
pinnedAt: DateTime.now(),
|
||||
@@ -168,7 +168,8 @@ void main() {
|
||||
|
||||
// Fetched message id should match the inserted message id
|
||||
final fetchedMessage = await messageDao.getMessageById(id);
|
||||
expect(fetchedMessage.id, insertedMessages.first.id);
|
||||
expect(fetchedMessage, isNotNull);
|
||||
expect(fetchedMessage!.id, insertedMessages.first.id);
|
||||
});
|
||||
|
||||
test('getThreadMessages', () async {
|
||||
@@ -332,7 +333,7 @@ void main() {
|
||||
showInChannel: math.Random().nextBool(),
|
||||
replyCount: 4,
|
||||
updatedAt: DateTime.now(),
|
||||
extraData: {'extra_test_field': 'extraTestData'},
|
||||
extraData: const {'extra_test_field': 'extraTestData'},
|
||||
text: 'Dummy text #4',
|
||||
pinned: math.Random().nextBool(),
|
||||
pinnedAt: DateTime.now(),
|
||||
|
||||
@@ -6,8 +6,8 @@ import 'package:stream_chat_persistence/src/db/moor_chat_database.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
PinnedMessageDao pinnedMessageDao;
|
||||
MoorChatDatabase database;
|
||||
late PinnedMessageDao pinnedMessageDao;
|
||||
late MoorChatDatabase database;
|
||||
|
||||
setUp(() {
|
||||
database = MoorChatDatabase.testable('testUserId');
|
||||
@@ -32,7 +32,7 @@ void main() {
|
||||
shadowed: math.Random().nextBool(),
|
||||
replyCount: index,
|
||||
updatedAt: DateTime.now(),
|
||||
extraData: {'extra_test_field': 'extraTestData'},
|
||||
extraData: const {'extra_test_field': 'extraTestData'},
|
||||
text: 'Dummy text #$index',
|
||||
pinned: math.Random().nextBool(),
|
||||
pinnedAt: DateTime.now(),
|
||||
@@ -49,7 +49,7 @@ void main() {
|
||||
shadowed: math.Random().nextBool(),
|
||||
replyCount: index,
|
||||
updatedAt: DateTime.now(),
|
||||
extraData: {'extra_test_field': 'extraTestData'},
|
||||
extraData: const {'extra_test_field': 'extraTestData'},
|
||||
text: 'Dummy text #$index',
|
||||
quotedMessageId: messages[index].id,
|
||||
pinned: math.Random().nextBool(),
|
||||
@@ -69,7 +69,7 @@ void main() {
|
||||
shadowed: math.Random().nextBool(),
|
||||
replyCount: index,
|
||||
updatedAt: DateTime.now(),
|
||||
extraData: {'extra_test_field': 'extraTestData'},
|
||||
extraData: const {'extra_test_field': 'extraTestData'},
|
||||
text: 'Dummy text #$index',
|
||||
pinned: math.Random().nextBool(),
|
||||
pinnedAt: DateTime.now(),
|
||||
@@ -168,7 +168,8 @@ void main() {
|
||||
|
||||
// Fetched message id should match the inserted message id
|
||||
final fetchedMessage = await pinnedMessageDao.getMessageById(id);
|
||||
expect(fetchedMessage.id, insertedMessages.first.id);
|
||||
expect(fetchedMessage, isNotNull);
|
||||
expect(fetchedMessage!.id, insertedMessages.first.id);
|
||||
});
|
||||
|
||||
test('getThreadMessages', () async {
|
||||
@@ -333,7 +334,7 @@ void main() {
|
||||
showInChannel: math.Random().nextBool(),
|
||||
replyCount: 4,
|
||||
updatedAt: DateTime.now(),
|
||||
extraData: {'extra_test_field': 'extraTestData'},
|
||||
extraData: const {'extra_test_field': 'extraTestData'},
|
||||
text: 'Dummy text #4',
|
||||
pinned: math.Random().nextBool(),
|
||||
pinnedAt: DateTime.now(),
|
||||
|
||||
@@ -6,8 +6,8 @@ import 'package:stream_chat_persistence/src/db/moor_chat_database.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
ReactionDao reactionDao;
|
||||
MoorChatDatabase database;
|
||||
late ReactionDao reactionDao;
|
||||
late MoorChatDatabase database;
|
||||
|
||||
setUp(() {
|
||||
database = MoorChatDatabase.testable('testUserId');
|
||||
@@ -16,7 +16,7 @@ void main() {
|
||||
|
||||
Future<List<Reaction>> _prepareReactionData(
|
||||
String messageId, {
|
||||
String userId,
|
||||
String? userId,
|
||||
int count = 3,
|
||||
}) async {
|
||||
final users = List.generate(count, (index) => User(id: 'testUserId$index'));
|
||||
@@ -29,7 +29,7 @@ void main() {
|
||||
showInChannel: math.Random().nextBool(),
|
||||
replyCount: 3,
|
||||
updatedAt: DateTime.now(),
|
||||
extraData: {'extra_test_field': 'extraTestData'},
|
||||
extraData: const {'extra_test_field': 'extraTestData'},
|
||||
text: 'Dummy text',
|
||||
pinned: math.Random().nextBool(),
|
||||
pinnedAt: DateTime.now(),
|
||||
|
||||
@@ -6,8 +6,8 @@ import 'package:test/test.dart';
|
||||
import '../utils/date_matcher.dart';
|
||||
|
||||
void main() {
|
||||
ReadDao readDao;
|
||||
MoorChatDatabase database;
|
||||
late ReadDao readDao;
|
||||
late MoorChatDatabase database;
|
||||
|
||||
setUp(() {
|
||||
database = MoorChatDatabase.testable('testUserId');
|
||||
|
||||
@@ -6,8 +6,8 @@ import 'package:test/test.dart';
|
||||
import 'package:stream_chat/stream_chat.dart';
|
||||
|
||||
void main() {
|
||||
UserDao userDao;
|
||||
MoorChatDatabase database;
|
||||
late UserDao userDao;
|
||||
late MoorChatDatabase database;
|
||||
|
||||
setUp(() {
|
||||
database = MoorChatDatabase.testable('testUserId');
|
||||
|
||||
@@ -34,15 +34,21 @@ void main() {
|
||||
expect(channelModel.updatedAt, isSameDateAs(entity.updatedAt));
|
||||
expect(channelModel.memberCount, entity.memberCount);
|
||||
expect(channelModel.cid, entity.cid);
|
||||
expect(channelModel.lastMessageAt, isSameDateAs(entity.lastMessageAt));
|
||||
expect(channelModel.deletedAt, isSameDateAs(entity.deletedAt));
|
||||
expect(channelModel.lastMessageAt, isSameDateAs(entity.lastMessageAt!));
|
||||
expect(channelModel.deletedAt, isSameDateAs(entity.deletedAt!));
|
||||
expect(channelModel.extraData, entity.extraData);
|
||||
expect(channelModel.createdBy.id, entity.createdById);
|
||||
expect(channelModel.createdBy!.id, entity.createdById);
|
||||
});
|
||||
|
||||
test('toChannelState should map entity into ChannelState ', () {
|
||||
final members = List.generate(3, (index) => Member());
|
||||
final reads = List.generate(3, (index) => Read());
|
||||
final reads = List.generate(
|
||||
3,
|
||||
(index) => Read(
|
||||
user: User(id: 'testUserId$index'),
|
||||
lastRead: DateTime.now(),
|
||||
),
|
||||
);
|
||||
final messages = List.generate(3, (index) => Message());
|
||||
|
||||
final channelState = entity.toChannelState(
|
||||
@@ -59,7 +65,7 @@ void main() {
|
||||
expect(channelState.messages.length, messages.length);
|
||||
expect(channelState.pinnedMessages.length, messages.length);
|
||||
|
||||
final channelModel = channelState.channel;
|
||||
final channelModel = channelState.channel!;
|
||||
expect(channelModel.id, entity.id);
|
||||
expect(channelModel.config.toJson()['max_message_length'], 33);
|
||||
expect(channelModel.frozen, entity.frozen);
|
||||
@@ -67,10 +73,10 @@ void main() {
|
||||
expect(channelModel.updatedAt, isSameDateAs(entity.updatedAt));
|
||||
expect(channelModel.memberCount, entity.memberCount);
|
||||
expect(channelModel.cid, entity.cid);
|
||||
expect(channelModel.lastMessageAt, isSameDateAs(entity.lastMessageAt));
|
||||
expect(channelModel.deletedAt, isSameDateAs(entity.deletedAt));
|
||||
expect(channelModel.lastMessageAt, isSameDateAs(entity.lastMessageAt!));
|
||||
expect(channelModel.deletedAt, isSameDateAs(entity.deletedAt!));
|
||||
expect(channelModel.extraData, entity.extraData);
|
||||
expect(channelModel.createdBy.id, entity.createdById);
|
||||
expect(channelModel.createdBy!.id, entity.createdById);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -103,9 +109,9 @@ void main() {
|
||||
expect(channelEntity.updatedAt, isSameDateAs(model.updatedAt));
|
||||
expect(channelEntity.memberCount, model.memberCount);
|
||||
expect(channelEntity.cid, model.cid);
|
||||
expect(channelEntity.lastMessageAt, isSameDateAs(model.lastMessageAt));
|
||||
expect(channelEntity.deletedAt, isSameDateAs(model.deletedAt));
|
||||
expect(channelEntity.lastMessageAt, isSameDateAs(model.lastMessageAt!));
|
||||
expect(channelEntity.deletedAt, isSameDateAs(model.deletedAt!));
|
||||
expect(channelEntity.extraData, model.extraData);
|
||||
expect(channelEntity.createdById, model.createdBy.id);
|
||||
expect(channelEntity.createdById, model.createdBy!.id);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ void main() {
|
||||
);
|
||||
final event = entity.toEvent();
|
||||
expect(event, isA<Event>());
|
||||
expect(event.me.id, ownUser.id);
|
||||
expect(event.me!.id, ownUser.id);
|
||||
expect(event.totalUnreadCount, entity.totalUnreadCount);
|
||||
expect(event.unreadChannels, entity.unreadChannels);
|
||||
});
|
||||
|
||||
@@ -25,12 +25,12 @@ void main() {
|
||||
);
|
||||
final member = entity.toMember(user: user);
|
||||
expect(member, isA<Member>());
|
||||
expect(member.user.id, entity.userId);
|
||||
expect(member.user!.id, entity.userId);
|
||||
expect(member.createdAt, isSameDateAs(entity.createdAt));
|
||||
expect(member.updatedAt, isSameDateAs(entity.updatedAt));
|
||||
expect(member.role, entity.role);
|
||||
expect(member.inviteAcceptedAt, isSameDateAs(entity.inviteAcceptedAt));
|
||||
expect(member.inviteRejectedAt, isSameDateAs(entity.inviteRejectedAt));
|
||||
expect(member.inviteAcceptedAt, isSameDateAs(entity.inviteAcceptedAt!));
|
||||
expect(member.inviteRejectedAt, isSameDateAs(entity.inviteRejectedAt!));
|
||||
expect(member.invited, entity.invited);
|
||||
expect(member.banned, entity.banned);
|
||||
expect(member.shadowBanned, entity.shadowBanned);
|
||||
@@ -55,12 +55,12 @@ void main() {
|
||||
final entity = member.toEntity(cid: cid);
|
||||
expect(entity, isA<MemberEntity>());
|
||||
expect(entity.channelCid, cid);
|
||||
expect(entity.userId, member.user.id);
|
||||
expect(entity.userId, member.user!.id);
|
||||
expect(entity.createdAt, isSameDateAs(member.createdAt));
|
||||
expect(entity.updatedAt, isSameDateAs(member.updatedAt));
|
||||
expect(entity.role, member.role);
|
||||
expect(entity.inviteAcceptedAt, isSameDateAs(member.inviteAcceptedAt));
|
||||
expect(entity.inviteRejectedAt, isSameDateAs(member.inviteRejectedAt));
|
||||
expect(entity.inviteAcceptedAt, isSameDateAs(member.inviteAcceptedAt!));
|
||||
expect(entity.inviteRejectedAt, isSameDateAs(member.inviteRejectedAt!));
|
||||
expect(entity.invited, member.invited);
|
||||
expect(entity.banned, member.banned);
|
||||
expect(entity.shadowBanned, member.shadowBanned);
|
||||
|
||||
@@ -32,7 +32,7 @@ void main() {
|
||||
);
|
||||
final entity = MessageEntity(
|
||||
id: 'testMessageId',
|
||||
attachments: attachments?.map((it) => jsonEncode(it.toData()))?.toList(),
|
||||
attachments: attachments.map((it) => jsonEncode(it.toData())).toList(),
|
||||
channelCid: 'testCid',
|
||||
type: 'testType',
|
||||
parentId: 'testParentId',
|
||||
@@ -46,8 +46,9 @@ void main() {
|
||||
reactionCounts: reactions.fold(
|
||||
{},
|
||||
(prev, curr) =>
|
||||
prev..update(curr.type, (value) => value + 1, ifAbsent: () => 1),
|
||||
prev?..update(curr.type, (value) => value + 1, ifAbsent: () => 1),
|
||||
),
|
||||
mentionedUsers: const [],
|
||||
status: MessageSendingStatus.sent,
|
||||
updatedAt: DateTime.now(),
|
||||
extraData: {'extra_test_data': 'extraData'},
|
||||
@@ -82,13 +83,13 @@ void main() {
|
||||
expect(message.status, entity.status);
|
||||
expect(message.updatedAt, isSameDateAs(entity.updatedAt));
|
||||
expect(message.extraData, entity.extraData);
|
||||
expect(message.user.id, entity.userId);
|
||||
expect(message.deletedAt, isSameDateAs(entity.deletedAt));
|
||||
expect(message.user!.id, entity.userId);
|
||||
expect(message.deletedAt, isSameDateAs(entity.deletedAt!));
|
||||
expect(message.text, entity.messageText);
|
||||
expect(message.pinned, entity.pinned);
|
||||
expect(message.pinExpires, isSameDateAs(entity.pinExpires));
|
||||
expect(message.pinnedAt, isSameDateAs(entity.pinnedAt));
|
||||
expect(message.pinnedBy.id, entity.pinnedByUserId);
|
||||
expect(message.pinExpires, isSameDateAs(entity.pinExpires!));
|
||||
expect(message.pinnedAt, isSameDateAs(entity.pinnedAt!));
|
||||
expect(message.pinnedBy!.id, entity.pinnedByUserId);
|
||||
expect(message.reactionCounts, entity.reactionCounts);
|
||||
expect(message.reactionScores, entity.reactionScores);
|
||||
for (var i = 0; i < message.attachments.length; i++) {
|
||||
@@ -138,11 +139,11 @@ void main() {
|
||||
reactionCounts: reactions.fold(
|
||||
{},
|
||||
(prev, curr) =>
|
||||
prev..update(curr.type, (value) => value + 1, ifAbsent: () => 1),
|
||||
prev?..update(curr.type, (value) => value + 1, ifAbsent: () => 1),
|
||||
),
|
||||
status: MessageSendingStatus.sending,
|
||||
updatedAt: DateTime.now(),
|
||||
extraData: {'extra_test_data': 'extraData'},
|
||||
extraData: const {'extra_test_data': 'extraData'},
|
||||
user: user,
|
||||
deletedAt: DateTime.now(),
|
||||
text: 'dummy text',
|
||||
@@ -167,18 +168,18 @@ void main() {
|
||||
expect(entity.status, message.status);
|
||||
expect(entity.updatedAt, isSameDateAs(message.updatedAt));
|
||||
expect(entity.extraData, message.extraData);
|
||||
expect(entity.userId, message.user.id);
|
||||
expect(entity.deletedAt, isSameDateAs(message.deletedAt));
|
||||
expect(entity.userId, message.user!.id);
|
||||
expect(entity.deletedAt, isSameDateAs(message.deletedAt!));
|
||||
expect(entity.messageText, message.text);
|
||||
expect(entity.pinned, message.pinned);
|
||||
expect(entity.pinExpires, isSameDateAs(message.pinExpires));
|
||||
expect(entity.pinnedAt, isSameDateAs(message.pinnedAt));
|
||||
expect(entity.pinnedByUserId, message.pinnedBy.id);
|
||||
expect(entity.pinExpires, isSameDateAs(message.pinExpires!));
|
||||
expect(entity.pinnedAt, isSameDateAs(message.pinnedAt!));
|
||||
expect(entity.pinnedByUserId, message.pinnedBy!.id);
|
||||
expect(entity.reactionCounts, message.reactionCounts);
|
||||
expect(entity.reactionScores, message.reactionScores);
|
||||
expect(
|
||||
entity.attachments,
|
||||
message.attachments?.map((it) => jsonEncode(it.toData()))?.toList(),
|
||||
message.attachments.map((it) => jsonEncode(it.toData())).toList(),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ void main() {
|
||||
);
|
||||
final entity = PinnedMessageEntity(
|
||||
id: 'testMessageId',
|
||||
attachments: attachments?.map((it) => jsonEncode(it.toData()))?.toList(),
|
||||
attachments: attachments.map((it) => jsonEncode(it.toData())).toList(),
|
||||
channelCid: 'testCid',
|
||||
type: 'testType',
|
||||
parentId: 'testParentId',
|
||||
@@ -46,8 +46,9 @@ void main() {
|
||||
reactionCounts: reactions.fold(
|
||||
{},
|
||||
(prev, curr) =>
|
||||
prev..update(curr.type, (value) => value + 1, ifAbsent: () => 1),
|
||||
prev?..update(curr.type, (value) => value + 1, ifAbsent: () => 1),
|
||||
),
|
||||
mentionedUsers: [],
|
||||
status: MessageSendingStatus.sent,
|
||||
updatedAt: DateTime.now(),
|
||||
extraData: {'extra_test_data': 'extraData'},
|
||||
@@ -82,13 +83,13 @@ void main() {
|
||||
expect(message.status, entity.status);
|
||||
expect(message.updatedAt, isSameDateAs(entity.updatedAt));
|
||||
expect(message.extraData, entity.extraData);
|
||||
expect(message.user.id, entity.userId);
|
||||
expect(message.deletedAt, isSameDateAs(entity.deletedAt));
|
||||
expect(message.user!.id, entity.userId);
|
||||
expect(message.deletedAt, isSameDateAs(entity.deletedAt!));
|
||||
expect(message.text, entity.messageText);
|
||||
expect(message.pinned, entity.pinned);
|
||||
expect(message.pinExpires, isSameDateAs(entity.pinExpires));
|
||||
expect(message.pinnedAt, isSameDateAs(entity.pinnedAt));
|
||||
expect(message.pinnedBy.id, entity.pinnedByUserId);
|
||||
expect(message.pinExpires, isSameDateAs(entity.pinExpires!));
|
||||
expect(message.pinnedAt, isSameDateAs(entity.pinnedAt!));
|
||||
expect(message.pinnedBy!.id, entity.pinnedByUserId);
|
||||
expect(message.reactionCounts, entity.reactionCounts);
|
||||
expect(message.reactionScores, entity.reactionScores);
|
||||
for (var i = 0; i < message.attachments.length; i++) {
|
||||
@@ -138,11 +139,11 @@ void main() {
|
||||
reactionCounts: reactions.fold(
|
||||
{},
|
||||
(prev, curr) =>
|
||||
prev..update(curr.type, (value) => value + 1, ifAbsent: () => 1),
|
||||
prev?..update(curr.type, (value) => value + 1, ifAbsent: () => 1),
|
||||
),
|
||||
status: MessageSendingStatus.sending,
|
||||
updatedAt: DateTime.now(),
|
||||
extraData: {'extra_test_data': 'extraData'},
|
||||
extraData: const {'extra_test_data': 'extraData'},
|
||||
user: user,
|
||||
deletedAt: DateTime.now(),
|
||||
text: 'dummy text',
|
||||
@@ -167,18 +168,18 @@ void main() {
|
||||
expect(entity.status, message.status);
|
||||
expect(entity.updatedAt, isSameDateAs(message.updatedAt));
|
||||
expect(entity.extraData, message.extraData);
|
||||
expect(entity.userId, message.user.id);
|
||||
expect(entity.deletedAt, isSameDateAs(message.deletedAt));
|
||||
expect(entity.userId, message.user!.id);
|
||||
expect(entity.deletedAt, isSameDateAs(message.deletedAt!));
|
||||
expect(entity.messageText, message.text);
|
||||
expect(entity.pinned, message.pinned);
|
||||
expect(entity.pinExpires, isSameDateAs(message.pinExpires));
|
||||
expect(entity.pinnedAt, isSameDateAs(message.pinnedAt));
|
||||
expect(entity.pinnedByUserId, message.pinnedBy.id);
|
||||
expect(entity.pinExpires, isSameDateAs(message.pinExpires!));
|
||||
expect(entity.pinnedAt, isSameDateAs(message.pinnedAt!));
|
||||
expect(entity.pinnedByUserId, message.pinnedBy!.id);
|
||||
expect(entity.reactionCounts, message.reactionCounts);
|
||||
expect(entity.reactionScores, message.reactionScores);
|
||||
expect(
|
||||
entity.attachments,
|
||||
message.attachments?.map((it) => jsonEncode(it.toData()))?.toList(),
|
||||
message.attachments.map((it) => jsonEncode(it.toData())).toList(),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ void main() {
|
||||
expect(user.role, entity.role);
|
||||
expect(user.createdAt, isSameDateAs(entity.createdAt));
|
||||
expect(user.updatedAt, isSameDateAs(entity.updatedAt));
|
||||
expect(user.lastActive, isSameDateAs(entity.lastActive));
|
||||
expect(user.lastActive, isSameDateAs(entity.lastActive!));
|
||||
expect(user.online, entity.online);
|
||||
expect(user.banned, entity.banned);
|
||||
expect(user.extraData, entity.extraData);
|
||||
@@ -47,7 +47,7 @@ void main() {
|
||||
expect(entity.role, user.role);
|
||||
expect(entity.createdAt, isSameDateAs(user.createdAt));
|
||||
expect(entity.updatedAt, isSameDateAs(user.updatedAt));
|
||||
expect(entity.lastActive, isSameDateAs(user.lastActive));
|
||||
expect(entity.lastActive, isSameDateAs(user.lastActive!));
|
||||
expect(entity.online, user.online);
|
||||
expect(entity.banned, user.banned);
|
||||
expect(entity.extraData, user.extraData);
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
import 'package:test/test.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
Matcher isSameDateAs(DateTime targetDate) =>
|
||||
_IsSameDateAs(targetDate: targetDate);
|
||||
|
||||
class _IsSameDateAs extends Matcher {
|
||||
const _IsSameDateAs({
|
||||
@required this.targetDate,
|
||||
}) : assert(targetDate != null, '');
|
||||
const _IsSameDateAs({required this.targetDate});
|
||||
|
||||
final DateTime targetDate;
|
||||
|
||||
|
||||
@@ -10,22 +10,6 @@ MoorChatDatabase _testDatabaseProvider(String userId, ConnectionMode mode) =>
|
||||
MoorChatDatabase.testable(userId);
|
||||
|
||||
void main() {
|
||||
group('client constructor', () {
|
||||
test('throws assertion error if null connectionMode is provided', () {
|
||||
expect(
|
||||
() => StreamChatPersistenceClient(connectionMode: null),
|
||||
throwsA(isA<AssertionError>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('throws assertion error if null logLevel is provided', () {
|
||||
expect(
|
||||
() => StreamChatPersistenceClient(logLevel: null),
|
||||
throwsA(isA<AssertionError>()),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('connect', () {
|
||||
const userId = 'testUserId';
|
||||
test('successfully connects with the Database', () async {
|
||||
@@ -34,7 +18,7 @@ void main() {
|
||||
await client.connect(userId, databaseProvider: _testDatabaseProvider);
|
||||
expect(client.db, isNotNull);
|
||||
expect(client.db, isA<MoorChatDatabase>());
|
||||
expect(client.db.userId, userId);
|
||||
expect(client.db!.userId, userId);
|
||||
|
||||
addTearDown(() async {
|
||||
await client.disconnect();
|
||||
@@ -48,7 +32,7 @@ void main() {
|
||||
expect(client.db, isNotNull);
|
||||
expect(client.db, isNotNull);
|
||||
expect(client.db, isA<MoorChatDatabase>());
|
||||
expect(client.db.userId, userId);
|
||||
expect(client.db!.userId, userId);
|
||||
expect(
|
||||
() => client.connect(userId, databaseProvider: _testDatabaseProvider),
|
||||
throwsException,
|
||||
@@ -73,7 +57,7 @@ void main() {
|
||||
const userId = 'testUserId';
|
||||
final mockDatabase = MockChatDatabase();
|
||||
MoorChatDatabase _mockDatabaseProvider(_, __) => mockDatabase;
|
||||
StreamChatPersistenceClient client;
|
||||
late StreamChatPersistenceClient client;
|
||||
|
||||
setUp(() async {
|
||||
client = StreamChatPersistenceClient(logLevel: Level.ALL);
|
||||
@@ -95,12 +79,13 @@ void main() {
|
||||
});
|
||||
|
||||
test('getConnectionInfo', () async {
|
||||
final event = Event(type: 'testEvent');
|
||||
const event = Event(type: 'testEvent');
|
||||
when(() => mockDatabase.connectionEventDao.connectionEvent)
|
||||
.thenAnswer((_) async => event);
|
||||
|
||||
final fetchedEvent = await client.getConnectionInfo();
|
||||
expect(fetchedEvent.type, event.type);
|
||||
expect(fetchedEvent, isNotNull);
|
||||
expect(fetchedEvent!.type, event.type);
|
||||
verify(() => mockDatabase.connectionEventDao.connectionEvent).called(1);
|
||||
});
|
||||
|
||||
@@ -115,11 +100,9 @@ void main() {
|
||||
});
|
||||
|
||||
test('updateConnectionInfo', () async {
|
||||
final event = Event(type: 'testEvent');
|
||||
const event = Event(type: 'testEvent');
|
||||
when(() => mockDatabase.connectionEventDao.updateConnectionEvent(event))
|
||||
.thenAnswer((_) async {
|
||||
return;
|
||||
});
|
||||
.thenAnswer((_) async => 1);
|
||||
|
||||
await client.updateConnectionInfo(event);
|
||||
verify(() => mockDatabase.connectionEventDao.updateConnectionEvent(event))
|
||||
@@ -129,9 +112,7 @@ void main() {
|
||||
test('updateLastSyncAt', () async {
|
||||
final lastSync = DateTime.now();
|
||||
when(() => mockDatabase.connectionEventDao.updateLastSyncAt(lastSync))
|
||||
.thenAnswer((_) {
|
||||
return;
|
||||
});
|
||||
.thenAnswer((_) async => 1);
|
||||
|
||||
await client.updateLastSyncAt(lastSync);
|
||||
verify(() => mockDatabase.connectionEventDao.updateLastSyncAt(lastSync))
|
||||
@@ -149,13 +130,14 @@ void main() {
|
||||
});
|
||||
|
||||
test('getChannelByCid', () async {
|
||||
const cid = 'testCid';
|
||||
const cid = 'testType:testId';
|
||||
final channelModel = ChannelModel(cid: cid);
|
||||
when(() => mockDatabase.channelDao.getChannelByCid(cid))
|
||||
.thenAnswer((_) async => channelModel);
|
||||
|
||||
final fetchedChannelModel = await client.getChannelByCid(cid);
|
||||
expect(fetchedChannelModel.cid, channelModel.cid);
|
||||
expect(fetchedChannelModel, isNotNull);
|
||||
expect(fetchedChannelModel!.cid, channelModel.cid);
|
||||
verify(() => mockDatabase.channelDao.getChannelByCid(cid)).called(1);
|
||||
});
|
||||
|
||||
@@ -172,7 +154,13 @@ void main() {
|
||||
|
||||
test('getReadsByCid', () async {
|
||||
const cid = 'testCid';
|
||||
final reads = List.generate(3, (index) => Read());
|
||||
final reads = List.generate(
|
||||
3,
|
||||
(index) => Read(
|
||||
user: User(id: 'testUserId$index'),
|
||||
lastRead: DateTime.now(),
|
||||
),
|
||||
);
|
||||
when(() => mockDatabase.readDao.getReadsByCid(cid))
|
||||
.thenAnswer((_) async => reads);
|
||||
|
||||
@@ -205,10 +193,16 @@ void main() {
|
||||
});
|
||||
|
||||
test('getChannelStateByCid', () async {
|
||||
const cid = 'testCid';
|
||||
const cid = 'testType:testId';
|
||||
final messages = List.generate(3, (index) => Message());
|
||||
final members = List.generate(3, (index) => Member());
|
||||
final reads = List.generate(3, (index) => Read());
|
||||
final reads = List.generate(
|
||||
3,
|
||||
(index) => Read(
|
||||
user: User(id: 'testUserId$index'),
|
||||
lastRead: DateTime.now(),
|
||||
),
|
||||
);
|
||||
final channel = ChannelModel(cid: cid);
|
||||
|
||||
when(() => mockDatabase.memberDao.getMembersByCid(cid))
|
||||
@@ -227,7 +221,7 @@ void main() {
|
||||
expect(fetchedChannelState.pinnedMessages.length, messages.length);
|
||||
expect(fetchedChannelState.members.length, members.length);
|
||||
expect(fetchedChannelState.read.length, reads.length);
|
||||
expect(fetchedChannelState.channel.cid, channel.cid);
|
||||
expect(fetchedChannelState.channel!.cid, channel.cid);
|
||||
|
||||
verify(() => mockDatabase.memberDao.getMembersByCid(cid)).called(1);
|
||||
verify(() => mockDatabase.readDao.getReadsByCid(cid)).called(1);
|
||||
@@ -238,11 +232,17 @@ void main() {
|
||||
});
|
||||
|
||||
test('getChannelStates', () async {
|
||||
const cid = 'testCid';
|
||||
const cid = 'testType:testId';
|
||||
final channels = List.generate(3, (index) => ChannelModel(cid: cid));
|
||||
final messages = List.generate(3, (index) => Message());
|
||||
final members = List.generate(3, (index) => Member());
|
||||
final reads = List.generate(3, (index) => Read());
|
||||
final reads = List.generate(
|
||||
3,
|
||||
(index) => Read(
|
||||
user: User(id: 'testUserId$index'),
|
||||
lastRead: DateTime.now(),
|
||||
),
|
||||
);
|
||||
final channel = ChannelModel(cid: cid);
|
||||
final channelStates = channels
|
||||
.map(
|
||||
@@ -279,7 +279,7 @@ void main() {
|
||||
expect(fetched.messages.length, original.messages.length);
|
||||
expect(fetched.pinnedMessages.length, original.pinnedMessages.length);
|
||||
expect(fetched.read.length, original.read.length);
|
||||
expect(fetched.channel.cid, original.channel.cid);
|
||||
expect(fetched.channel!.cid, original.channel!.cid);
|
||||
}
|
||||
|
||||
verify(() => mockDatabase.channelQueryDao.getChannels()).called(1);
|
||||
@@ -296,9 +296,7 @@ void main() {
|
||||
const cids = <String>[];
|
||||
when(() =>
|
||||
mockDatabase.channelQueryDao.updateChannelQueries(filter, cids))
|
||||
.thenAnswer((realInvocation) async {
|
||||
return;
|
||||
});
|
||||
.thenAnswer((_) => Future.value());
|
||||
|
||||
await client.updateChannelQueries(filter, cids);
|
||||
verify(() =>
|
||||
@@ -309,9 +307,7 @@ void main() {
|
||||
test('deleteMessageById', () async {
|
||||
const messageId = 'testMessageId';
|
||||
when(() => mockDatabase.messageDao.deleteMessageByIds([messageId]))
|
||||
.thenAnswer((_) async {
|
||||
return;
|
||||
});
|
||||
.thenAnswer((_) async => 1);
|
||||
|
||||
await client.deleteMessageById(messageId);
|
||||
verify(() => mockDatabase.messageDao.deleteMessageByIds([messageId]))
|
||||
@@ -321,9 +317,7 @@ void main() {
|
||||
test('deletePinnedMessageById', () async {
|
||||
const messageId = 'testMessageId';
|
||||
when(() => mockDatabase.pinnedMessageDao.deleteMessageByIds([messageId]))
|
||||
.thenAnswer((_) async {
|
||||
return;
|
||||
});
|
||||
.thenAnswer((_) async => 1);
|
||||
|
||||
await client.deletePinnedMessageById(messageId);
|
||||
verify(() =>
|
||||
@@ -334,9 +328,7 @@ void main() {
|
||||
test('deleteMessageByIds', () async {
|
||||
const messageIds = <String>[];
|
||||
when(() => mockDatabase.messageDao.deleteMessageByIds(messageIds))
|
||||
.thenAnswer((_) async {
|
||||
return;
|
||||
});
|
||||
.thenAnswer((_) async => 1);
|
||||
|
||||
await client.deleteMessageByIds(messageIds);
|
||||
verify(() => mockDatabase.messageDao.deleteMessageByIds(messageIds))
|
||||
@@ -346,9 +338,7 @@ void main() {
|
||||
test('deletePinnedMessageByIds', () async {
|
||||
const messageIds = <String>[];
|
||||
when(() => mockDatabase.pinnedMessageDao.deleteMessageByIds(messageIds))
|
||||
.thenAnswer((_) async {
|
||||
return;
|
||||
});
|
||||
.thenAnswer((_) async => 1);
|
||||
|
||||
await client.deletePinnedMessageByIds(messageIds);
|
||||
verify(() => mockDatabase.pinnedMessageDao.deleteMessageByIds(messageIds))
|
||||
@@ -358,9 +348,7 @@ void main() {
|
||||
test('deleteMessageByCid', () async {
|
||||
const cid = 'testCid';
|
||||
when(() => mockDatabase.messageDao.deleteMessageByCids([cid]))
|
||||
.thenAnswer((_) async {
|
||||
return;
|
||||
});
|
||||
.thenAnswer((_) async => 1);
|
||||
|
||||
await client.deleteMessageByCid(cid);
|
||||
verify(() => mockDatabase.messageDao.deleteMessageByCids([cid]))
|
||||
@@ -370,9 +358,7 @@ void main() {
|
||||
test('deletePinnedMessageByCid', () async {
|
||||
const cid = 'testCid';
|
||||
when(() => mockDatabase.pinnedMessageDao.deleteMessageByCids([cid]))
|
||||
.thenAnswer((_) async {
|
||||
return;
|
||||
});
|
||||
.thenAnswer((_) async => 1);
|
||||
|
||||
await client.deletePinnedMessageByCid(cid);
|
||||
verify(() => mockDatabase.pinnedMessageDao.deleteMessageByCids([cid]))
|
||||
@@ -382,9 +368,7 @@ void main() {
|
||||
test('deleteMessageByCids', () async {
|
||||
const cids = <String>[];
|
||||
when(() => mockDatabase.messageDao.deleteMessageByCids(cids))
|
||||
.thenAnswer((_) async {
|
||||
return;
|
||||
});
|
||||
.thenAnswer((_) async => 1);
|
||||
|
||||
await client.deleteMessageByCids(cids);
|
||||
verify(() => mockDatabase.messageDao.deleteMessageByCids(cids)).called(1);
|
||||
@@ -393,9 +377,7 @@ void main() {
|
||||
test('deletePinnedMessageByCids', () async {
|
||||
const cids = <String>[];
|
||||
when(() => mockDatabase.pinnedMessageDao.deleteMessageByCids(cids))
|
||||
.thenAnswer((_) async {
|
||||
return;
|
||||
});
|
||||
.thenAnswer((_) async => 1);
|
||||
|
||||
await client.deletePinnedMessageByCids(cids);
|
||||
verify(() => mockDatabase.pinnedMessageDao.deleteMessageByCids(cids))
|
||||
@@ -405,9 +387,7 @@ void main() {
|
||||
test('deleteChannels', () async {
|
||||
const cids = <String>[];
|
||||
when(() => mockDatabase.channelDao.deleteChannelByCids(cids))
|
||||
.thenAnswer((_) async {
|
||||
return;
|
||||
});
|
||||
.thenAnswer((_) async => 1);
|
||||
|
||||
await client.deleteChannels(cids);
|
||||
verify(() => mockDatabase.channelDao.deleteChannelByCids(cids)).called(1);
|
||||
@@ -417,9 +397,7 @@ void main() {
|
||||
const cid = 'testCid';
|
||||
final messages = List.generate(3, (index) => Message());
|
||||
when(() => mockDatabase.messageDao.updateMessages(cid, messages))
|
||||
.thenAnswer((_) async {
|
||||
return;
|
||||
});
|
||||
.thenAnswer((_) => Future.value());
|
||||
|
||||
await client.updateMessages(cid, messages);
|
||||
verify(() => mockDatabase.messageDao.updateMessages(cid, messages))
|
||||
@@ -430,9 +408,7 @@ void main() {
|
||||
const cid = 'testCid';
|
||||
final messages = List.generate(3, (index) => Message());
|
||||
when(() => mockDatabase.pinnedMessageDao.updateMessages(cid, messages))
|
||||
.thenAnswer((_) async {
|
||||
return;
|
||||
});
|
||||
.thenAnswer((_) => Future.value());
|
||||
|
||||
await client.updatePinnedMessages(cid, messages);
|
||||
verify(() => mockDatabase.pinnedMessageDao.updateMessages(cid, messages))
|
||||
@@ -445,14 +421,12 @@ void main() {
|
||||
List.generate(3, (index) => Message(parentId: 'testParentId$index'));
|
||||
final threads = messages.fold<Map<String, List<Message>>>(
|
||||
{},
|
||||
(prev, curr) {
|
||||
return prev
|
||||
..update(
|
||||
curr.parentId,
|
||||
(value) => [...value, curr],
|
||||
ifAbsent: () => [],
|
||||
);
|
||||
},
|
||||
(prev, curr) => prev
|
||||
..update(
|
||||
curr.parentId!,
|
||||
(value) => [...value, curr],
|
||||
ifAbsent: () => [],
|
||||
),
|
||||
);
|
||||
when(() => mockDatabase.messageDao.getThreadMessages(cid))
|
||||
.thenAnswer((realInvocation) async => messages);
|
||||
@@ -469,11 +443,10 @@ void main() {
|
||||
});
|
||||
|
||||
test('updateChannels', () async {
|
||||
final channels = List.generate(3, (index) => ChannelModel());
|
||||
const cid = 'testType:testId';
|
||||
final channels = List.generate(3, (index) => ChannelModel(cid: cid));
|
||||
when(() => mockDatabase.channelDao.updateChannels(channels))
|
||||
.thenAnswer((_) async {
|
||||
return;
|
||||
});
|
||||
.thenAnswer((_) => Future.value());
|
||||
|
||||
await client.updateChannels(channels);
|
||||
verify(() => mockDatabase.channelDao.updateChannels(channels)).called(1);
|
||||
@@ -483,9 +456,7 @@ void main() {
|
||||
const cid = 'testCid';
|
||||
final members = List.generate(3, (index) => Member());
|
||||
when(() => mockDatabase.memberDao.updateMembers(cid, members))
|
||||
.thenAnswer((_) async {
|
||||
return;
|
||||
});
|
||||
.thenAnswer((_) => Future.value());
|
||||
|
||||
await client.updateMembers(cid, members);
|
||||
verify(() => mockDatabase.memberDao.updateMembers(cid, members))
|
||||
@@ -494,32 +465,36 @@ void main() {
|
||||
|
||||
test('updateReads', () async {
|
||||
const cid = 'testCid';
|
||||
final reads = List.generate(3, (index) => Read());
|
||||
final reads = List.generate(
|
||||
3,
|
||||
(index) => Read(
|
||||
user: User(id: 'testUserId$index'),
|
||||
lastRead: DateTime.now(),
|
||||
),
|
||||
);
|
||||
when(() => mockDatabase.readDao.updateReads(cid, reads))
|
||||
.thenAnswer((_) async {
|
||||
return;
|
||||
});
|
||||
.thenAnswer((_) => Future.value());
|
||||
|
||||
await client.updateReads(cid, reads);
|
||||
verify(() => mockDatabase.readDao.updateReads(cid, reads)).called(1);
|
||||
});
|
||||
|
||||
test('updateUsers', () async {
|
||||
final users = List.generate(3, (index) => User());
|
||||
when(() => mockDatabase.userDao.updateUsers(users)).thenAnswer((_) async {
|
||||
return;
|
||||
});
|
||||
final users = List.generate(3, (index) => User(id: 'testUserId$index'));
|
||||
when(() => mockDatabase.userDao.updateUsers(users))
|
||||
.thenAnswer((_) => Future.value());
|
||||
|
||||
await client.updateUsers(users);
|
||||
verify(() => mockDatabase.userDao.updateUsers(users)).called(1);
|
||||
});
|
||||
|
||||
test('updateReactions', () async {
|
||||
final reactions = List.generate(3, (index) => Reaction());
|
||||
final reactions = List.generate(
|
||||
3,
|
||||
(index) => Reaction(type: 'testType$index'),
|
||||
);
|
||||
when(() => mockDatabase.reactionDao.updateReactions(reactions))
|
||||
.thenAnswer((_) async {
|
||||
return;
|
||||
});
|
||||
.thenAnswer((_) => Future.value());
|
||||
|
||||
await client.updateReactions(reactions);
|
||||
verify(() => mockDatabase.reactionDao.updateReactions(reactions))
|
||||
@@ -530,9 +505,7 @@ void main() {
|
||||
final messageIds = <String>[];
|
||||
when(() =>
|
||||
mockDatabase.reactionDao.deleteReactionsByMessageIds(messageIds))
|
||||
.thenAnswer((_) async {
|
||||
return;
|
||||
});
|
||||
.thenAnswer((_) => Future.value());
|
||||
|
||||
await client.deleteReactionsByMessageId(messageIds);
|
||||
verify(() =>
|
||||
@@ -543,9 +516,7 @@ void main() {
|
||||
test('deleteMembersByCids', () async {
|
||||
final cids = <String>[];
|
||||
when(() => mockDatabase.memberDao.deleteMemberByCids(cids))
|
||||
.thenAnswer((_) async {
|
||||
return;
|
||||
});
|
||||
.thenAnswer((_) => Future.value());
|
||||
|
||||
await client.deleteMembersByCids(cids);
|
||||
verify(() => mockDatabase.memberDao.deleteMemberByCids(cids)).called(1);
|
||||
|
||||
Reference in New Issue
Block a user