From 6b29630a644db6e7cecec771850901dc63320b62 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Fri, 2 Jun 2023 12:24:04 +0530 Subject: [PATCH 01/23] feat(llc, persistence): add support for open and close persistence via client. Signed-off-by: xsahil03x --- .../stream_chat/lib/src/client/channel.dart | 17 ++- .../stream_chat/lib/src/client/client.dart | 117 ++++++++++++------ .../lib/src/db/chat_persistence_client.dart | 5 + .../src/db/chat_persistence_client_test.dart | 3 + packages/stream_chat/test/src/mocks.dart | 9 +- .../src/stream_chat_persistence_client.dart | 3 + 6 files changed, 102 insertions(+), 52 deletions(-) diff --git a/packages/stream_chat/lib/src/client/channel.dart b/packages/stream_chat/lib/src/client/channel.dart index 3b249fcaa..54feb2ab0 100644 --- a/packages/stream_chat/lib/src/client/channel.dart +++ b/packages/stream_chat/lib/src/client/channel.dart @@ -1379,13 +1379,14 @@ class Channel { this.state?.updateChannelState(updatedState); return updatedState; } catch (e) { - if (!_client.persistenceEnabled) { - rethrow; + if (_client.persistenceEnabled) { + return _client.chatPersistenceClient!.getChannelStateByCid( + cid!, + messagePagination: messagesPagination, + ); } - return _client.chatPersistenceClient!.getChannelStateByCid( - cid!, - messagePagination: messagesPagination, - ); + + rethrow; } } @@ -1841,9 +1842,7 @@ class ChannelClientState { /// [isUpToDate] flag count as a stream. Stream get isUpToDateStream => _isUpToDateController.stream; - - final BehaviorSubject _isUpToDateController = - BehaviorSubject.seeded(true); + final _isUpToDateController = BehaviorSubject.seeded(true); /// The retry queue associated to this channel. late final RetryQueue _retryQueue; diff --git a/packages/stream_chat/lib/src/client/client.dart b/packages/stream_chat/lib/src/client/client.dart index 7627cf1df..54fefd579 100644 --- a/packages/stream_chat/lib/src/client/client.dart +++ b/packages/stream_chat/lib/src/client/client.dart @@ -125,10 +125,6 @@ class StreamChatClient { final _tokenManager = TokenManager(); final _connectionIdManager = ConnectionIdManager(); - set chatPersistenceClient(ChatPersistenceClient? value) { - _originalChatPersistenceClient = value; - } - /// Default user agent for all requests static String defaultUserAgent = 'stream-chat-dart-client-${CurrentPlatform.name}'; @@ -139,15 +135,15 @@ class StreamChatClient { /// The current package version static const packageVersion = PACKAGE_VERSION; - ChatPersistenceClient? _originalChatPersistenceClient; - /// Chat persistence client - ChatPersistenceClient? get chatPersistenceClient => _chatPersistenceClient; + ChatPersistenceClient? chatPersistenceClient; - ChatPersistenceClient? _chatPersistenceClient; - - /// Whether the chat persistence is available or not - bool get persistenceEnabled => _chatPersistenceClient != null; + /// Returns `True` if the [chatPersistenceClient] is available and connected. + /// Otherwise, returns `False`. + bool get persistenceEnabled { + final client = chatPersistenceClient; + return client != null && client.isConnected; + } late final RetryPolicy _retryPolicy; @@ -324,20 +320,27 @@ class StreamChatClient { final ownUser = OwnUser.fromUser(user); state.currentUser = ownUser; - if (!connectWebSocket) return ownUser; - try { - if (_originalChatPersistenceClient != null) { - _chatPersistenceClient = _originalChatPersistenceClient; - await _chatPersistenceClient!.connect(ownUser.id); + // Connect to persistence client if its set. + if (chatPersistenceClient != null) { + await openPersistenceConnection(ownUser); } - final connectedUser = await openConnection( - includeUserDetailsInConnectCall: true, - ); - return state.currentUser = connectedUser; + + // Connect to websocket if [connectWebSocket] is true. + // + // This is useful when you want to connect to websocket + // at a later stage or use the client in connection-less mode. + if (connectWebSocket) { + final connectedUser = await openConnection( + includeUserDetailsInConnectCall: true, + ); + state.currentUser = connectedUser; + } + + return state.currentUser!; } catch (e, stk) { if (e is StreamWebSocketError && e.isRetriable) { - final event = await _chatPersistenceClient?.getConnectionInfo(); + final event = await chatPersistenceClient?.getConnectionInfo(); if (event != null) return ownUser.merge(event.me); } logger.severe('error connecting user : ${ownUser.id}', e, stk); @@ -345,6 +348,40 @@ class StreamChatClient { } } + /// Connects the [chatPersistenceClient] to the given [user]. + Future openPersistenceConnection(User user) async { + final client = chatPersistenceClient; + if (client == null) { + throw const StreamChatError('Chat persistence client is not set'); + } + + if (client.isConnected) { + // If the persistence client is already connected to the userId, + // we don't need to connect again. + if (client.userId == user.id) return; + + throw const StreamChatError(''' + Chat persistence client is already connected to a different user, + please close the connection before connecting a new one.'''); + } + + // Connect the persistence client to the userId. + return client.connect(user.id); + } + + /// Disconnects the [chatPersistenceClient] from the current user. + Future closePersistenceConnection({bool flush = false}) async { + final client = chatPersistenceClient; + // If the persistence client is never connected, we don't need to close it. + if (client == null || !client.isConnected) { + logger.info('Chat persistence client is not connected'); + return; + } + + // Disconnect the persistence client. + return client.disconnect(flush: flush); + } + /// Creates a new WebSocket connection with the current user. /// If [includeUserDetailsInConnectCall] is true it will include the current /// user details in the connect call. @@ -422,7 +459,7 @@ class StreamChatClient { final connectionId = event.connectionId; if (connectionId != null) { _connectionIdManager.setConnectionId(connectionId); - _chatPersistenceClient?.updateConnectionInfo(event); + chatPersistenceClient?.updateConnectionInfo(event); } } @@ -460,9 +497,9 @@ class StreamChatClient { // channels are empty, assuming it's a fresh start // and making sure `lastSyncAt` is initialized if (persistenceEnabled) { - final lastSyncAt = await _chatPersistenceClient?.getLastSyncAt(); + final lastSyncAt = await chatPersistenceClient?.getLastSyncAt(); if (lastSyncAt == null) { - await _chatPersistenceClient?.updateLastSyncAt(DateTime.now()); + await chatPersistenceClient?.updateLastSyncAt(DateTime.now()); } } } @@ -493,13 +530,12 @@ class StreamChatClient { /// Will automatically fetch [cids] and [lastSyncedAt] if [persistenceEnabled] Future sync({List? cids, DateTime? lastSyncAt}) { return synchronized(() async { - final channels = cids ?? await _chatPersistenceClient?.getChannelCids(); + final channels = cids ?? await chatPersistenceClient?.getChannelCids(); if (channels == null || channels.isEmpty) { return; } - final syncAt = - lastSyncAt ?? await _chatPersistenceClient?.getLastSyncAt(); + final syncAt = lastSyncAt ?? await chatPersistenceClient?.getLastSyncAt(); if (syncAt == null) { return; } @@ -520,7 +556,7 @@ class StreamChatClient { final now = DateTime.now(); _lastSyncedAt = now; - _chatPersistenceClient?.updateLastSyncAt(now); + chatPersistenceClient?.updateLastSyncAt(now); } catch (e, stk) { logger.severe('Error during sync', e, stk); } @@ -679,7 +715,7 @@ class StreamChatClient { final updateData = _mapChannelStateToChannel(channels); - await _chatPersistenceClient?.updateChannelQueries( + await chatPersistenceClient?.updateChannelQueries( filter, channels.map((c) => c.channel!.cid).toList(), clearQueryCache: paginationParams.offset == 0, @@ -698,7 +734,7 @@ class StreamChatClient { List>? channelStateSort, PaginationParams paginationParams = const PaginationParams(), }) async { - final offlineChannels = (await _chatPersistenceClient?.getChannelStates( + final offlineChannels = (await chatPersistenceClient?.getChannelStates( filter: filter, // ignore: deprecated_member_use_from_same_package sort: sort, @@ -1362,7 +1398,7 @@ class StreamChatClient { final response = await _chatApi.message.deleteMessage(messageId, hard: hard); if (hard == true) { - await _chatPersistenceClient?.deleteMessageById(messageId); + await chatPersistenceClient?.deleteMessageById(messageId); } return response; } @@ -1468,34 +1504,33 @@ class StreamChatClient { Future disconnectUser({bool flushChatPersistence = false}) async { logger.info('Disconnecting user : ${state.currentUser?.id}'); - // resetting state + // resetting state. state.dispose(); state = ClientState(this); _lastSyncedAt = null; - // resetting credentials + // resetting credentials. _tokenManager.reset(); _connectionIdManager.reset(); - // disconnecting persistence client - await _chatPersistenceClient?.disconnect(flush: flushChatPersistence); - _chatPersistenceClient = null; + // closing persistence connection. + await closePersistenceConnection(flush: flushChatPersistence); // closing web-socket connection - closeConnection(); + return closeConnection(); } /// Call this function to dispose the client Future dispose() async { logger.info('Disposing new StreamChatClient'); - // disposing state + // disposing state. state.dispose(); - // disconnecting persistence client - await _chatPersistenceClient?.disconnect(); + // closing persistence connection. + await closePersistenceConnection(); - // closing web-socket connection + // closing web-socket connection. closeConnection(); await _eventController.close(); diff --git a/packages/stream_chat/lib/src/db/chat_persistence_client.dart b/packages/stream_chat/lib/src/db/chat_persistence_client.dart index 4710190e8..bf0b1a764 100644 --- a/packages/stream_chat/lib/src/db/chat_persistence_client.dart +++ b/packages/stream_chat/lib/src/db/chat_persistence_client.dart @@ -17,6 +17,11 @@ abstract class ChatPersistenceClient { /// Whether the connection is established. bool get isConnected; + /// The current user id to which the client is connected. + /// + /// Returns `null` if the client is not connected. + String? get userId; + /// Creates a new connection to the client Future connect(String userId); diff --git a/packages/stream_chat/test/src/db/chat_persistence_client_test.dart b/packages/stream_chat/test/src/db/chat_persistence_client_test.dart index 62a7cf25e..a0a129357 100644 --- a/packages/stream_chat/test/src/db/chat_persistence_client_test.dart +++ b/packages/stream_chat/test/src/db/chat_persistence_client_test.dart @@ -15,6 +15,9 @@ class TestPersistenceClient extends ChatPersistenceClient { @override bool get isConnected => throw UnimplementedError(); + @override + String? get userId => throw UnimplementedError(); + @override Future connect(String userId) => throw UnimplementedError(); diff --git a/packages/stream_chat/test/src/mocks.dart b/packages/stream_chat/test/src/mocks.dart index 440785198..86a77a666 100644 --- a/packages/stream_chat/test/src/mocks.dart +++ b/packages/stream_chat/test/src/mocks.dart @@ -64,11 +64,16 @@ class MockAttachmentFileUploader extends Mock implements AttachmentFileUploader {} class MockPersistenceClient extends Mock implements ChatPersistenceClient { + bool _isConnected = false; + + @override + bool get isConnected => _isConnected; + @override - Future connect(String userId) => Future.value(); + Future connect(String userId) async => _isConnected = true; @override - Future disconnect({bool flush = false}) => Future.value(); + Future disconnect({bool flush = false}) async => _isConnected = false; } class MockStreamChatClient extends Mock implements StreamChatClient { diff --git a/packages/stream_chat_persistence/lib/src/stream_chat_persistence_client.dart b/packages/stream_chat_persistence/lib/src/stream_chat_persistence_client.dart index 374bfa599..e8737baa0 100644 --- a/packages/stream_chat_persistence/lib/src/stream_chat_persistence_client.dart +++ b/packages/stream_chat_persistence/lib/src/stream_chat_persistence_client.dart @@ -82,6 +82,9 @@ class StreamChatPersistenceClient extends ChatPersistenceClient { @override bool get isConnected => db != null; + @override + String? get userId => db?.userId; + @override Future connect( String userId, { From 4ad042341be57a22d7922eec3c77a16ec45ce136 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Fri, 2 Jun 2023 12:26:52 +0530 Subject: [PATCH 02/23] chore: update CHANGELOG.md Signed-off-by: xsahil03x --- packages/stream_chat/CHANGELOG.md | 3 +++ packages/stream_chat_persistence/CHANGELOG.md | 2 ++ 2 files changed, 5 insertions(+) diff --git a/packages/stream_chat/CHANGELOG.md b/packages/stream_chat/CHANGELOG.md index 1989aea0f..5406b1fa8 100644 --- a/packages/stream_chat/CHANGELOG.md +++ b/packages/stream_chat/CHANGELOG.md @@ -8,6 +8,9 @@ ✅ Added - Added support for `ChatPersistenceClient.isConnected` for checking if the client is connected to the database. +- Added support for `ChatPersistenceClient.userId` for getting the current connected user id. +- Added two new methods `ChatPersistenceClient.disconnect` and `ChatPersistenceClient.connect` for disconnecting and + connecting to the database. ## 6.1.0 diff --git a/packages/stream_chat_persistence/CHANGELOG.md b/packages/stream_chat_persistence/CHANGELOG.md index 1295ba147..c2b608a3d 100644 --- a/packages/stream_chat_persistence/CHANGELOG.md +++ b/packages/stream_chat_persistence/CHANGELOG.md @@ -3,6 +3,8 @@ - Added support for `StreamChatPersistenceClient.isConnected` for checking if the client is connected to the database. - [[#1422]](https://github.com/GetStream/stream-chat-flutter/issues/1422) Removed default values from `UserEntity` `createdAt` and `updatedAt` fields. +- Added support for `StreamChatPersistenceClient.openPersistenceConnection` + and `StreamChatPersistenceClient.closePersistenceConnection` for opening and closing the database connection. ## 6.1.0 From 02c5d039d702eb7c0d75ed666787c4a9141e1a1f Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Fri, 2 Jun 2023 12:55:39 +0530 Subject: [PATCH 03/23] test: update test. Signed-off-by: xsahil03x --- .../test/stream_chat_persistence_client_test.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/stream_chat_persistence/test/stream_chat_persistence_client_test.dart b/packages/stream_chat_persistence/test/stream_chat_persistence_client_test.dart index 6791e07cc..0f3223a6e 100644 --- a/packages/stream_chat_persistence/test/stream_chat_persistence_client_test.dart +++ b/packages/stream_chat_persistence/test/stream_chat_persistence_client_test.dart @@ -20,7 +20,7 @@ void main() { await client.connect(userId, databaseProvider: testDatabaseProvider); expect(client.isConnected, true); expect(client.db, isA()); - expect(client.db!.userId, userId); + expect(client.userId, userId); addTearDown(() async { await client.disconnect(); @@ -33,7 +33,7 @@ void main() { await client.connect(userId, databaseProvider: testDatabaseProvider); expect(client.isConnected, true); expect(client.db, isA()); - expect(client.db!.userId, userId); + expect(client.userId, userId); expect( () => client.connect(userId, databaseProvider: testDatabaseProvider), throwsException, From 8978cb0035696b25583d6b27e195ea27caf06a35 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Mon, 5 Jun 2023 16:55:41 +0530 Subject: [PATCH 04/23] fix(llc): Remove cached channel once left. Signed-off-by: xsahil03x --- .../stream_chat/lib/src/client/client.dart | 22 ++++++++++++++++++- packages/stream_chat/lib/src/event_type.dart | 4 ++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/packages/stream_chat/lib/src/client/client.dart b/packages/stream_chat/lib/src/client/client.dart index 7627cf1df..d44750ed9 100644 --- a/packages/stream_chat/lib/src/client/client.dart +++ b/packages/stream_chat/lib/src/client/client.dart @@ -1541,6 +1541,8 @@ class ClientState { currentUser = currentUser?.copyWith(totalUnreadCount: count); })); + _listenChannelLeft(); + _listenChannelDeleted(); _listenChannelHidden(); @@ -1601,12 +1603,30 @@ class ClientState { ); } + void _listenChannelLeft() { + _eventsSubscription?.add( + _client + .on( + EventType.memberRemoved, + EventType.notificationRemovedFromChannel, + ) + .listen((event) async { + final isCurrentUser = event.user!.id == currentUser!.id; + if (isCurrentUser) { + final eventChannel = event.channel!; + await _client.chatPersistenceClient + ?.deleteChannels([eventChannel.cid]); + channels.remove(eventChannel.cid)?.dispose(); + } + }), + ); + } + void _listenChannelDeleted() { _eventsSubscription?.add( _client .on( EventType.channelDeleted, - EventType.notificationRemovedFromChannel, EventType.notificationChannelDeleted, ) .listen((Event event) async { diff --git a/packages/stream_chat/lib/src/event_type.dart b/packages/stream_chat/lib/src/event_type.dart index f8fb7ed7b..5bf6e0fd9 100644 --- a/packages/stream_chat/lib/src/event_type.dart +++ b/packages/stream_chat/lib/src/event_type.dart @@ -63,7 +63,7 @@ class EventType { static const String notificationAddedToChannel = 'notification.added_to_channel'; - /// Event sent when the user is removed to a channel + /// Event sent when the user is removed from a channel static const String notificationRemovedFromChannel = 'notification.removed_from_channel'; @@ -76,7 +76,7 @@ class EventType { /// Event sent when a member is added to a channel static const String memberAdded = 'member.added'; - /// Event sent when a member is removed to a channel + /// Event sent when a member is removed from a channel static const String memberRemoved = 'member.removed'; /// Event sent when a member is updated in a channel From b6f4c194e5209420b954add295ff38b20f9b1d60 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Mon, 5 Jun 2023 16:57:15 +0530 Subject: [PATCH 05/23] chore: update CHANGELOG.md Signed-off-by: xsahil03x --- packages/stream_chat/CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/stream_chat/CHANGELOG.md b/packages/stream_chat/CHANGELOG.md index b001d99e7..158a8722a 100644 --- a/packages/stream_chat/CHANGELOG.md +++ b/packages/stream_chat/CHANGELOG.md @@ -1,3 +1,10 @@ +## Upcoming + +🐞 Fixed + +- [[#1585]](https://github.com/GetStream/stream-chat-flutter/issues/1585) Fixed channels left not being removed from + the persistent storage. + ## 6.2.0 🐞 Fixed From dea56648514960bc889a31f966f31416ce7b2797 Mon Sep 17 00:00:00 2001 From: rlee1990 Date: Mon, 5 Jun 2023 13:18:29 -0400 Subject: [PATCH 06/23] Update Jiffy & Fixed --- .../lib/src/channel/channel_info.dart | 2 +- .../lib/src/channel/channel_preview.dart | 6 +++--- .../lib/src/localization/translations.dart | 6 +++--- .../message_list_view/message_list_view.dart | 18 +++++++++++------- .../lib/src/message_widget/bottom_row.dart | 2 +- .../lib/src/misc/date_divider.dart | 12 ++++++------ .../stream_channel_list_tile.dart | 6 +++--- .../stream_message_search_list_tile.dart | 4 ++-- .../stream_user_list_tile.dart | 2 +- .../lib/src/stream_chat.dart | 4 ++-- .../lib/src/user/user_item.dart | 2 +- .../lib/svgs/video_call_icon.svg | 3 +++ packages/stream_chat_flutter/pubspec.yaml | 2 +- 13 files changed, 38 insertions(+), 31 deletions(-) create mode 100644 packages/stream_chat_flutter/lib/svgs/video_call_icon.svg diff --git a/packages/stream_chat_flutter/lib/src/channel/channel_info.dart b/packages/stream_chat_flutter/lib/src/channel/channel_info.dart index 5c32d2789..b59236005 100644 --- a/packages/stream_chat_flutter/lib/src/channel/channel_info.dart +++ b/packages/stream_chat_flutter/lib/src/channel/channel_info.dart @@ -108,7 +108,7 @@ class _ConnectedTitleState extends StatelessWidget { } else { alternativeWidget = Text( '${context.translations.userLastOnlineText} ' - '${Jiffy(otherMember.user?.lastActive).fromNow()}', + '${Jiffy.parseFromDateTime(otherMember.user!.lastActive!).fromNow()}', style: textStyle, ); } diff --git a/packages/stream_chat_flutter/lib/src/channel/channel_preview.dart b/packages/stream_chat_flutter/lib/src/channel/channel_preview.dart index ae6247ea2..f64b9dc95 100644 --- a/packages/stream_chat_flutter/lib/src/channel/channel_preview.dart +++ b/packages/stream_chat_flutter/lib/src/channel/channel_preview.dart @@ -349,16 +349,16 @@ class _Date extends StatelessWidget { if (lastMessageAt.millisecondsSinceEpoch >= startOfDay.millisecondsSinceEpoch) { - stringDate = Jiffy(lastMessageAt.toLocal()).jm; + stringDate = Jiffy.parseFromDateTime(lastMessageAt.toLocal()).jm; } else if (lastMessageAt.millisecondsSinceEpoch >= startOfDay .subtract(const Duration(days: 1)) .millisecondsSinceEpoch) { stringDate = context.translations.yesterdayLabel; } else if (startOfDay.difference(lastMessageAt).inDays < 7) { - stringDate = Jiffy(lastMessageAt.toLocal()).EEEE; + stringDate = Jiffy.parseFromDateTime(lastMessageAt.toLocal()).EEEE; } else { - stringDate = Jiffy(lastMessageAt.toLocal()).yMd; + stringDate = Jiffy.parseFromDateTime(lastMessageAt.toLocal()).yMd; } return Text( diff --git a/packages/stream_chat_flutter/lib/src/localization/translations.dart b/packages/stream_chat_flutter/lib/src/localization/translations.dart index 71254e734..b213cc0ae 100644 --- a/packages/stream_chat_flutter/lib/src/localization/translations.dart +++ b/packages/stream_chat_flutter/lib/src/localization/translations.dart @@ -83,7 +83,7 @@ abstract class Translations { /// in the [StreamMessageListView] String unreadMessagesSeparatorText( @Deprecated('unreadCount is not used anymore and will be removed ') - int unreadCount, + int unreadCount, ); /// The label for "connected" in [StreamConnectionStatusBuilder] @@ -611,13 +611,13 @@ class DefaultTranslations implements Translations { } else if (date == yesterday) { return 'yesterday'; } else { - return 'on ${Jiffy(date).MMMd}'; + return 'on ${Jiffy.parseFromDateTime(date).MMMd}'; } } @override String sentAtText({required DateTime date, required DateTime time}) => - 'Sent ${_getDay(date)} at ${Jiffy(time.toLocal()).format('HH:mm')}'; + 'Sent ${_getDay(date)} at ${Jiffy.parseFromDateTime(time.toLocal()).format(pattern: 'HH:mm')}'; @override String get todayLabel => 'Today'; diff --git a/packages/stream_chat_flutter/lib/src/message_list_view/message_list_view.dart b/packages/stream_chat_flutter/lib/src/message_list_view/message_list_view.dart index 4c29eb691..b175f01ca 100644 --- a/packages/stream_chat_flutter/lib/src/message_list_view/message_list_view.dart +++ b/packages/stream_chat_flutter/lib/src/message_list_view/message_list_view.dart @@ -666,12 +666,15 @@ class _StreamMessageListViewState extends State { final createdAt = message.createdAt.toLocal(); final nextCreatedAt = nextMessage.createdAt.toLocal(); - if (!Jiffy(createdAt).isSame(nextCreatedAt, Units.DAY)) { + if (!Jiffy.parseFromDateTime(createdAt).isSame( + Jiffy.parseFromDateTime(nextCreatedAt), + unit: Unit.day)) { separator = _buildDateDivider(nextMessage); } else { - final hasTimeDiff = !Jiffy(createdAt).isSame( - nextCreatedAt, - Units.MINUTE, + final hasTimeDiff = + !Jiffy.parseFromDateTime(createdAt).isSame( + Jiffy.parseFromDateTime(nextCreatedAt), + unit: Unit.minute, ); final isNextUserSame = @@ -1061,9 +1064,10 @@ class _StreamMessageListViewState extends State { var hasTimeDiff = false; if (nextMessage != null) { - hasTimeDiff = !Jiffy(message.createdAt.toLocal()).isSame( - nextMessage.createdAt.toLocal(), - Units.MINUTE, + hasTimeDiff = + !Jiffy.parseFromDateTime(message.createdAt.toLocal()).isSame( + Jiffy.parseFromDateTime(nextMessage.createdAt.toLocal()), + unit: Unit.minute, ); } diff --git a/packages/stream_chat_flutter/lib/src/message_widget/bottom_row.dart b/packages/stream_chat_flutter/lib/src/message_widget/bottom_row.dart index 5ca2462a5..7092dadf5 100644 --- a/packages/stream_chat_flutter/lib/src/message_widget/bottom_row.dart +++ b/packages/stream_chat_flutter/lib/src/message_widget/bottom_row.dart @@ -191,7 +191,7 @@ class BottomRow extends StatelessWidget { ), if (showTimeStamp) Text( - Jiffy(message.createdAt.toLocal()).jm, + Jiffy.parseFromDateTime(message.createdAt.toLocal()).jm, style: messageTheme.createdAtStyle, ), if (showSendingIndicator) diff --git a/packages/stream_chat_flutter/lib/src/misc/date_divider.dart b/packages/stream_chat_flutter/lib/src/misc/date_divider.dart index 24af4f3f2..24c0c9a73 100644 --- a/packages/stream_chat_flutter/lib/src/misc/date_divider.dart +++ b/packages/stream_chat_flutter/lib/src/misc/date_divider.dart @@ -20,17 +20,17 @@ class StreamDateDivider extends StatelessWidget { @override Widget build(BuildContext context) { - final createdAt = Jiffy(dateTime); - final now = Jiffy(DateTime.now()); + final createdAt = Jiffy.parseFromDateTime(dateTime); + final now = Jiffy.parseFromDateTime(DateTime.now()); var dayInfo = createdAt.MMMd; - if (createdAt.isSame(now, Units.DAY)) { + if (createdAt.isSame(now, unit: Unit.day)) { dayInfo = context.translations.todayLabel; - } else if (createdAt.isSame(now.subtract(days: 1), Units.DAY)) { + } else if (createdAt.isSame(now.subtract(days: 1), unit: Unit.day)) { dayInfo = context.translations.yesterdayLabel; - } else if (createdAt.isAfter(now.subtract(days: 7), Units.DAY)) { + } else if (createdAt.isAfter(now.subtract(days: 7), unit: Unit.day)) { dayInfo = createdAt.EEEE; - } else if (createdAt.isAfter(now.subtract(years: 1), Units.DAY)) { + } else if (createdAt.isAfter(now.subtract(years: 1), unit: Unit.day)) { dayInfo = createdAt.MMMd; } diff --git a/packages/stream_chat_flutter/lib/src/scroll_view/channel_scroll_view/stream_channel_list_tile.dart b/packages/stream_chat_flutter/lib/src/scroll_view/channel_scroll_view/stream_channel_list_tile.dart index 6b2a9b4fe..b5261802d 100644 --- a/packages/stream_chat_flutter/lib/src/scroll_view/channel_scroll_view/stream_channel_list_tile.dart +++ b/packages/stream_chat_flutter/lib/src/scroll_view/channel_scroll_view/stream_channel_list_tile.dart @@ -287,16 +287,16 @@ class ChannelLastMessageDate extends StatelessWidget { if (lastMessageAt.millisecondsSinceEpoch >= startOfDay.millisecondsSinceEpoch) { - stringDate = Jiffy(lastMessageAt.toLocal()).jm; + stringDate = Jiffy.parseFromDateTime(lastMessageAt.toLocal()).jm; } else if (lastMessageAt.millisecondsSinceEpoch >= startOfDay .subtract(const Duration(days: 1)) .millisecondsSinceEpoch) { stringDate = context.translations.yesterdayLabel; } else if (startOfDay.difference(lastMessageAt).inDays < 7) { - stringDate = Jiffy(lastMessageAt.toLocal()).EEEE; + stringDate = Jiffy.parseFromDateTime(lastMessageAt.toLocal()).EEEE; } else { - stringDate = Jiffy(lastMessageAt.toLocal()).yMd; + stringDate = Jiffy.parseFromDateTime(lastMessageAt.toLocal()).yMd; } return Text( diff --git a/packages/stream_chat_flutter/lib/src/scroll_view/message_search_scroll_view/stream_message_search_list_tile.dart b/packages/stream_chat_flutter/lib/src/scroll_view/message_search_scroll_view/stream_message_search_list_tile.dart index 5aab3b2d4..3eb03aec1 100644 --- a/packages/stream_chat_flutter/lib/src/scroll_view/message_search_scroll_view/stream_message_search_list_tile.dart +++ b/packages/stream_chat_flutter/lib/src/scroll_view/message_search_scroll_view/stream_message_search_list_tile.dart @@ -227,9 +227,9 @@ class MessageSearchTileMessageDate extends StatelessWidget { if (now.year != createdAt.year || now.month != createdAt.month || now.day != createdAt.day) { - stringDate = Jiffy(createdAt.toLocal()).yMd; + stringDate = Jiffy.parseFromDateTime(createdAt.toLocal()).yMd; } else { - stringDate = Jiffy(createdAt.toLocal()).jm; + stringDate = Jiffy.parseFromDateTime(createdAt.toLocal()).jm; } return Text( diff --git a/packages/stream_chat_flutter/lib/src/scroll_view/user_scroll_view/stream_user_list_tile.dart b/packages/stream_chat_flutter/lib/src/scroll_view/user_scroll_view/stream_user_list_tile.dart index dbb0f6a5f..57f21a3cb 100644 --- a/packages/stream_chat_flutter/lib/src/scroll_view/user_scroll_view/stream_user_list_tile.dart +++ b/packages/stream_chat_flutter/lib/src/scroll_view/user_scroll_view/stream_user_list_tile.dart @@ -179,7 +179,7 @@ class UserLastActive extends StatelessWidget { user.online ? context.translations.userOnlineText : '${context.translations.userLastOnlineText} ' - '${Jiffy(user.lastActive).fromNow()}', + '${Jiffy.parseFromDateTime(user.lastActive!).fromNow()}', style: chatTheme.textTheme.footnote.copyWith( color: chatTheme.colorTheme.textHighEmphasis.withOpacity(0.5), ), diff --git a/packages/stream_chat_flutter/lib/src/stream_chat.dart b/packages/stream_chat_flutter/lib/src/stream_chat.dart index 73a0d0a0a..6b0d0e609 100644 --- a/packages/stream_chat_flutter/lib/src/stream_chat.dart +++ b/packages/stream_chat_flutter/lib/src/stream_chat.dart @@ -165,9 +165,9 @@ class StreamChatState extends State { @override void didChangeDependencies() { final currentLocale = Localizations.localeOf(context).toString(); - final availableLocales = Jiffy.getAllAvailableLocales(); + final availableLocales = Jiffy.getSupportedLocales(); if (availableLocales.contains(currentLocale)) { - Jiffy.locale(currentLocale); + Jiffy.setLocale(currentLocale); } super.didChangeDependencies(); } diff --git a/packages/stream_chat_flutter/lib/src/user/user_item.dart b/packages/stream_chat_flutter/lib/src/user/user_item.dart index 85d12a997..dcd18bcb1 100644 --- a/packages/stream_chat_flutter/lib/src/user/user_item.dart +++ b/packages/stream_chat_flutter/lib/src/user/user_item.dart @@ -77,7 +77,7 @@ class StreamUserItem extends StatelessWidget { user.online ? context.translations.userOnlineText : '${context.translations.userLastOnlineText} ' - '${Jiffy(user.lastActive).fromNow()}', + '${Jiffy.parseFromDateTime(user.lastActive!).fromNow()}', style: chatTheme.textTheme.footnote.copyWith( color: chatTheme.colorTheme.textHighEmphasis.withOpacity(0.5), ), diff --git a/packages/stream_chat_flutter/lib/svgs/video_call_icon.svg b/packages/stream_chat_flutter/lib/svgs/video_call_icon.svg new file mode 100644 index 000000000..1c3832d67 --- /dev/null +++ b/packages/stream_chat_flutter/lib/svgs/video_call_icon.svg @@ -0,0 +1,3 @@ + + + diff --git a/packages/stream_chat_flutter/pubspec.yaml b/packages/stream_chat_flutter/pubspec.yaml index c360f1ec5..743e4366d 100644 --- a/packages/stream_chat_flutter/pubspec.yaml +++ b/packages/stream_chat_flutter/pubspec.yaml @@ -29,7 +29,7 @@ dependencies: http_parser: ^4.0.0 image_gallery_saver: ^2.0.1 image_picker: ^0.8.2 - jiffy: ^5.0.0 + jiffy: ^6.2.1 lottie: ^2.0.0 meta: ^1.8.0 path_provider: ^2.0.9 From 4dcc747f943adf063db7909dcb9a2058ac21d727 Mon Sep 17 00:00:00 2001 From: rlee1990 Date: Mon, 5 Jun 2023 15:46:17 -0400 Subject: [PATCH 07/23] Removed Jiffy update --- .../lib/src/channel/channel_info.dart | 2 +- .../lib/src/channel/channel_preview.dart | 6 +++--- .../lib/src/localization/translations.dart | 4 ++-- .../message_list_view/message_list_view.dart | 19 ++++++++----------- .../lib/src/message_widget/bottom_row.dart | 2 +- .../lib/src/misc/date_divider.dart | 12 ++++++------ .../stream_channel_list_tile.dart | 6 +++--- .../stream_message_search_list_tile.dart | 4 ++-- .../stream_user_list_tile.dart | 2 +- .../lib/src/stream_chat.dart | 4 ++-- .../lib/src/user/user_item.dart | 2 +- packages/stream_chat_flutter/pubspec.yaml | 2 +- 12 files changed, 31 insertions(+), 34 deletions(-) diff --git a/packages/stream_chat_flutter/lib/src/channel/channel_info.dart b/packages/stream_chat_flutter/lib/src/channel/channel_info.dart index b59236005..264908a87 100644 --- a/packages/stream_chat_flutter/lib/src/channel/channel_info.dart +++ b/packages/stream_chat_flutter/lib/src/channel/channel_info.dart @@ -108,7 +108,7 @@ class _ConnectedTitleState extends StatelessWidget { } else { alternativeWidget = Text( '${context.translations.userLastOnlineText} ' - '${Jiffy.parseFromDateTime(otherMember.user!.lastActive!).fromNow()}', + '${Jiffy(otherMember.user!.lastActive!).fromNow()}', style: textStyle, ); } diff --git a/packages/stream_chat_flutter/lib/src/channel/channel_preview.dart b/packages/stream_chat_flutter/lib/src/channel/channel_preview.dart index f64b9dc95..ae6247ea2 100644 --- a/packages/stream_chat_flutter/lib/src/channel/channel_preview.dart +++ b/packages/stream_chat_flutter/lib/src/channel/channel_preview.dart @@ -349,16 +349,16 @@ class _Date extends StatelessWidget { if (lastMessageAt.millisecondsSinceEpoch >= startOfDay.millisecondsSinceEpoch) { - stringDate = Jiffy.parseFromDateTime(lastMessageAt.toLocal()).jm; + stringDate = Jiffy(lastMessageAt.toLocal()).jm; } else if (lastMessageAt.millisecondsSinceEpoch >= startOfDay .subtract(const Duration(days: 1)) .millisecondsSinceEpoch) { stringDate = context.translations.yesterdayLabel; } else if (startOfDay.difference(lastMessageAt).inDays < 7) { - stringDate = Jiffy.parseFromDateTime(lastMessageAt.toLocal()).EEEE; + stringDate = Jiffy(lastMessageAt.toLocal()).EEEE; } else { - stringDate = Jiffy.parseFromDateTime(lastMessageAt.toLocal()).yMd; + stringDate = Jiffy(lastMessageAt.toLocal()).yMd; } return Text( diff --git a/packages/stream_chat_flutter/lib/src/localization/translations.dart b/packages/stream_chat_flutter/lib/src/localization/translations.dart index b213cc0ae..61c3441a2 100644 --- a/packages/stream_chat_flutter/lib/src/localization/translations.dart +++ b/packages/stream_chat_flutter/lib/src/localization/translations.dart @@ -611,13 +611,13 @@ class DefaultTranslations implements Translations { } else if (date == yesterday) { return 'yesterday'; } else { - return 'on ${Jiffy.parseFromDateTime(date).MMMd}'; + return 'on ${Jiffy(date).MMMd}'; } } @override String sentAtText({required DateTime date, required DateTime time}) => - 'Sent ${_getDay(date)} at ${Jiffy.parseFromDateTime(time.toLocal()).format(pattern: 'HH:mm')}'; + 'Sent ${_getDay(date)} at ${Jiffy(time.toLocal()).format('HH:mm')}'; @override String get todayLabel => 'Today'; diff --git a/packages/stream_chat_flutter/lib/src/message_list_view/message_list_view.dart b/packages/stream_chat_flutter/lib/src/message_list_view/message_list_view.dart index b175f01ca..76d552854 100644 --- a/packages/stream_chat_flutter/lib/src/message_list_view/message_list_view.dart +++ b/packages/stream_chat_flutter/lib/src/message_list_view/message_list_view.dart @@ -666,15 +666,13 @@ class _StreamMessageListViewState extends State { final createdAt = message.createdAt.toLocal(); final nextCreatedAt = nextMessage.createdAt.toLocal(); - if (!Jiffy.parseFromDateTime(createdAt).isSame( - Jiffy.parseFromDateTime(nextCreatedAt), - unit: Unit.day)) { + if (!Jiffy(createdAt) + .isSame(Jiffy(nextCreatedAt), Units.DAY)) { separator = _buildDateDivider(nextMessage); } else { - final hasTimeDiff = - !Jiffy.parseFromDateTime(createdAt).isSame( - Jiffy.parseFromDateTime(nextCreatedAt), - unit: Unit.minute, + final hasTimeDiff = !Jiffy(createdAt).isSame( + Jiffy(nextCreatedAt), + Units.MINUTE, ); final isNextUserSame = @@ -1064,10 +1062,9 @@ class _StreamMessageListViewState extends State { var hasTimeDiff = false; if (nextMessage != null) { - hasTimeDiff = - !Jiffy.parseFromDateTime(message.createdAt.toLocal()).isSame( - Jiffy.parseFromDateTime(nextMessage.createdAt.toLocal()), - unit: Unit.minute, + hasTimeDiff = !Jiffy(message.createdAt.toLocal()).isSame( + Jiffy(nextMessage.createdAt.toLocal()), + Units.MINUTE, ); } diff --git a/packages/stream_chat_flutter/lib/src/message_widget/bottom_row.dart b/packages/stream_chat_flutter/lib/src/message_widget/bottom_row.dart index 7092dadf5..5ca2462a5 100644 --- a/packages/stream_chat_flutter/lib/src/message_widget/bottom_row.dart +++ b/packages/stream_chat_flutter/lib/src/message_widget/bottom_row.dart @@ -191,7 +191,7 @@ class BottomRow extends StatelessWidget { ), if (showTimeStamp) Text( - Jiffy.parseFromDateTime(message.createdAt.toLocal()).jm, + Jiffy(message.createdAt.toLocal()).jm, style: messageTheme.createdAtStyle, ), if (showSendingIndicator) diff --git a/packages/stream_chat_flutter/lib/src/misc/date_divider.dart b/packages/stream_chat_flutter/lib/src/misc/date_divider.dart index 24c0c9a73..24af4f3f2 100644 --- a/packages/stream_chat_flutter/lib/src/misc/date_divider.dart +++ b/packages/stream_chat_flutter/lib/src/misc/date_divider.dart @@ -20,17 +20,17 @@ class StreamDateDivider extends StatelessWidget { @override Widget build(BuildContext context) { - final createdAt = Jiffy.parseFromDateTime(dateTime); - final now = Jiffy.parseFromDateTime(DateTime.now()); + final createdAt = Jiffy(dateTime); + final now = Jiffy(DateTime.now()); var dayInfo = createdAt.MMMd; - if (createdAt.isSame(now, unit: Unit.day)) { + if (createdAt.isSame(now, Units.DAY)) { dayInfo = context.translations.todayLabel; - } else if (createdAt.isSame(now.subtract(days: 1), unit: Unit.day)) { + } else if (createdAt.isSame(now.subtract(days: 1), Units.DAY)) { dayInfo = context.translations.yesterdayLabel; - } else if (createdAt.isAfter(now.subtract(days: 7), unit: Unit.day)) { + } else if (createdAt.isAfter(now.subtract(days: 7), Units.DAY)) { dayInfo = createdAt.EEEE; - } else if (createdAt.isAfter(now.subtract(years: 1), unit: Unit.day)) { + } else if (createdAt.isAfter(now.subtract(years: 1), Units.DAY)) { dayInfo = createdAt.MMMd; } diff --git a/packages/stream_chat_flutter/lib/src/scroll_view/channel_scroll_view/stream_channel_list_tile.dart b/packages/stream_chat_flutter/lib/src/scroll_view/channel_scroll_view/stream_channel_list_tile.dart index b5261802d..6b2a9b4fe 100644 --- a/packages/stream_chat_flutter/lib/src/scroll_view/channel_scroll_view/stream_channel_list_tile.dart +++ b/packages/stream_chat_flutter/lib/src/scroll_view/channel_scroll_view/stream_channel_list_tile.dart @@ -287,16 +287,16 @@ class ChannelLastMessageDate extends StatelessWidget { if (lastMessageAt.millisecondsSinceEpoch >= startOfDay.millisecondsSinceEpoch) { - stringDate = Jiffy.parseFromDateTime(lastMessageAt.toLocal()).jm; + stringDate = Jiffy(lastMessageAt.toLocal()).jm; } else if (lastMessageAt.millisecondsSinceEpoch >= startOfDay .subtract(const Duration(days: 1)) .millisecondsSinceEpoch) { stringDate = context.translations.yesterdayLabel; } else if (startOfDay.difference(lastMessageAt).inDays < 7) { - stringDate = Jiffy.parseFromDateTime(lastMessageAt.toLocal()).EEEE; + stringDate = Jiffy(lastMessageAt.toLocal()).EEEE; } else { - stringDate = Jiffy.parseFromDateTime(lastMessageAt.toLocal()).yMd; + stringDate = Jiffy(lastMessageAt.toLocal()).yMd; } return Text( diff --git a/packages/stream_chat_flutter/lib/src/scroll_view/message_search_scroll_view/stream_message_search_list_tile.dart b/packages/stream_chat_flutter/lib/src/scroll_view/message_search_scroll_view/stream_message_search_list_tile.dart index 3eb03aec1..5aab3b2d4 100644 --- a/packages/stream_chat_flutter/lib/src/scroll_view/message_search_scroll_view/stream_message_search_list_tile.dart +++ b/packages/stream_chat_flutter/lib/src/scroll_view/message_search_scroll_view/stream_message_search_list_tile.dart @@ -227,9 +227,9 @@ class MessageSearchTileMessageDate extends StatelessWidget { if (now.year != createdAt.year || now.month != createdAt.month || now.day != createdAt.day) { - stringDate = Jiffy.parseFromDateTime(createdAt.toLocal()).yMd; + stringDate = Jiffy(createdAt.toLocal()).yMd; } else { - stringDate = Jiffy.parseFromDateTime(createdAt.toLocal()).jm; + stringDate = Jiffy(createdAt.toLocal()).jm; } return Text( diff --git a/packages/stream_chat_flutter/lib/src/scroll_view/user_scroll_view/stream_user_list_tile.dart b/packages/stream_chat_flutter/lib/src/scroll_view/user_scroll_view/stream_user_list_tile.dart index 57f21a3cb..00e7339a6 100644 --- a/packages/stream_chat_flutter/lib/src/scroll_view/user_scroll_view/stream_user_list_tile.dart +++ b/packages/stream_chat_flutter/lib/src/scroll_view/user_scroll_view/stream_user_list_tile.dart @@ -179,7 +179,7 @@ class UserLastActive extends StatelessWidget { user.online ? context.translations.userOnlineText : '${context.translations.userLastOnlineText} ' - '${Jiffy.parseFromDateTime(user.lastActive!).fromNow()}', + '${Jiffy(user.lastActive!).fromNow()}', style: chatTheme.textTheme.footnote.copyWith( color: chatTheme.colorTheme.textHighEmphasis.withOpacity(0.5), ), diff --git a/packages/stream_chat_flutter/lib/src/stream_chat.dart b/packages/stream_chat_flutter/lib/src/stream_chat.dart index 6b0d0e609..73a0d0a0a 100644 --- a/packages/stream_chat_flutter/lib/src/stream_chat.dart +++ b/packages/stream_chat_flutter/lib/src/stream_chat.dart @@ -165,9 +165,9 @@ class StreamChatState extends State { @override void didChangeDependencies() { final currentLocale = Localizations.localeOf(context).toString(); - final availableLocales = Jiffy.getSupportedLocales(); + final availableLocales = Jiffy.getAllAvailableLocales(); if (availableLocales.contains(currentLocale)) { - Jiffy.setLocale(currentLocale); + Jiffy.locale(currentLocale); } super.didChangeDependencies(); } diff --git a/packages/stream_chat_flutter/lib/src/user/user_item.dart b/packages/stream_chat_flutter/lib/src/user/user_item.dart index dcd18bcb1..0d3b811a0 100644 --- a/packages/stream_chat_flutter/lib/src/user/user_item.dart +++ b/packages/stream_chat_flutter/lib/src/user/user_item.dart @@ -77,7 +77,7 @@ class StreamUserItem extends StatelessWidget { user.online ? context.translations.userOnlineText : '${context.translations.userLastOnlineText} ' - '${Jiffy.parseFromDateTime(user.lastActive!).fromNow()}', + '${Jiffy(user.lastActive!).fromNow()}', style: chatTheme.textTheme.footnote.copyWith( color: chatTheme.colorTheme.textHighEmphasis.withOpacity(0.5), ), diff --git a/packages/stream_chat_flutter/pubspec.yaml b/packages/stream_chat_flutter/pubspec.yaml index 743e4366d..c360f1ec5 100644 --- a/packages/stream_chat_flutter/pubspec.yaml +++ b/packages/stream_chat_flutter/pubspec.yaml @@ -29,7 +29,7 @@ dependencies: http_parser: ^4.0.0 image_gallery_saver: ^2.0.1 image_picker: ^0.8.2 - jiffy: ^6.2.1 + jiffy: ^5.0.0 lottie: ^2.0.0 meta: ^1.8.0 path_provider: ^2.0.9 From 7ef9dea72b43e3e8c39c463947279d0f1026638e Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Tue, 6 Jun 2023 15:17:06 +0530 Subject: [PATCH 08/23] chore(llc, core, ui): bump dio to ^5.2.0. Signed-off-by: xsahil03x --- .../lib/src/core/error/stream_chat_error.dart | 15 ++++++++---- .../http/interceptor/auth_interceptor.dart | 16 ++++++------- .../http/interceptor/logging_interceptor.dart | 22 ++++++++--------- .../src/core/http/stream_chat_dio_error.dart | 2 +- .../lib/src/core/http/stream_http_client.dart | 24 +++++++++---------- packages/stream_chat/lib/stream_chat.dart | 18 ++++++++------ packages/stream_chat/pubspec.yaml | 2 +- .../core/error/stream_chat_error_test.dart | 6 ++--- .../interceptor/auth_interceptor_test.dart | 16 ++++++------- .../core/http/stream_chat_dio_error_test.dart | 2 +- .../core/http/stream_http_client_test.dart | 18 +++++++------- packages/stream_chat_flutter/pubspec.yaml | 2 +- .../lib/src/stream_channel.dart | 15 ++++++------ .../test/stream_channel_test.dart | 4 ++-- 14 files changed, 85 insertions(+), 77 deletions(-) diff --git a/packages/stream_chat/lib/src/core/error/stream_chat_error.dart b/packages/stream_chat/lib/src/core/error/stream_chat_error.dart index 1df285582..333211f28 100644 --- a/packages/stream_chat/lib/src/core/error/stream_chat_error.dart +++ b/packages/stream_chat/lib/src/core/error/stream_chat_error.dart @@ -89,8 +89,13 @@ class StreamChatNetworkError extends StreamChatError { }) : super(message); /// - factory StreamChatNetworkError.fromDioError(DioError error) { - final response = error.response; + @Deprecated('Use `StreamChatNetworkError.fromDioException` instead') + factory StreamChatNetworkError.fromDioError(DioException error) = + StreamChatNetworkError.fromDioException; + + /// + factory StreamChatNetworkError.fromDioException(DioException exception) { + final response = exception.response; ErrorResponse? errorResponse; final data = response?.data; if (data != null) { @@ -100,12 +105,12 @@ class StreamChatNetworkError extends StreamChatError { code: errorResponse?.code ?? -1, message: errorResponse?.message ?? response?.statusMessage ?? - error.message ?? + exception.message ?? '', statusCode: errorResponse?.statusCode ?? response?.statusCode, data: errorResponse, - isRequestCancelledError: error.type == DioErrorType.cancel, - )..stackTrace = error.stackTrace; + isRequestCancelledError: exception.type == DioExceptionType.cancel, + )..stackTrace = exception.stackTrace; } /// Error code diff --git a/packages/stream_chat/lib/src/core/http/interceptor/auth_interceptor.dart b/packages/stream_chat/lib/src/core/http/interceptor/auth_interceptor.dart index 759e8e791..7bd9a9575 100644 --- a/packages/stream_chat/lib/src/core/http/interceptor/auth_interceptor.dart +++ b/packages/stream_chat/lib/src/core/http/interceptor/auth_interceptor.dart @@ -46,26 +46,26 @@ class AuthInterceptor extends QueuedInterceptor { @override void onError( - DioError err, + DioException exception, ErrorInterceptorHandler handler, ) async { - final data = err.response?.data; + final data = exception.response?.data; if (data == null || data is! Map) { - return handler.next(err); + return handler.next(exception); } final error = ErrorResponse.fromJson(data); if (error.code == ChatErrorCode.tokenExpired.code) { - if (_tokenManager.isStatic) return handler.next(err); + if (_tokenManager.isStatic) return handler.next(exception); await _tokenManager.loadToken(refresh: true); try { - final options = err.requestOptions; + final options = exception.requestOptions; final response = await _client.fetch(options); return handler.resolve(response); - } on DioError catch (error) { - return handler.next(error); + } on DioException catch (exception) { + return handler.next(exception); } } - return handler.next(err); + return handler.next(exception); } } diff --git a/packages/stream_chat/lib/src/core/http/interceptor/logging_interceptor.dart b/packages/stream_chat/lib/src/core/http/interceptor/logging_interceptor.dart index 72fd70d03..6d6f74c30 100644 --- a/packages/stream_chat/lib/src/core/http/interceptor/logging_interceptor.dart +++ b/packages/stream_chat/lib/src/core/http/interceptor/logging_interceptor.dart @@ -119,32 +119,32 @@ class LoggingInterceptor extends Interceptor { } @override - void onError(DioError err, ErrorInterceptorHandler handler) { + void onError(DioException exception, ErrorInterceptorHandler handler) { if (error) { - if (err.type == DioErrorType.badResponse) { - final uri = err.response?.requestOptions.uri; + if (exception.type == DioExceptionType.badResponse) { + final uri = exception.response?.requestOptions.uri; _printBoxed( _logPrintError, header: - 'DioError ║ Status: ${err.response?.statusCode} ${err.response?.statusMessage}', + 'DioException ║ Status: ${exception.response?.statusCode} ${exception.response?.statusMessage}', text: uri.toString(), ); - if (err.response != null && err.response?.data != null) { - _logPrintError('╔ ${err.type.toString()}'); - _printResponse(_logPrintError, err.response!); + if (exception.response != null && exception.response?.data != null) { + _logPrintError('╔ ${exception.type.toString()}'); + _printResponse(_logPrintError, exception.response!); } _printLine(_logPrintError, '╚'); _logPrintError(''); } else { _printBoxed( _logPrintError, - header: 'DioError ║ ${err.type}', - text: err.message, + header: 'DioException ║ ${exception.type}', + text: exception.message, ); - _printRequestHeader(_logPrintError, err.requestOptions); + _printRequestHeader(_logPrintError, exception.requestOptions); } } - super.onError(err, handler); + super.onError(exception, handler); } @override diff --git a/packages/stream_chat/lib/src/core/http/stream_chat_dio_error.dart b/packages/stream_chat/lib/src/core/http/stream_chat_dio_error.dart index b494671c2..5b6f91a07 100644 --- a/packages/stream_chat/lib/src/core/http/stream_chat_dio_error.dart +++ b/packages/stream_chat/lib/src/core/http/stream_chat_dio_error.dart @@ -2,7 +2,7 @@ import 'package:dio/dio.dart'; import 'package:stream_chat/src/core/error/error.dart'; /// Error class specific to StreamChat and Dio -class StreamChatDioError extends DioError { +class StreamChatDioError extends DioException { /// Initialize a stream chat dio error StreamChatDioError({ required this.error, diff --git a/packages/stream_chat/lib/src/core/http/stream_http_client.dart b/packages/stream_chat/lib/src/core/http/stream_http_client.dart index 99e72339f..0d21f973d 100644 --- a/packages/stream_chat/lib/src/core/http/stream_http_client.dart +++ b/packages/stream_chat/lib/src/core/http/stream_http_client.dart @@ -92,16 +92,16 @@ class StreamHttpClient { /// calling [close] will throw an exception. void close({bool force = false}) => httpClient.close(force: force); - StreamChatNetworkError _parseError(DioError err) { + StreamChatNetworkError _parseError(DioException exception) { StreamChatNetworkError error; // locally thrown dio error - if (err is StreamChatDioError) { - error = err.error; + if (exception is StreamChatDioError) { + error = exception.error; } else { // real network request dio error - error = StreamChatNetworkError.fromDioError(err); + error = StreamChatNetworkError.fromDioException(exception); } - return error..stackTrace = err.stackTrace; + return error..stackTrace = exception.stackTrace; } /// Handy method to make http GET request with error parsing. @@ -121,7 +121,7 @@ class StreamHttpClient { cancelToken: cancelToken, ); return response; - } on DioError catch (error) { + } on DioException catch (error) { throw _parseError(error); } } @@ -147,7 +147,7 @@ class StreamHttpClient { cancelToken: cancelToken, ); return response; - } on DioError catch (error) { + } on DioException catch (error) { throw _parseError(error); } } @@ -167,7 +167,7 @@ class StreamHttpClient { cancelToken: cancelToken, ); return response; - } on DioError catch (error) { + } on DioException catch (error) { throw _parseError(error); } } @@ -193,7 +193,7 @@ class StreamHttpClient { cancelToken: cancelToken, ); return response; - } on DioError catch (error) { + } on DioException catch (error) { throw _parseError(error); } } @@ -219,7 +219,7 @@ class StreamHttpClient { cancelToken: cancelToken, ); return response; - } on DioError catch (error) { + } on DioException catch (error) { throw _parseError(error); } } @@ -268,7 +268,7 @@ class StreamHttpClient { cancelToken: cancelToken, ); return response; - } on DioError catch (error) { + } on DioException catch (error) { throw _parseError(error); } } @@ -281,7 +281,7 @@ class StreamHttpClient { try { final response = await httpClient.fetch(requestOptions); return response; - } on DioError catch (error) { + } on DioException catch (error) { throw _parseError(error); } } diff --git a/packages/stream_chat/lib/stream_chat.dart b/packages/stream_chat/lib/stream_chat.dart index 1e0df28c6..2dbf1afdb 100644 --- a/packages/stream_chat/lib/stream_chat.dart +++ b/packages/stream_chat/lib/stream_chat.dart @@ -1,12 +1,17 @@ library stream_chat; export 'package:async/async.dart'; -export 'package:dio/src/cancel_token.dart'; -export 'package:dio/src/dio_error.dart'; -export 'package:dio/src/dio_mixin.dart' show Interceptor, InterceptorsWrapper; -export 'package:dio/src/multipart_file.dart'; -export 'package:dio/src/options.dart'; -export 'package:dio/src/options.dart' show ProgressCallback; +export 'package:dio/dio.dart' + show + DioException, + DioExceptionType, + RequestOptions, + CancelToken, + Interceptor, + InterceptorsWrapper, + MultipartFile, + Options, + ProgressCallback; export 'package:logging/logging.dart' show Logger, Level, LogRecord; export 'package:rate_limiter/rate_limiter.dart'; export 'package:uuid/uuid.dart'; @@ -17,7 +22,6 @@ export 'src/client/key_stroke_handler.dart'; export 'src/core/api/attachment_file_uploader.dart'; export 'src/core/api/requests.dart'; export 'src/core/api/responses.dart'; -export 'src/core/api/stream_chat_api.dart' show PushProvider; export 'src/core/api/stream_chat_api.dart'; export 'src/core/error/error.dart'; export 'src/core/http/interceptor/logging_interceptor.dart'; diff --git a/packages/stream_chat/pubspec.yaml b/packages/stream_chat/pubspec.yaml index 62bf7b52a..cbd95b881 100644 --- a/packages/stream_chat/pubspec.yaml +++ b/packages/stream_chat/pubspec.yaml @@ -11,7 +11,7 @@ environment: dependencies: async: ^2.10.0 collection: ^1.17.0 - dio: ^5.1.1 + dio: ^5.2.0 equatable: ^2.0.5 freezed_annotation: ^2.2.0 http_parser: ^4.0.2 diff --git a/packages/stream_chat/test/src/core/error/stream_chat_error_test.dart b/packages/stream_chat/test/src/core/error/stream_chat_error_test.dart index a32e0d71c..8d4e5465b 100644 --- a/packages/stream_chat/test/src/core/error/stream_chat_error_test.dart +++ b/packages/stream_chat/test/src/core/error/stream_chat_error_test.dart @@ -60,7 +60,7 @@ void main() { expect(error.message, message); }); - test('.fromDioError', () { + test('.fromDioException', () { const code = 333; const statusCode = 666; const message = 'test-error-message'; @@ -69,7 +69,7 @@ void main() { ..code = code ..statusCode = statusCode ..message = message; - final dioError = DioError( + final dioError = DioException( requestOptions: options, response: Response( requestOptions: options, @@ -77,7 +77,7 @@ void main() { data: data.toJson(), ), ); - final error = StreamChatNetworkError.fromDioError(dioError); + final error = StreamChatNetworkError.fromDioException(dioError); expect(error, isNotNull); expect(error.code, code); expect(error.message, message); diff --git a/packages/stream_chat/test/src/core/http/interceptor/auth_interceptor_test.dart b/packages/stream_chat/test/src/core/http/interceptor/auth_interceptor_test.dart index 7bd81ff0e..e5d066007 100644 --- a/packages/stream_chat/test/src/core/http/interceptor/auth_interceptor_test.dart +++ b/packages/stream_chat/test/src/core/http/interceptor/auth_interceptor_test.dart @@ -88,7 +88,7 @@ void main() { requestOptions: options, data: errorResponse.toJson(), ); - final err = DioError(requestOptions: options, response: response); + final err = DioException(requestOptions: options, response: response); final handler = ErrorInterceptorHandler(); when(() => tokenManager.isStatic).thenReturn(false); @@ -135,7 +135,7 @@ void main() { requestOptions: options, data: errorResponse.toJson(), ); - final err = DioError(requestOptions: options, response: response); + final err = DioException(requestOptions: options, response: response); final handler = ErrorInterceptorHandler(); when(() => tokenManager.isStatic).thenReturn(false); @@ -153,7 +153,7 @@ void main() { } catch (e) { // need to cast it as the type is private in dio final error = (e as dynamic).data; - expect(error, isA()); + expect(error, isA()); } verify(() => tokenManager.isStatic).called(1); @@ -179,7 +179,7 @@ void main() { requestOptions: options, data: errorResponse.toJson(), ); - final err = DioError(requestOptions: options, response: response); + final err = DioException(requestOptions: options, response: response); final handler = ErrorInterceptorHandler(); when(() => tokenManager.isStatic).thenReturn(true); @@ -191,8 +191,8 @@ void main() { } catch (e) { // need to cast it as the type is private in dio final error = (e as dynamic).data; - expect(error, isA()); - final response = StreamChatNetworkError.fromDioError(error); + expect(error, isA()); + final response = StreamChatNetworkError.fromDioException(error); expect(response.errorCode, code); } @@ -207,7 +207,7 @@ void main() { const path = 'test-request-path'; final options = RequestOptions(path: path); final response = Response(requestOptions: options); - final err = DioError(requestOptions: options, response: response); + final err = DioException(requestOptions: options, response: response); final handler = ErrorInterceptorHandler(); authInterceptor.onError(err, handler); @@ -217,7 +217,7 @@ void main() { } catch (e) { // need to cast it as the type is private in dio final error = (e as dynamic).data; - expect(error, isA()); + expect(error, isA()); } }, ); diff --git a/packages/stream_chat/test/src/core/http/stream_chat_dio_error_test.dart b/packages/stream_chat/test/src/core/http/stream_chat_dio_error_test.dart index f13cf50d5..e29148bf4 100644 --- a/packages/stream_chat/test/src/core/http/stream_chat_dio_error_test.dart +++ b/packages/stream_chat/test/src/core/http/stream_chat_dio_error_test.dart @@ -12,7 +12,7 @@ void main() { requestOptions: options, ); - expect(dioError, isA()); + expect(dioError, isA()); expect(dioError, isNotNull); expect(dioError.error, error); expect(dioError.requestOptions, options); diff --git a/packages/stream_chat/test/src/core/http/stream_http_client_test.dart b/packages/stream_chat/test/src/core/http/stream_http_client_test.dart index 51533b115..f63e08f14 100644 --- a/packages/stream_chat/test/src/core/http/stream_http_client_test.dart +++ b/packages/stream_chat/test/src/core/http/stream_http_client_test.dart @@ -21,7 +21,7 @@ void main() { statusCode: 200, ); - DioError throwableError( + DioException throwableError( String path, { StreamChatNetworkError? error, bool streamChatDioError = false, @@ -32,11 +32,11 @@ void main() { ..code = error?.code ..statusCode = error?.statusCode ..message = error?.message; - DioError? dioError; + DioException? dioError; if (streamChatDioError) { dioError = StreamChatDioError(error: error!, requestOptions: options); } else { - dioError = DioError( + dioError = DioException( error: error, requestOptions: options, response: Response( @@ -210,7 +210,7 @@ void main() { await client.get(path); } catch (e) { expect(e, isA()); - expect(e, StreamChatNetworkError.fromDioError(error)); + expect(e, StreamChatNetworkError.fromDioException(error)); } verify(() => dio.get( @@ -263,7 +263,7 @@ void main() { await client.post(path); } catch (e) { expect(e, isA()); - expect(e, StreamChatNetworkError.fromDioError(error)); + expect(e, StreamChatNetworkError.fromDioException(error)); } verify(() => dio.post( @@ -317,7 +317,7 @@ void main() { await client.delete(path); } catch (e) { expect(e, isA()); - expect(e, StreamChatNetworkError.fromDioError(error)); + expect(e, StreamChatNetworkError.fromDioException(error)); } verify(() => dio.delete( @@ -371,7 +371,7 @@ void main() { await client.patch(path); } catch (e) { expect(e, isA()); - expect(e, StreamChatNetworkError.fromDioError(error)); + expect(e, StreamChatNetworkError.fromDioException(error)); } verify(() => dio.patch( @@ -425,7 +425,7 @@ void main() { await client.put(path); } catch (e) { expect(e, isA()); - expect(e, StreamChatNetworkError.fromDioError(error)); + expect(e, StreamChatNetworkError.fromDioException(error)); } verify(() => dio.put( @@ -486,7 +486,7 @@ void main() { await client.postFile(path, file); } catch (e) { expect(e, isA()); - expect(e, StreamChatNetworkError.fromDioError(error)); + expect(e, StreamChatNetworkError.fromDioException(error)); } verify(() => dio.post( diff --git a/packages/stream_chat_flutter/pubspec.yaml b/packages/stream_chat_flutter/pubspec.yaml index c360f1ec5..03ee2b22b 100644 --- a/packages/stream_chat_flutter/pubspec.yaml +++ b/packages/stream_chat_flutter/pubspec.yaml @@ -17,7 +17,7 @@ dependencies: dart_vlc: ^0.4.0 desktop_drop: ^0.4.0 diacritic: ^0.1.3 - dio: ^5.1.1 + dio: ^5.2.0 ezanimation: ^0.6.0 file_picker: ^5.2.4 file_selector: ^0.9.0 diff --git a/packages/stream_chat_flutter_core/lib/src/stream_channel.dart b/packages/stream_chat_flutter_core/lib/src/stream_channel.dart index 9cfc34640..5bb8dee7f 100644 --- a/packages/stream_chat_flutter_core/lib/src/stream_channel.dart +++ b/packages/stream_chat_flutter_core/lib/src/stream_channel.dart @@ -430,16 +430,15 @@ class StreamChannelState extends State { ], builder: (context, snapshot) { if (snapshot.hasError) { - var message = snapshot.error.toString(); - if (snapshot.error is DioError) { - final dioError = snapshot.error as DioError?; - if (dioError?.type == DioErrorType.badResponse) { - message = dioError!.message ?? 'Bad response'; - } else { - message = 'Check your connection and retry'; + final error = snapshot.error; + if (error is DioException) { + if (error.type == DioExceptionType.badResponse) { + return Center(child: Text(error.message ?? 'Bad response')); } + return const Center(child: Text('Check your connection and retry')); } - return Center(child: Text(message)); + + return Center(child: Text(error.toString())); } final dataLoaded = snapshot.data?.every((it) => it) == true; diff --git a/packages/stream_chat_flutter_core/test/stream_channel_test.dart b/packages/stream_chat_flutter_core/test/stream_channel_test.dart index f4acf3c9c..5ba31042e 100644 --- a/packages/stream_chat_flutter_core/test/stream_channel_test.dart +++ b/packages/stream_chat_flutter_core/test/stream_channel_test.dart @@ -91,8 +91,8 @@ void main() { ); const errorMessage = 'Error! Error! Error!'; - final error = DioError( - type: DioErrorType.badResponse, + final error = DioException( + type: DioExceptionType.badResponse, message: errorMessage, requestOptions: RequestOptions(), ); From 4ba0e9fc0ef6aeb59b17157c9c0c90177b5ce457 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Tue, 6 Jun 2023 15:19:20 +0530 Subject: [PATCH 09/23] chore: update CHANGELOG.md Signed-off-by: xsahil03x --- packages/stream_chat/CHANGELOG.md | 6 ++++++ packages/stream_chat_flutter/CHANGELOG.md | 6 ++++++ packages/stream_chat_flutter_core/CHANGELOG.md | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/packages/stream_chat/CHANGELOG.md b/packages/stream_chat/CHANGELOG.md index b001d99e7..9173d27a2 100644 --- a/packages/stream_chat/CHANGELOG.md +++ b/packages/stream_chat/CHANGELOG.md @@ -1,3 +1,9 @@ +## Upcoming + +🔄 Changed + +- Updated `dio` dependency to `^5.2.0`. + ## 6.2.0 🐞 Fixed diff --git a/packages/stream_chat_flutter/CHANGELOG.md b/packages/stream_chat_flutter/CHANGELOG.md index 0ea80c8f1..2e1b875f4 100644 --- a/packages/stream_chat_flutter/CHANGELOG.md +++ b/packages/stream_chat_flutter/CHANGELOG.md @@ -1,3 +1,9 @@ +## Upcoming + +🔄 Changed + +- Updated `dio` dependency to `^5.2.0`. + ## 6.2.0 🐞 Fixed diff --git a/packages/stream_chat_flutter_core/CHANGELOG.md b/packages/stream_chat_flutter_core/CHANGELOG.md index c7869125c..0c178fd45 100644 --- a/packages/stream_chat_flutter_core/CHANGELOG.md +++ b/packages/stream_chat_flutter_core/CHANGELOG.md @@ -1,3 +1,7 @@ +## Upcoming + +- Updated `stream_chat` dependency to [`Upcoming`](https://pub.dev/packages/stream_chat/changelog). + ## 6.2.0 - Fixed `StreamMessageInputController.textPatternStyle` not matching case-insensitive patterns. From 5322ad717068d6bd29408d3a8fb4774dba9a1ad3 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Tue, 6 Jun 2023 16:07:31 +0530 Subject: [PATCH 10/23] test: add tests. Signed-off-by: xsahil03x --- .../test/src/client/client_test.dart | 118 ++++++++++++++++++ packages/stream_chat/test/src/mocks.dart | 14 ++- 2 files changed, 130 insertions(+), 2 deletions(-) diff --git a/packages/stream_chat/test/src/client/client_test.dart b/packages/stream_chat/test/src/client/client_test.dart index 7a6055570..b1f724afe 100644 --- a/packages/stream_chat/test/src/client/client_test.dart +++ b/packages/stream_chat/test/src/client/client_test.dart @@ -2544,4 +2544,122 @@ void main() { }, ); }); + + group('PersistenceConnectionTests', () { + const apiKey = 'test-api-key'; + late final api = FakeChatApi(); + late final ws = FakeWebSocket(); + + final user = User(id: 'test-user-id'); + final token = Token.development(user.id).rawValue; + + late StreamChatClient client; + + setUp(() async { + client = StreamChatClient(apiKey, chatApi: api, ws: ws); + expect(client.persistenceEnabled, isFalse); + }); + + tearDown(() { + client.chatPersistenceClient = null; + expect(client.persistenceEnabled, isFalse); + client.dispose(); + }); + + test('openPersistenceConnection connects the client to the user', () async { + client.chatPersistenceClient = MockPersistenceClient(); + await client.openPersistenceConnection(user); + expect(client.persistenceEnabled, isTrue); + }); + + test( + '''multiple call to openPersistenceConnection does not throws an error if already connected to the same user''', + () async { + client.chatPersistenceClient = MockPersistenceClient(); + await client.openPersistenceConnection(user); + expect(client.persistenceEnabled, isTrue); + + expect(() => client.openPersistenceConnection(user), returnsNormally); + expect(() => client.openPersistenceConnection(user), returnsNormally); + expect(() => client.openPersistenceConnection(user), returnsNormally); + }, + ); + + test( + '''openPersistenceConnection throws an error if client is already connected to a different user''', + () async { + client.chatPersistenceClient = MockPersistenceClient(); + await client.openPersistenceConnection(user); + expect(client.persistenceEnabled, isTrue); + + expect( + () => client.openPersistenceConnection(user.copyWith(id: 'new-id')), + throwsA(const TypeMatcher()), + ); + }, + ); + + test( + '''openPersistenceConnection throws an error if chatPersistenceClient is not set''', + () async { + expect( + () => client.openPersistenceConnection(user), + throwsA(const TypeMatcher()), + ); + }, + ); + + test('closePersistenceConnection disconnects the client', () async { + client.chatPersistenceClient = MockPersistenceClient(); + await client.openPersistenceConnection(user); + expect(client.persistenceEnabled, isTrue); + + await client.closePersistenceConnection(); + expect(client.persistenceEnabled, isFalse); + }); + + test( + '''closePersistenceConnection does nothing if chatPersistenceClient is not connected''', + () async { + client.chatPersistenceClient = MockPersistenceClient(); + expect(client.persistenceEnabled, isFalse); + + expect(() => client.closePersistenceConnection(), returnsNormally); + }, + ); + + test( + '''closePersistenceConnection does nothing if chatPersistenceClient is not set''', + () async { + expect(client.persistenceEnabled, isFalse); + expect(() => client.closePersistenceConnection(), returnsNormally); + }, + ); + + test( + '''connectUser should re-use the persistence connection if already connected''', + () async { + client.chatPersistenceClient = MockPersistenceClient(); + await client.openPersistenceConnection(user); + expect(client.persistenceEnabled, isTrue); + + await client.connectUser(user, token, connectWebSocket: false); + expect(client.persistenceEnabled, isTrue); + }, + ); + + test( + '''connectUser should throw if the persistence connection if already connected to a different user''', + () async { + client.chatPersistenceClient = MockPersistenceClient(); + await client.openPersistenceConnection(user.copyWith(id: 'new-id')); + expect(client.persistenceEnabled, isTrue); + + expect( + () => client.connectUser(user, token, connectWebSocket: false), + throwsA(const TypeMatcher()), + ); + }, + ); + }); } diff --git a/packages/stream_chat/test/src/mocks.dart b/packages/stream_chat/test/src/mocks.dart index 86a77a666..f412d15a8 100644 --- a/packages/stream_chat/test/src/mocks.dart +++ b/packages/stream_chat/test/src/mocks.dart @@ -64,16 +64,26 @@ class MockAttachmentFileUploader extends Mock implements AttachmentFileUploader {} class MockPersistenceClient extends Mock implements ChatPersistenceClient { + String? _userId; bool _isConnected = false; @override bool get isConnected => _isConnected; @override - Future connect(String userId) async => _isConnected = true; + String? get userId => _userId; @override - Future disconnect({bool flush = false}) async => _isConnected = false; + Future connect(String userId) async { + _userId = userId; + _isConnected = true; + } + + @override + Future disconnect({bool flush = false}) async { + _userId = null; + _isConnected = false; + } } class MockStreamChatClient extends Mock implements StreamChatClient { From 0e67cdacf5282d1bf8b2510ee4fd0489636fc3ec Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Tue, 6 Jun 2023 16:15:54 +0530 Subject: [PATCH 11/23] test: update test for async methods. Signed-off-by: xsahil03x --- .../test/src/client/client_test.dart | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/packages/stream_chat/test/src/client/client_test.dart b/packages/stream_chat/test/src/client/client_test.dart index b1f724afe..9ff0c69f7 100644 --- a/packages/stream_chat/test/src/client/client_test.dart +++ b/packages/stream_chat/test/src/client/client_test.dart @@ -2579,9 +2579,9 @@ void main() { await client.openPersistenceConnection(user); expect(client.persistenceEnabled, isTrue); - expect(() => client.openPersistenceConnection(user), returnsNormally); - expect(() => client.openPersistenceConnection(user), returnsNormally); - expect(() => client.openPersistenceConnection(user), returnsNormally); + await expectLater(client.openPersistenceConnection(user), completes); + await expectLater(client.openPersistenceConnection(user), completes); + await expectLater(client.openPersistenceConnection(user), completes); }, ); @@ -2592,8 +2592,8 @@ void main() { await client.openPersistenceConnection(user); expect(client.persistenceEnabled, isTrue); - expect( - () => client.openPersistenceConnection(user.copyWith(id: 'new-id')), + await expectLater( + client.openPersistenceConnection(user.copyWith(id: 'new-id')), throwsA(const TypeMatcher()), ); }, @@ -2602,8 +2602,8 @@ void main() { test( '''openPersistenceConnection throws an error if chatPersistenceClient is not set''', () async { - expect( - () => client.openPersistenceConnection(user), + await expectLater( + client.openPersistenceConnection(user), throwsA(const TypeMatcher()), ); }, @@ -2619,32 +2619,34 @@ void main() { }); test( - '''closePersistenceConnection does nothing if chatPersistenceClient is not connected''', + '''closePersistenceConnection compeletes normally if chatPersistenceClient is not connected''', () async { client.chatPersistenceClient = MockPersistenceClient(); - expect(client.persistenceEnabled, isFalse); + expect(client.chatPersistenceClient!.isConnected, isFalse); - expect(() => client.closePersistenceConnection(), returnsNormally); + await expectLater(client.closePersistenceConnection(), completes); }, ); test( - '''closePersistenceConnection does nothing if chatPersistenceClient is not set''', + '''closePersistenceConnection completes normally if chatPersistenceClient is not set''', () async { expect(client.persistenceEnabled, isFalse); - expect(() => client.closePersistenceConnection(), returnsNormally); + await expectLater(client.closePersistenceConnection(), completes); }, ); test( - '''connectUser should re-use the persistence connection if already connected''', + '''connectUser completes normally if the persistence connection is already connected to the same user''', () async { client.chatPersistenceClient = MockPersistenceClient(); await client.openPersistenceConnection(user); expect(client.persistenceEnabled, isTrue); - await client.connectUser(user, token, connectWebSocket: false); - expect(client.persistenceEnabled, isTrue); + await expectLater( + client.connectUser(user, token, connectWebSocket: false), + completes, + ); }, ); @@ -2655,8 +2657,8 @@ void main() { await client.openPersistenceConnection(user.copyWith(id: 'new-id')); expect(client.persistenceEnabled, isTrue); - expect( - () => client.connectUser(user, token, connectWebSocket: false), + await expectLater( + client.connectUser(user, token, connectWebSocket: false), throwsA(const TypeMatcher()), ); }, From ba3f61fa1534dc4b75cdb6ecf71dc701c3c3bd3a Mon Sep 17 00:00:00 2001 From: rlee1990 Date: Tue, 6 Jun 2023 12:11:25 -0400 Subject: [PATCH 12/23] Removed Jiffy --- .../stream_chat_flutter/lib/src/channel/channel_info.dart | 2 +- .../lib/src/message_list_view/message_list_view.dart | 7 +++---- .../user_scroll_view/stream_user_list_tile.dart | 2 +- packages/stream_chat_flutter/lib/src/user/user_item.dart | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/stream_chat_flutter/lib/src/channel/channel_info.dart b/packages/stream_chat_flutter/lib/src/channel/channel_info.dart index 264908a87..5c32d2789 100644 --- a/packages/stream_chat_flutter/lib/src/channel/channel_info.dart +++ b/packages/stream_chat_flutter/lib/src/channel/channel_info.dart @@ -108,7 +108,7 @@ class _ConnectedTitleState extends StatelessWidget { } else { alternativeWidget = Text( '${context.translations.userLastOnlineText} ' - '${Jiffy(otherMember.user!.lastActive!).fromNow()}', + '${Jiffy(otherMember.user?.lastActive).fromNow()}', style: textStyle, ); } diff --git a/packages/stream_chat_flutter/lib/src/message_list_view/message_list_view.dart b/packages/stream_chat_flutter/lib/src/message_list_view/message_list_view.dart index 76d552854..4c29eb691 100644 --- a/packages/stream_chat_flutter/lib/src/message_list_view/message_list_view.dart +++ b/packages/stream_chat_flutter/lib/src/message_list_view/message_list_view.dart @@ -666,12 +666,11 @@ class _StreamMessageListViewState extends State { final createdAt = message.createdAt.toLocal(); final nextCreatedAt = nextMessage.createdAt.toLocal(); - if (!Jiffy(createdAt) - .isSame(Jiffy(nextCreatedAt), Units.DAY)) { + if (!Jiffy(createdAt).isSame(nextCreatedAt, Units.DAY)) { separator = _buildDateDivider(nextMessage); } else { final hasTimeDiff = !Jiffy(createdAt).isSame( - Jiffy(nextCreatedAt), + nextCreatedAt, Units.MINUTE, ); @@ -1063,7 +1062,7 @@ class _StreamMessageListViewState extends State { var hasTimeDiff = false; if (nextMessage != null) { hasTimeDiff = !Jiffy(message.createdAt.toLocal()).isSame( - Jiffy(nextMessage.createdAt.toLocal()), + nextMessage.createdAt.toLocal(), Units.MINUTE, ); } diff --git a/packages/stream_chat_flutter/lib/src/scroll_view/user_scroll_view/stream_user_list_tile.dart b/packages/stream_chat_flutter/lib/src/scroll_view/user_scroll_view/stream_user_list_tile.dart index 00e7339a6..dbb0f6a5f 100644 --- a/packages/stream_chat_flutter/lib/src/scroll_view/user_scroll_view/stream_user_list_tile.dart +++ b/packages/stream_chat_flutter/lib/src/scroll_view/user_scroll_view/stream_user_list_tile.dart @@ -179,7 +179,7 @@ class UserLastActive extends StatelessWidget { user.online ? context.translations.userOnlineText : '${context.translations.userLastOnlineText} ' - '${Jiffy(user.lastActive!).fromNow()}', + '${Jiffy(user.lastActive).fromNow()}', style: chatTheme.textTheme.footnote.copyWith( color: chatTheme.colorTheme.textHighEmphasis.withOpacity(0.5), ), diff --git a/packages/stream_chat_flutter/lib/src/user/user_item.dart b/packages/stream_chat_flutter/lib/src/user/user_item.dart index 0d3b811a0..85d12a997 100644 --- a/packages/stream_chat_flutter/lib/src/user/user_item.dart +++ b/packages/stream_chat_flutter/lib/src/user/user_item.dart @@ -77,7 +77,7 @@ class StreamUserItem extends StatelessWidget { user.online ? context.translations.userOnlineText : '${context.translations.userLastOnlineText} ' - '${Jiffy(user.lastActive!).fromNow()}', + '${Jiffy(user.lastActive).fromNow()}', style: chatTheme.textTheme.footnote.copyWith( color: chatTheme.colorTheme.textHighEmphasis.withOpacity(0.5), ), From b70c1b97a8eb57ef272bb03a6d369026654ca304 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Wed, 7 Jun 2023 15:01:46 +0530 Subject: [PATCH 13/23] fix(ui): fix attachment download on web. Signed-off-by: xsahil03x --- .../lib/src/attachment/handler/common.dart | 70 ++++++++++++------- .../stream_attachment_handler_html.dart | 12 +++- .../handler/stream_attachment_handler_io.dart | 67 +++++++----------- 3 files changed, 80 insertions(+), 69 deletions(-) diff --git a/packages/stream_chat_flutter/lib/src/attachment/handler/common.dart b/packages/stream_chat_flutter/lib/src/attachment/handler/common.dart index fb4f192a8..96d5e1ed5 100644 --- a/packages/stream_chat_flutter/lib/src/attachment/handler/common.dart +++ b/packages/stream_chat_flutter/lib/src/attachment/handler/common.dart @@ -4,9 +4,41 @@ import 'package:dio/dio.dart'; import 'package:file_selector/file_selector.dart'; import 'package:stream_chat_flutter_core/stream_chat_flutter_core.dart'; -/// Downloads the [attachment] to the device and returns -/// the path to the file. -Future downloadWebOrDesktopAttachment( +/// Represents the url and bytes of an attachment. +class AttachmentData { + /// Creates a new [AttachmentData] instance. + const AttachmentData({ + required this.bytes, + required this.downloadUrl, + required this.fileName, + this.mimeType, + }); + + /// The data downloaded from the [downloadUrl]. + final Uint8List bytes; + + /// The url of the attachment that was used to download the [bytes]. + final String downloadUrl; + + /// The name of the file to use when saving the [bytes]. + final String fileName; + + /// The mime type of the attachment. + final String? mimeType; + + /// Creates an [XFile] from the [AttachmentData]. + XFile toXFile({String? path}) { + return XFile.fromData( + bytes, + mimeType: mimeType, + name: fileName, + path: path, + ); + } +} + +/// Downloads the [attachment] and returns the [AttachmentData]. +Future downloadAttachmentData( Attachment attachment, { ProgressCallback? onReceiveProgress, Map? queryParameters, @@ -34,13 +66,14 @@ Future downloadWebOrDesktopAttachment( fileName = attachment.title; } - assert( - downloadUrl != null, - 'Attachment must have an assetUrl or imageUrl or thumbUrl', - ); + if (downloadUrl == null) { + throw ArgumentError( + 'Attachment must have an assetUrl or imageUrl or thumbUrl', + ); + } final response = await Dio().get>( - downloadUrl!, + downloadUrl, onReceiveProgress: onReceiveProgress, queryParameters: queryParameters, cancelToken: cancelToken, @@ -49,23 +82,12 @@ Future downloadWebOrDesktopAttachment( Options(responseType: ResponseType.bytes), ); - // Open the native file browser so the user can select the download path. - final path = await getSavePath(suggestedName: fileName); + final bytes = Uint8List.fromList(response.data!); - if (path == null) { - // Operation was canceled by the user. - return null; - } - - // Create an XFile for proper file saving - final file = XFile.fromData( - Uint8List.fromList(response.data!), + return AttachmentData( + bytes: bytes, + downloadUrl: downloadUrl, + fileName: fileName!, mimeType: attachment.mimeType, - name: fileName, - path: path, ); - - // Save the file to the user's selected path. - await file.saveTo(path); - return path; } diff --git a/packages/stream_chat_flutter/lib/src/attachment/handler/stream_attachment_handler_html.dart b/packages/stream_chat_flutter/lib/src/attachment/handler/stream_attachment_handler_html.dart index 2d3a6fba6..b3d4b1217 100644 --- a/packages/stream_chat_flutter/lib/src/attachment/handler/stream_attachment_handler_html.dart +++ b/packages/stream_chat_flutter/lib/src/attachment/handler/stream_attachment_handler_html.dart @@ -50,13 +50,21 @@ class StreamAttachmentHandler extends StreamAttachmentHandlerBase { Map? queryParameters, CancelToken? cancelToken, Options? options, - }) { - return downloadWebOrDesktopAttachment( + }) async { + final data = await downloadAttachmentData( attachment, onReceiveProgress: onReceiveProgress, queryParameters: queryParameters, cancelToken: cancelToken, options: options, ); + + // Create an XFile for proper file saving. + final file = data.toXFile(); + + // Save the file. We are not using the path parameter because it is not + // supported on web. + await file.saveTo(''); + return null; } } diff --git a/packages/stream_chat_flutter/lib/src/attachment/handler/stream_attachment_handler_io.dart b/packages/stream_chat_flutter/lib/src/attachment/handler/stream_attachment_handler_io.dart index 268dbf152..0b04ee615 100644 --- a/packages/stream_chat_flutter/lib/src/attachment/handler/stream_attachment_handler_io.dart +++ b/packages/stream_chat_flutter/lib/src/attachment/handler/stream_attachment_handler_io.dart @@ -1,8 +1,7 @@ import 'dart:io'; -import 'dart:typed_data'; -import 'package:dio/dio.dart'; import 'package:file_picker/file_picker.dart'; +import 'package:file_selector/file_selector.dart'; import 'package:image_picker/image_picker.dart'; import 'package:path_provider/path_provider.dart'; import 'package:stream_chat_flutter/src/attachment/handler/common.dart'; @@ -21,14 +20,29 @@ class StreamAttachmentHandlerDesktop extends StreamAttachmentHandler { Map? queryParameters, CancelToken? cancelToken, Options? options, - }) { - return downloadWebOrDesktopAttachment( + }) async { + final data = await downloadAttachmentData( attachment, onReceiveProgress: onReceiveProgress, queryParameters: queryParameters, cancelToken: cancelToken, options: options, ); + + // Open the native file browser so the user can select the download path. + final path = await getSavePath(suggestedName: data.fileName); + + if (path == null) { + // Operation was canceled by the user. + return null; + } + + // Create an XFile for proper file saving. + final file = data.toXFile(path: path); + + // Save the file to the user's selected path. + await file.saveTo(path); + return path; } } @@ -160,53 +174,20 @@ class StreamAttachmentHandler extends StreamAttachmentHandlerBase { CancelToken? cancelToken, Options? options, }) async { - final type = attachment.type; - - String? downloadUrl; - String? fileName; - /* ---IMAGES/GIFS--- */ - if (type == 'image') { - downloadUrl = attachment.imageUrl ?? attachment.assetUrl; - fileName = attachment.title; - fileName ??= 'attachment.${attachment.mimeType ?? 'png'}'; - } - /* ---GIPHY's--- */ - else if (type == 'giphy') { - downloadUrl = attachment.thumbUrl; - fileName = '${attachment.title}.gif'; - } - /* ---FILES AND VIDEOS--- */ - else if (type == 'file' || type == 'video') { - downloadUrl = attachment.assetUrl; - fileName = attachment.title; - } - - assert( - downloadUrl != null, - 'Attachment must have an assetUrl or imageUrl or thumbUrl', - ); - - final response = await Dio().get>( - downloadUrl!, + final data = await downloadAttachmentData( + attachment, onReceiveProgress: onReceiveProgress, queryParameters: queryParameters, cancelToken: cancelToken, - // set responseType to `bytes` - options: options?.copyWith(responseType: ResponseType.bytes) ?? - Options(responseType: ResponseType.bytes), + options: options, ); final appDir = await getTemporaryDirectory(); - final ext = Uri.parse(downloadUrl).pathSegments.last; + final ext = Uri.parse(data.downloadUrl).pathSegments.last; final path = '${appDir.path}/${attachment.id}.$ext'; - // Create an XFile for proper file saving - final file = XFile.fromData( - Uint8List.fromList(response.data!), - mimeType: attachment.mimeType, - name: fileName, - path: path, - ); + // Create an XFile for proper file saving. + final file = data.toXFile(path: path); // Save the file to the user's selected path. await file.saveTo(path); From fa2263e93f7a9eb15148076fba9476994b6f6d28 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Wed, 7 Jun 2023 15:03:06 +0530 Subject: [PATCH 14/23] chore: update CHANGELOG.md Signed-off-by: xsahil03x --- packages/stream_chat_flutter/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/stream_chat_flutter/CHANGELOG.md b/packages/stream_chat_flutter/CHANGELOG.md index 2e1b875f4..981c2986f 100644 --- a/packages/stream_chat_flutter/CHANGELOG.md +++ b/packages/stream_chat_flutter/CHANGELOG.md @@ -1,5 +1,9 @@ ## Upcoming +🐞 Fixed + +- [[#1592]](https://github.com/GetStream/stream-chat-flutter/issues/1592) Fixed broken attachment download on web. + 🔄 Changed - Updated `dio` dependency to `^5.2.0`. From 6ce67a72699b11544f35399dd78aff4ee4eabe82 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Wed, 7 Jun 2023 18:16:46 +0530 Subject: [PATCH 15/23] fix(ui): fix channelInfoBottomSheet members rendering. Signed-off-by: xsahil03x --- .../bottom_sheets/stream_channel_info_bottom_sheet.dart | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/stream_chat_flutter/lib/src/bottom_sheets/stream_channel_info_bottom_sheet.dart b/packages/stream_chat_flutter/lib/src/bottom_sheets/stream_channel_info_bottom_sheet.dart index 6f5b32a8c..ea25f7bcb 100644 --- a/packages/stream_chat_flutter/lib/src/bottom_sheets/stream_channel_info_bottom_sheet.dart +++ b/packages/stream_chat_flutter/lib/src/bottom_sheets/stream_channel_info_bottom_sheet.dart @@ -91,12 +91,14 @@ class StreamChannelInfoBottomSheet extends StatelessWidget { final member = members[index]; final user = member.user!; return Column( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, children: [ StreamUserAvatar( user: user, - constraints: const BoxConstraints( - maxHeight: 64, - maxWidth: 64, + constraints: const BoxConstraints.tightFor( + height: 64, + width: 64, ), borderRadius: BorderRadius.circular(32), onlineIndicatorConstraints: BoxConstraints.tight( From 3b34efb5c5ad2b1cb3ff21a93686745e154a2b81 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Wed, 7 Jun 2023 18:18:09 +0530 Subject: [PATCH 16/23] chore: update CHANGELOG.md Signed-off-by: xsahil03x --- packages/stream_chat_flutter/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/stream_chat_flutter/CHANGELOG.md b/packages/stream_chat_flutter/CHANGELOG.md index 981c2986f..956450dc2 100644 --- a/packages/stream_chat_flutter/CHANGELOG.md +++ b/packages/stream_chat_flutter/CHANGELOG.md @@ -3,6 +3,8 @@ 🐞 Fixed - [[#1592]](https://github.com/GetStream/stream-chat-flutter/issues/1592) Fixed broken attachment download on web. +- [[#1591]](https://github.com/GetStream/stream-chat-flutter/issues/1591) Fixed `StreamChannelInfoBottomSheet` not + rendering member list properly. 🔄 Changed From 7a7588f20e471e0eb0c25c006af7f1ab7105de0e Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Wed, 7 Jun 2023 18:19:32 +0530 Subject: [PATCH 17/23] chore: formatting. Signed-off-by: xsahil03x --- packages/stream_chat/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/stream_chat/CHANGELOG.md b/packages/stream_chat/CHANGELOG.md index 7a3e9eecf..2a76beb92 100644 --- a/packages/stream_chat/CHANGELOG.md +++ b/packages/stream_chat/CHANGELOG.md @@ -4,7 +4,7 @@ - [[#1585]](https://github.com/GetStream/stream-chat-flutter/issues/1585) Fixed channels left not being removed from the persistent storage. - + 🔄 Changed - Updated `dio` dependency to `^5.2.0`. From c8aa868f40a2892f04af86cebe1c34b65d7aaac1 Mon Sep 17 00:00:00 2001 From: rlee1990 Date: Wed, 7 Jun 2023 09:34:54 -0400 Subject: [PATCH 18/23] Updated change log --- packages/stream_chat_flutter/CHANGELOG.md | 7 +++++++ .../stream_chat_flutter/lib/src/theme/message_theme.dart | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/stream_chat_flutter/CHANGELOG.md b/packages/stream_chat_flutter/CHANGELOG.md index 0ea80c8f1..a7dc01ffe 100644 --- a/packages/stream_chat_flutter/CHANGELOG.md +++ b/packages/stream_chat_flutter/CHANGELOG.md @@ -1,3 +1,10 @@ +## Upcoming + +🐞 Fixed + +- [[#1427]](https://github.com/GetStream/stream-chat-flutter/issues/1427) Fixed unable to load asset error for + `packages/stream_chat_flutter/lib/svgs/video_call_icon.svg`. + ## 6.2.0 🐞 Fixed diff --git a/packages/stream_chat_flutter/lib/src/theme/message_theme.dart b/packages/stream_chat_flutter/lib/src/theme/message_theme.dart index 6c35c5e34..b997fd4a3 100644 --- a/packages/stream_chat_flutter/lib/src/theme/message_theme.dart +++ b/packages/stream_chat_flutter/lib/src/theme/message_theme.dart @@ -23,7 +23,7 @@ class StreamMessageThemeData with Diagnosticable { this.avatarTheme, this.createdAtStyle, @Deprecated('Use urlAttachmentBackgroundColor instead') - Color? linkBackgroundColor, + Color? linkBackgroundColor, Color? urlAttachmentBackgroundColor, this.urlAttachmentHostStyle, this.urlAttachmentTitleStyle, @@ -102,7 +102,7 @@ class StreamMessageThemeData with Diagnosticable { Color? reactionsBorderColor, Color? reactionsMaskColor, @Deprecated('Use urlAttachmentBackgroundColor instead') - Color? linkBackgroundColor, + Color? linkBackgroundColor, Color? urlAttachmentBackgroundColor, TextStyle? urlAttachmentHostStyle, TextStyle? urlAttachmentTitleStyle, From 1a7a05c62f372db2e70b432079b980443994b7f5 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Wed, 7 Jun 2023 19:20:34 +0530 Subject: [PATCH 19/23] Apply suggestions from code review --- .../lib/src/localization/translations.dart | 2 +- packages/stream_chat_flutter/lib/src/theme/message_theme.dart | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/stream_chat_flutter/lib/src/localization/translations.dart b/packages/stream_chat_flutter/lib/src/localization/translations.dart index 61c3441a2..71254e734 100644 --- a/packages/stream_chat_flutter/lib/src/localization/translations.dart +++ b/packages/stream_chat_flutter/lib/src/localization/translations.dart @@ -83,7 +83,7 @@ abstract class Translations { /// in the [StreamMessageListView] String unreadMessagesSeparatorText( @Deprecated('unreadCount is not used anymore and will be removed ') - int unreadCount, + int unreadCount, ); /// The label for "connected" in [StreamConnectionStatusBuilder] diff --git a/packages/stream_chat_flutter/lib/src/theme/message_theme.dart b/packages/stream_chat_flutter/lib/src/theme/message_theme.dart index b997fd4a3..6c35c5e34 100644 --- a/packages/stream_chat_flutter/lib/src/theme/message_theme.dart +++ b/packages/stream_chat_flutter/lib/src/theme/message_theme.dart @@ -23,7 +23,7 @@ class StreamMessageThemeData with Diagnosticable { this.avatarTheme, this.createdAtStyle, @Deprecated('Use urlAttachmentBackgroundColor instead') - Color? linkBackgroundColor, + Color? linkBackgroundColor, Color? urlAttachmentBackgroundColor, this.urlAttachmentHostStyle, this.urlAttachmentTitleStyle, @@ -102,7 +102,7 @@ class StreamMessageThemeData with Diagnosticable { Color? reactionsBorderColor, Color? reactionsMaskColor, @Deprecated('Use urlAttachmentBackgroundColor instead') - Color? linkBackgroundColor, + Color? linkBackgroundColor, Color? urlAttachmentBackgroundColor, TextStyle? urlAttachmentHostStyle, TextStyle? urlAttachmentTitleStyle, From 3dfd59c36ecbf4f94f8e645b9b951484502e1da6 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Thu, 8 Jun 2023 18:08:25 +0530 Subject: [PATCH 20/23] chore: prepare for release. Signed-off-by: xsahil03x --- packages/stream_chat/CHANGELOG.md | 2 +- packages/stream_chat/lib/version.dart | 2 +- packages/stream_chat/pubspec.yaml | 2 +- packages/stream_chat_flutter/CHANGELOG.md | 2 +- packages/stream_chat_flutter/pubspec.yaml | 4 ++-- packages/stream_chat_flutter_core/CHANGELOG.md | 4 ++-- packages/stream_chat_flutter_core/pubspec.yaml | 4 ++-- packages/stream_chat_localizations/CHANGELOG.md | 4 ++++ packages/stream_chat_localizations/pubspec.yaml | 4 ++-- packages/stream_chat_persistence/CHANGELOG.md | 4 ++++ packages/stream_chat_persistence/pubspec.yaml | 4 ++-- 11 files changed, 22 insertions(+), 14 deletions(-) diff --git a/packages/stream_chat/CHANGELOG.md b/packages/stream_chat/CHANGELOG.md index 2a76beb92..ade0551eb 100644 --- a/packages/stream_chat/CHANGELOG.md +++ b/packages/stream_chat/CHANGELOG.md @@ -1,4 +1,4 @@ -## Upcoming +## 6.3.0 🐞 Fixed diff --git a/packages/stream_chat/lib/version.dart b/packages/stream_chat/lib/version.dart index 8fdd5ebcf..bf392fb35 100644 --- a/packages/stream_chat/lib/version.dart +++ b/packages/stream_chat/lib/version.dart @@ -3,4 +3,4 @@ import 'package:stream_chat/src/client/client.dart'; /// Current package version /// Used in [StreamChatClient] to build the `x-stream-client` header // ignore: constant_identifier_names -const PACKAGE_VERSION = '6.2.0'; +const PACKAGE_VERSION = '6.3.0'; diff --git a/packages/stream_chat/pubspec.yaml b/packages/stream_chat/pubspec.yaml index cbd95b881..db3bad2c4 100644 --- a/packages/stream_chat/pubspec.yaml +++ b/packages/stream_chat/pubspec.yaml @@ -1,7 +1,7 @@ name: stream_chat homepage: https://getstream.io/ description: The official Dart client for Stream Chat, a service for building chat applications. -version: 6.2.0 +version: 6.3.0 repository: https://github.com/GetStream/stream-chat-flutter issue_tracker: https://github.com/GetStream/stream-chat-flutter/issues diff --git a/packages/stream_chat_flutter/CHANGELOG.md b/packages/stream_chat_flutter/CHANGELOG.md index ed0369346..77a7f55ef 100644 --- a/packages/stream_chat_flutter/CHANGELOG.md +++ b/packages/stream_chat_flutter/CHANGELOG.md @@ -1,4 +1,4 @@ -## Upcoming +## 6.3.0 🐞 Fixed diff --git a/packages/stream_chat_flutter/pubspec.yaml b/packages/stream_chat_flutter/pubspec.yaml index 03ee2b22b..5342f4abb 100644 --- a/packages/stream_chat_flutter/pubspec.yaml +++ b/packages/stream_chat_flutter/pubspec.yaml @@ -1,7 +1,7 @@ name: stream_chat_flutter homepage: https://github.com/GetStream/stream-chat-flutter description: Stream Chat official Flutter SDK. Build your own chat experience using Dart and Flutter. -version: 6.2.0 +version: 6.3.0 repository: https://github.com/GetStream/stream-chat-flutter issue_tracker: https://github.com/GetStream/stream-chat-flutter/issues @@ -38,7 +38,7 @@ dependencies: rxdart: ^0.27.0 share_plus: ^6.3.0 shimmer: ^3.0.0 - stream_chat_flutter_core: ^6.2.0 + stream_chat_flutter_core: ^6.3.0 synchronized: ^3.0.0 thumblr: ^0.0.4 url_launcher: ^6.1.0 diff --git a/packages/stream_chat_flutter_core/CHANGELOG.md b/packages/stream_chat_flutter_core/CHANGELOG.md index 0c178fd45..d694a7316 100644 --- a/packages/stream_chat_flutter_core/CHANGELOG.md +++ b/packages/stream_chat_flutter_core/CHANGELOG.md @@ -1,6 +1,6 @@ -## Upcoming +## 6.3.0 -- Updated `stream_chat` dependency to [`Upcoming`](https://pub.dev/packages/stream_chat/changelog). +- Updated `stream_chat` dependency to [`6.3.0`](https://pub.dev/packages/stream_chat/changelog). ## 6.2.0 diff --git a/packages/stream_chat_flutter_core/pubspec.yaml b/packages/stream_chat_flutter_core/pubspec.yaml index 3f602978f..bfd0d8817 100644 --- a/packages/stream_chat_flutter_core/pubspec.yaml +++ b/packages/stream_chat_flutter_core/pubspec.yaml @@ -1,7 +1,7 @@ name: stream_chat_flutter_core homepage: https://github.com/GetStream/stream-chat-flutter description: Stream Chat official Flutter SDK Core. Build your own chat experience using Dart and Flutter. -version: 6.2.0 +version: 6.3.0 repository: https://github.com/GetStream/stream-chat-flutter issue_tracker: https://github.com/GetStream/stream-chat-flutter/issues @@ -17,7 +17,7 @@ dependencies: freezed_annotation: ^2.0.3 meta: ^1.8.0 rxdart: ^0.27.0 - stream_chat: ^6.2.0 + stream_chat: ^6.3.0 dev_dependencies: build_runner: ^2.3.3 diff --git a/packages/stream_chat_localizations/CHANGELOG.md b/packages/stream_chat_localizations/CHANGELOG.md index ab1abd10b..50af8f396 100644 --- a/packages/stream_chat_localizations/CHANGELOG.md +++ b/packages/stream_chat_localizations/CHANGELOG.md @@ -1,3 +1,7 @@ +## 5.3.0 + +* Updated `stream_chat_flutter` dependency to [`6.3.0`](https://pub.dev/packages/stream_chat_flutter/changelog). + ## 5.2.0 * Updated `stream_chat_flutter` dependency to [`6.2.0`](https://pub.dev/packages/stream_chat_flutter/changelog). diff --git a/packages/stream_chat_localizations/pubspec.yaml b/packages/stream_chat_localizations/pubspec.yaml index dbcf7ea84..f5bcdc199 100644 --- a/packages/stream_chat_localizations/pubspec.yaml +++ b/packages/stream_chat_localizations/pubspec.yaml @@ -1,6 +1,6 @@ name: stream_chat_localizations description: The Official localizations for Stream Chat Flutter, a service for building chat applications -version: 5.2.0 +version: 5.3.0 homepage: https://github.com/GetStream/stream-chat-flutter repository: https://github.com/GetStream/stream-chat-flutter issue_tracker: https://github.com/GetStream/stream-chat-flutter/issues @@ -14,7 +14,7 @@ dependencies: sdk: flutter flutter_localizations: sdk: flutter - stream_chat_flutter: ^6.2.0 + stream_chat_flutter: ^6.3.0 dev_dependencies: dart_code_metrics: ^5.7.2 diff --git a/packages/stream_chat_persistence/CHANGELOG.md b/packages/stream_chat_persistence/CHANGELOG.md index 7254a9579..d2b3d075b 100644 --- a/packages/stream_chat_persistence/CHANGELOG.md +++ b/packages/stream_chat_persistence/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.3.0 + +- Updated `stream_chat` dependency to [`6.3.0`](https://pub.dev/packages/stream_chat/changelog). + ## 6.2.0 - Added support for `StreamChatPersistenceClient.isConnected` for checking if the client is connected to the database. diff --git a/packages/stream_chat_persistence/pubspec.yaml b/packages/stream_chat_persistence/pubspec.yaml index 9c5bd9caf..9a1a6148f 100644 --- a/packages/stream_chat_persistence/pubspec.yaml +++ b/packages/stream_chat_persistence/pubspec.yaml @@ -1,7 +1,7 @@ name: stream_chat_persistence homepage: https://github.com/GetStream/stream-chat-flutter description: Official Stream Chat Persistence library. Build your own chat experience using Dart and Flutter. -version: 6.2.0 +version: 6.3.0 repository: https://github.com/GetStream/stream-chat-flutter issue_tracker: https://github.com/GetStream/stream-chat-flutter/issues @@ -18,7 +18,7 @@ dependencies: path: ^1.8.2 path_provider: ^2.0.1 sqlite3_flutter_libs: ^0.5.0 - stream_chat: ^6.2.0 + stream_chat: ^6.3.0 dev_dependencies: build_runner: ^2.3.3 From 77484980a39f6e0d38d9dc894ce0f57d7242beed Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Thu, 8 Jun 2023 18:41:25 +0530 Subject: [PATCH 21/23] chore: fix formatting. Signed-off-by: xsahil03x --- .../stream_chat/lib/src/client/client.dart | 20 +++++++++++-------- .../lib/src/db/chat_persistence_client.dart | 5 ++--- .../src/db/chat_persistence_client_test.dart | 5 ++--- .../lib/src/localization/translations.dart | 2 +- .../lib/src/theme/message_theme.dart | 4 ++-- .../src/stream_chat_persistence_client.dart | 5 ++--- 6 files changed, 21 insertions(+), 20 deletions(-) diff --git a/packages/stream_chat/lib/src/client/client.dart b/packages/stream_chat/lib/src/client/client.dart index 9858b0ea1..c9037e014 100644 --- a/packages/stream_chat/lib/src/client/client.dart +++ b/packages/stream_chat/lib/src/client/client.dart @@ -568,9 +568,8 @@ class StreamChatClient { /// Requests channels with a given query. Stream> queryChannels({ Filter? filter, - @Deprecated(''' - sort has been deprecated. - Please use channelStateSort instead.''') List>? sort, + @Deprecated('Use channelStateSort instead.') + List>? sort, List>? channelStateSort, bool state = true, bool watch = true, @@ -730,7 +729,8 @@ class StreamChatClient { Filter? filter, @Deprecated(''' sort has been deprecated. - Please use channelStateSort instead.''') List>? sort, + Please use channelStateSort instead.''') + List>? sort, List>? channelStateSort, PaginationParams paginationParams = const PaginationParams(), }) async { @@ -1555,12 +1555,16 @@ class ClientState { _eventsSubscription! ..add(_client .on() - .where((event) => - event.me != null && event.type != EventType.healthCheck) + .where((event) { + if (event.type == EventType.notificationMutesUpdated) { + print("notificationMutesUpdated"); + } + return event.me != null && event.type != EventType.healthCheck; + }) .map((e) => e.me!) .listen((user) { - currentUser = currentUser?.merge(user) ?? user; - })) + currentUser = currentUser?.merge(user) ?? user; + })) ..add(_client .on() .map((event) => event.unreadChannels) diff --git a/packages/stream_chat/lib/src/db/chat_persistence_client.dart b/packages/stream_chat/lib/src/db/chat_persistence_client.dart index bf0b1a764..42f650cdf 100644 --- a/packages/stream_chat/lib/src/db/chat_persistence_client.dart +++ b/packages/stream_chat/lib/src/db/chat_persistence_client.dart @@ -102,9 +102,8 @@ abstract class ChatPersistenceClient { /// for filtering out states. Future> getChannelStates({ Filter? filter, - @Deprecated(''' - sort has been deprecated. - Please use channelStateSort instead.''') List>? sort, + @Deprecated('Use channelStateSort instead.') + List>? sort, List>? channelStateSort, PaginationParams? paginationParams, }); diff --git a/packages/stream_chat/test/src/db/chat_persistence_client_test.dart b/packages/stream_chat/test/src/db/chat_persistence_client_test.dart index a0a129357..b9c1407b5 100644 --- a/packages/stream_chat/test/src/db/chat_persistence_client_test.dart +++ b/packages/stream_chat/test/src/db/chat_persistence_client_test.dart @@ -62,9 +62,8 @@ class TestPersistenceClient extends ChatPersistenceClient { @override Future> getChannelStates( {Filter? filter, - @Deprecated(''' - sort has been deprecated. - Please use channelStateSort instead.''') List>? sort, + @Deprecated('Use channelStateSort instead.') + List>? sort, List>? channelStateSort, PaginationParams? paginationParams}) => throw UnimplementedError(); diff --git a/packages/stream_chat_flutter/lib/src/localization/translations.dart b/packages/stream_chat_flutter/lib/src/localization/translations.dart index 71254e734..61c3441a2 100644 --- a/packages/stream_chat_flutter/lib/src/localization/translations.dart +++ b/packages/stream_chat_flutter/lib/src/localization/translations.dart @@ -83,7 +83,7 @@ abstract class Translations { /// in the [StreamMessageListView] String unreadMessagesSeparatorText( @Deprecated('unreadCount is not used anymore and will be removed ') - int unreadCount, + int unreadCount, ); /// The label for "connected" in [StreamConnectionStatusBuilder] diff --git a/packages/stream_chat_flutter/lib/src/theme/message_theme.dart b/packages/stream_chat_flutter/lib/src/theme/message_theme.dart index 6c35c5e34..b997fd4a3 100644 --- a/packages/stream_chat_flutter/lib/src/theme/message_theme.dart +++ b/packages/stream_chat_flutter/lib/src/theme/message_theme.dart @@ -23,7 +23,7 @@ class StreamMessageThemeData with Diagnosticable { this.avatarTheme, this.createdAtStyle, @Deprecated('Use urlAttachmentBackgroundColor instead') - Color? linkBackgroundColor, + Color? linkBackgroundColor, Color? urlAttachmentBackgroundColor, this.urlAttachmentHostStyle, this.urlAttachmentTitleStyle, @@ -102,7 +102,7 @@ class StreamMessageThemeData with Diagnosticable { Color? reactionsBorderColor, Color? reactionsMaskColor, @Deprecated('Use urlAttachmentBackgroundColor instead') - Color? linkBackgroundColor, + Color? linkBackgroundColor, Color? urlAttachmentBackgroundColor, TextStyle? urlAttachmentHostStyle, TextStyle? urlAttachmentTitleStyle, diff --git a/packages/stream_chat_persistence/lib/src/stream_chat_persistence_client.dart b/packages/stream_chat_persistence/lib/src/stream_chat_persistence_client.dart index e8737baa0..8a44239c5 100644 --- a/packages/stream_chat_persistence/lib/src/stream_chat_persistence_client.dart +++ b/packages/stream_chat_persistence/lib/src/stream_chat_persistence_client.dart @@ -251,9 +251,8 @@ class StreamChatPersistenceClient extends ChatPersistenceClient { @override Future> getChannelStates({ Filter? filter, - @Deprecated(''' - sort has been deprecated. - Please use channelStateSort instead.''') List>? sort, + @Deprecated('Use channelStateSort instead.') + List>? sort, List>? channelStateSort, PaginationParams? paginationParams, }) async { From 92c8225018bc54d15bb8e0041992b96e9cfdd358 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Thu, 8 Jun 2023 18:50:36 +0530 Subject: [PATCH 22/23] ci: update flutter version. Signed-off-by: xsahil03x --- .github/workflows/dart_code_metrics.yaml | 2 +- .github/workflows/stream_flutter_workflow.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dart_code_metrics.yaml b/.github/workflows/dart_code_metrics.yaml index 54f9025e3..504173f3d 100644 --- a/.github/workflows/dart_code_metrics.yaml +++ b/.github/workflows/dart_code_metrics.yaml @@ -1,7 +1,7 @@ name: Dart Code Metrics env: - flutter_version: "3.10.0" + flutter_version: "3.10.4" folders: "lib, test" on: diff --git a/.github/workflows/stream_flutter_workflow.yml b/.github/workflows/stream_flutter_workflow.yml index 03c7c49c3..89baee7d9 100644 --- a/.github/workflows/stream_flutter_workflow.yml +++ b/.github/workflows/stream_flutter_workflow.yml @@ -2,7 +2,7 @@ name: stream_flutter_workflow env: ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true' - flutter_version: "3.10.0" + flutter_version: "3.10.4" on: pull_request: @@ -17,7 +17,7 @@ on: branches: - master - develop - + concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true From c533c0dbdfcad13b289cea9d99a30c455a0b9ecc Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Thu, 8 Jun 2023 18:55:32 +0530 Subject: [PATCH 23/23] chore: remove debug code. Signed-off-by: xsahil03x --- packages/stream_chat/lib/src/client/client.dart | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/stream_chat/lib/src/client/client.dart b/packages/stream_chat/lib/src/client/client.dart index c9037e014..f131b12fe 100644 --- a/packages/stream_chat/lib/src/client/client.dart +++ b/packages/stream_chat/lib/src/client/client.dart @@ -1555,16 +1555,12 @@ class ClientState { _eventsSubscription! ..add(_client .on() - .where((event) { - if (event.type == EventType.notificationMutesUpdated) { - print("notificationMutesUpdated"); - } - return event.me != null && event.type != EventType.healthCheck; - }) + .where((event) => + event.me != null && event.type != EventType.healthCheck) .map((e) => e.me!) .listen((user) { - currentUser = currentUser?.merge(user) ?? user; - })) + currentUser = currentUser?.merge(user) ?? user; + })) ..add(_client .on() .map((event) => event.unreadChannels)