diff --git a/packages/stream_chat/lib/src/api/channel.dart b/packages/stream_chat/lib/src/api/channel.dart index 3782b4b9..7421daa7 100644 --- a/packages/stream_chat/lib/src/api/channel.dart +++ b/packages/stream_chat/lib/src/api/channel.dart @@ -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 { [...messages!, ...threads!.values.expand((v) => v)] .where( (message) => - message.status != null && message.status != MessageSendingStatus.sent && message.createdAt!.isBefore( DateTime.now().subtract( diff --git a/packages/stream_chat/lib/src/client.dart b/packages/stream_chat/lib/src/client.dart index a6ec79d7..f6b9da79 100644 --- a/packages/stream_chat/lib/src/client.dart +++ b/packages/stream_chat/lib/src/client.dart @@ -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 = []; - 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? 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? 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; diff --git a/packages/stream_chat/lib/src/extensions/map_extension.dart b/packages/stream_chat/lib/src/extensions/map_extension.dart index af57a35a..8b1cb51f 100644 --- a/packages/stream_chat/lib/src/extensions/map_extension.dart +++ b/packages/stream_chat/lib/src/extensions/map_extension.dart @@ -1,6 +1,6 @@ /// Useful extension functions for [Map] extension MapX on Map { /// Returns a new map with null keys or values removed - Map get nullProtected => {...this as Map} + Map get nullProtected => {...this as Map} ..removeWhere((key, value) => key == null || value == null); } diff --git a/packages/stream_chat/lib/src/models/message.dart b/packages/stream_chat/lib/src/models/message.dart index 1fb51279..1849eb81 100644 --- a/packages/stream_chat/lib/src/models/message.dart +++ b/packages/stream_chat/lib/src/models/message.dart @@ -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 get props => [ diff --git a/packages/stream_chat/lib/src/models/reaction.dart b/packages/stream_chat/lib/src/models/reaction.dart index 42c23841..9f7b5851 100644 --- a/packages/stream_chat/lib/src/models/reaction.dart +++ b/packages/stream_chat/lib/src/models/reaction.dart @@ -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, + ); }