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