This commit is contained in:
Salvatore Giordano
2021-04-13 10:30:06 +02:00
parent 59b99e1cb2
commit 391eb8c1ce
5 changed files with 57 additions and 82 deletions
+3 -14
View File
@@ -321,15 +321,6 @@ class Channel {
).toList(), ).toList(),
); );
if (message.parentId != null && message.id == null) {
final parentMessage =
state!.messages!.firstWhere((m) => m.id == message.parentId);
state?.addMessage(parentMessage.copyWith(
replyCount: parentMessage.replyCount! + 1,
));
}
state?.addMessage(message); state?.addMessage(message);
try { try {
@@ -348,7 +339,7 @@ class Channel {
message = await attachmentsUploadCompleter.future; message = await attachmentsUploadCompleter.future;
} }
final response = await (_client.sendMessage(message, id, type)); final response = await _client.sendMessage(message, id, type);
state?.addMessage(response!.message!); state?.addMessage(response!.message!);
return response; return response;
} catch (error) { } catch (error) {
@@ -466,8 +457,7 @@ class Channel {
) { ) {
assert(() { assert(() {
if (timeoutOrExpirationDate is! DateTime && if (timeoutOrExpirationDate is! DateTime &&
timeoutOrExpirationDate is! num && timeoutOrExpirationDate is! num) {
timeoutOrExpirationDate != null) {
throw ArgumentError('Invalid timeout or Expiration date'); throw ArgumentError('Invalid timeout or Expiration date');
} }
return true; return true;
@@ -997,7 +987,7 @@ class Channel {
cid, cid,
messagePagination: messagesPagination, messagePagination: messagesPagination,
))!; ))!;
if (updatedState != null && updatedState.messages!.isNotEmpty) { if (updatedState.messages!.isNotEmpty) {
if (state == null) { if (state == null) {
_initState(updatedState); _initState(updatedState);
} else { } else {
@@ -1382,7 +1372,6 @@ class ChannelClientState {
<Message>[...messages!, ...threads!.values.expand((v) => v)] <Message>[...messages!, ...threads!.values.expand((v) => v)]
.where( .where(
(message) => (message) =>
message.status != null &&
message.status != MessageSendingStatus.sent && message.status != MessageSendingStatus.sent &&
message.createdAt!.isBefore( message.createdAt!.isBefore(
DateTime.now().subtract( DateTime.now().subtract(
+14 -22
View File
@@ -723,9 +723,7 @@ class StreamChatClient {
payload.addAll(options); payload.addAll(options);
} }
if (paginationParams != null) { payload.addAll(paginationParams.toJson());
payload.addAll(paginationParams.toJson());
}
final response = await get( final response = await get(
'/channels', '/channels',
@@ -765,8 +763,7 @@ class StreamChatClient {
await _chatPersistenceClient?.updateChannelQueries( await _chatPersistenceClient?.updateChannelQueries(
filter, filter,
channels.map((c) => c.channel!.cid).toList(), channels.map((c) => c.channel!.cid).toList(),
clearQueryCache: clearQueryCache: paginationParams.offset == 0,
paginationParams.offset == null || paginationParams.offset == 0,
); );
state!.channels = updateData.key; state!.channels = updateData.key;
@@ -794,17 +791,15 @@ class StreamChatClient {
) { ) {
final channels = {...state!.channels ?? {}}; final channels = {...state!.channels ?? {}};
final newChannels = <Channel>[]; final newChannels = <Channel>[];
if (channelStates != null) { for (final channelState in channelStates) {
for (final channelState in channelStates) { final channel = channels[channelState.channel!.cid];
final channel = channels[channelState.channel!.cid]; if (channel != null) {
if (channel != null) { channel.state?.updateChannelState(channelState);
channel.state?.updateChannelState(channelState); newChannels.add(channel);
newChannels.add(channel); } else {
} else { final newChannel = Channel.fromState(this, channelState);
final newChannel = Channel.fromState(this, channelState); channels[newChannel.cid] = newChannel;
channels[newChannel.cid] = newChannel; newChannels.add(newChannel);
newChannels.add(newChannel);
}
} }
} }
return MapEntry(channels, newChannels); return MapEntry(channels, newChannels);
@@ -1071,7 +1066,7 @@ class StreamChatClient {
Map<String, dynamic>? messageFilters, Map<String, dynamic>? messageFilters,
}) async { }) async {
assert(() { assert(() {
if (filters == null || filters.isEmpty) { if (filters.isEmpty) {
throw ArgumentError('`filters` cannot be set as null or empty'); throw ArgumentError('`filters` cannot be set as null or empty');
} }
if (query == null && messageFilters == null) { if (query == null && messageFilters == null) {
@@ -1199,9 +1194,7 @@ class StreamChatClient {
String? id, String? id,
Map<String, dynamic>? extraData, Map<String, dynamic>? extraData,
}) { }) {
if (type != null && if (id != null && state!.channels?.containsKey('$type:$id') == true) {
id != null &&
state!.channels?.containsKey('$type:$id') == true) {
if (state!.channels!['$type:$id'] != null) { if (state!.channels!['$type:$id'] != null) {
return state!.channels!['$type:$id'] as Channel; return state!.channels!['$type:$id'] as Channel;
} }
@@ -1369,8 +1362,7 @@ class StreamChatClient {
) { ) {
assert(() { assert(() {
if (timeoutOrExpirationDate is! DateTime && if (timeoutOrExpirationDate is! DateTime &&
timeoutOrExpirationDate is! num && timeoutOrExpirationDate is! num) {
timeoutOrExpirationDate != null) {
throw ArgumentError('Invalid timeout or Expiration date'); throw ArgumentError('Invalid timeout or Expiration date');
} }
return true; return true;
@@ -1,6 +1,6 @@
/// Useful extension functions for [Map] /// Useful extension functions for [Map]
extension MapX on Map { extension MapX on Map {
/// Returns a new map with null keys or values removed /// Returns a new map with null keys or values removed
Map<String, dynamic> get nullProtected => {...this as Map<String, dynamic>} Map<String?, dynamic> get nullProtected => {...this as Map<String?, dynamic>}
..removeWhere((key, value) => key == null || value == null); ..removeWhere((key, value) => key == null || value == null);
} }
@@ -314,39 +314,36 @@ class Message extends Equatable {
/// Returns a new [Message] that is a combination of this message and the /// Returns a new [Message] that is a combination of this message and the
/// given [other] message. /// given [other] message.
Message merge(Message other) { Message merge(Message other) => copyWith(
if (other == null) return this; id: other.id,
return copyWith( text: other.text,
id: other.id, type: other.type,
text: other.text, attachments: other.attachments,
type: other.type, mentionedUsers: other.mentionedUsers,
attachments: other.attachments, reactionCounts: other.reactionCounts,
mentionedUsers: other.mentionedUsers, reactionScores: other.reactionScores,
reactionCounts: other.reactionCounts, latestReactions: other.latestReactions,
reactionScores: other.reactionScores, ownReactions: other.ownReactions,
latestReactions: other.latestReactions, parentId: other.parentId,
ownReactions: other.ownReactions, quotedMessage: other.quotedMessage,
parentId: other.parentId, quotedMessageId: other.quotedMessageId,
quotedMessage: other.quotedMessage, replyCount: other.replyCount,
quotedMessageId: other.quotedMessageId, threadParticipants: other.threadParticipants,
replyCount: other.replyCount, showInChannel: other.showInChannel,
threadParticipants: other.threadParticipants, command: other.command,
showInChannel: other.showInChannel, createdAt: other.createdAt,
command: other.command, silent: other.silent,
createdAt: other.createdAt, extraData: other.extraData,
silent: other.silent, user: other.user,
extraData: other.extraData, shadowed: other.shadowed,
user: other.user, updatedAt: other.updatedAt,
shadowed: other.shadowed, deletedAt: other.deletedAt,
updatedAt: other.updatedAt, status: other.status,
deletedAt: other.deletedAt, pinned: other.pinned,
status: other.status, pinnedAt: other.pinnedAt,
pinned: other.pinned, pinExpires: other.pinExpires,
pinnedAt: other.pinnedAt, pinnedBy: other.pinnedBy,
pinExpires: other.pinExpires, );
pinnedBy: other.pinnedBy,
);
}
@override @override
List<Object?> get props => [ List<Object?> get props => [
@@ -83,16 +83,13 @@ class Reaction {
/// Returns a new [Reaction] that is a combination of this reaction and the /// Returns a new [Reaction] that is a combination of this reaction and the
/// given [other] reaction. /// given [other] reaction.
Reaction merge(Reaction other) { Reaction merge(Reaction other) => copyWith(
if (other == null) return this; messageId: other.messageId,
return copyWith( createdAt: other.createdAt,
messageId: other.messageId, type: other.type,
createdAt: other.createdAt, user: other.user,
type: other.type, userId: other.userId,
user: other.user, score: other.score,
userId: other.userId, extraData: other.extraData,
score: other.score, );
extraData: other.extraData,
);
}
} }