From ea336a4d98f67ff23aa2af03ce7cae087d0bede8 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Mon, 29 Nov 2021 22:13:11 +0530 Subject: [PATCH 1/7] ci(repo): fix melos bs for transitive deps --- .github/workflows/stream_flutter_workflow.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/stream_flutter_workflow.yml b/.github/workflows/stream_flutter_workflow.yml index b91dcb85..e3d7d231 100644 --- a/.github/workflows/stream_flutter_workflow.yml +++ b/.github/workflows/stream_flutter_workflow.yml @@ -3,6 +3,7 @@ name: stream_flutter_workflow env: ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true' flutter_version: "2.5.1" + melos_version: "1.0.0-dev.10" on: pull_request: @@ -31,7 +32,7 @@ jobs: flutter-version: ${{ env.flutter_version }} - name: "Install Tools" run: | - flutter pub global activate melos 1.0.0-dev.10 + flutter pub global activate melos ${{ env.melos_version }} - name: "Bootstrap Workspace" run: melos bootstrap - name: "Dart Analyze" @@ -60,7 +61,8 @@ jobs: with: flutter-version: ${{ env.flutter_version }} - name: "Install Tools" - run: flutter pub global activate melos + run: | + flutter pub global activate melos ${{ env.melos_version }} - name: "Bootstrap Workspace" run: melos bootstrap - name: "Melos Format" @@ -88,7 +90,7 @@ jobs: flutter-version: ${{ env.flutter_version }} - name: "Install Tools" run: | - flutter pub global activate melos + flutter pub global activate melos ${{ env.melos_version }} pub global activate remove_from_coverage - name: "Bootstrap Workspace" run: melos bootstrap @@ -120,4 +122,4 @@ jobs: uses: VeryGoodOpenSource/very_good_coverage@v1.1.1 with: path: packages/stream_chat_flutter/coverage/lcov.info - min_coverage: 67 \ No newline at end of file + min_coverage: 67 From 1e49156618f2ea20e3d593500e06e6764479146d Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Mon, 29 Nov 2021 22:56:02 +0530 Subject: [PATCH 2/7] test(core): fix failing tests Signed-off-by: xsahil03x --- .../stream_chat_flutter_core/lib/src/channel_list_core.dart | 5 +---- .../test/channel_list_core_test.dart | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/stream_chat_flutter_core/lib/src/channel_list_core.dart b/packages/stream_chat_flutter_core/lib/src/channel_list_core.dart index 51467ca3..d807091c 100644 --- a/packages/stream_chat_flutter_core/lib/src/channel_list_core.dart +++ b/packages/stream_chat_flutter_core/lib/src/channel_list_core.dart @@ -157,10 +157,7 @@ class ChannelListCoreState extends State { presence: widget.presence, memberLimit: widget.memberLimit, messageLimit: widget.messageLimit, - paginationParams: PaginationParams( - limit: widget.limit, - offset: 0, - ), + paginationParams: PaginationParams(limit: widget.limit, offset: 0), ); /// Fetches more channels with updated pagination and updates the widget diff --git a/packages/stream_chat_flutter_core/test/channel_list_core_test.dart b/packages/stream_chat_flutter_core/test/channel_list_core_test.dart index 88711647..5f7c0e03 100644 --- a/packages/stream_chat_flutter_core/test/channel_list_core_test.dart +++ b/packages/stream_chat_flutter_core/test/channel_list_core_test.dart @@ -9,7 +9,7 @@ import 'package:stream_chat_flutter_core/stream_chat_flutter_core.dart'; import 'mocks.dart'; void main() { - const pagination = PaginationParams(limit: 3); + const pagination = PaginationParams(limit: 3, offset: 0); List _generateChannels( StreamChatClient client, { @@ -476,7 +476,7 @@ void main() { _stateSetter?.call(() => limit = 6); final updatedChannels = _generateChannels(mockClient, count: limit); - final updatedPagination = PaginationParams(limit: limit); + final updatedPagination = PaginationParams(limit: limit, offset: 0); when(() => mockClient.queryChannels( filter: any(named: 'filter'), sort: any(named: 'sort'), From 05a9bfeb02d5cd3c69664f2f659ccc9af449e07b Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Mon, 29 Nov 2021 23:33:20 +0530 Subject: [PATCH 3/7] ci(repo): increase test timeout Signed-off-by: xsahil03x --- .github/workflows/stream_flutter_workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/stream_flutter_workflow.yml b/.github/workflows/stream_flutter_workflow.yml index e3d7d231..cc093a31 100644 --- a/.github/workflows/stream_flutter_workflow.yml +++ b/.github/workflows/stream_flutter_workflow.yml @@ -73,7 +73,7 @@ jobs: test: runs-on: macos-latest - timeout-minutes: 15 + timeout-minutes: 20 steps: - name: "Git Checkout" uses: actions/checkout@v2 From 5826074f3d08250ecfd1fc3012196f680b6de1a9 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Tue, 30 Nov 2021 23:38:30 +0530 Subject: [PATCH 4/7] fix(llc): fix user, channel unreadCount Signed-off-by: xsahil03x --- .../stream_chat/lib/src/client/channel.dart | 36 ++++++++++--------- .../stream_chat/lib/src/client/client.dart | 3 ++ 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/packages/stream_chat/lib/src/client/channel.dart b/packages/stream_chat/lib/src/client/channel.dart index 1bba9c84..af0703f2 100644 --- a/packages/stream_chat/lib/src/client/channel.dart +++ b/packages/stream_chat/lib/src/client/channel.dart @@ -1466,8 +1466,6 @@ class ChannelClientState { _listenMemberRemoved(); - _computeUnread(); - _startCleaning(); _startCleaningPinnedMessages(); @@ -1490,15 +1488,6 @@ class ChannelClientState { final _subscriptions = []; - void _computeUnread() { - final userRead = channelState.read.firstWhereOrNull( - (r) => r.user.id == _channel._client.state.currentUser?.id, - ); - if (userRead != null && userRead.unreadMessages > 0) { - unreadCount = userRead.unreadMessages; - } - } - void _checkExpiredAttachmentMessages(ChannelState channelState) async { final expiredAttachmentMessagesId = channelState.messages .where((m) => @@ -1850,15 +1839,31 @@ class ChannelClientState { /// Channel read list as a stream. Stream> get readStream => channelStateStream.map((cs) => cs.read); - final BehaviorSubject _unreadCountController = BehaviorSubject.seeded(0); + bool _isCurrentUserRead(Read read) => + read.user.id == _channel._client.state.currentUser!.id; - set unreadCount(int value) => _unreadCountController.add(value); + /// Channel read for the logged in user. + Read? get currentUserRead => read.firstWhereOrNull(_isCurrentUserRead); + + /// Channel read for the logged in user as a stream. + Stream get currentUserReadStream => + readStream.map((read) => read.firstWhereOrNull(_isCurrentUserRead)); /// Unread count getter as a stream. - Stream get unreadCountStream => _unreadCountController.stream.distinct(); + Stream get unreadCountStream => + currentUserReadStream.map((read) => read?.unreadMessages ?? 0); /// Unread count getter. - int get unreadCount => _unreadCountController.value; + int get unreadCount => currentUserRead?.unreadMessages ?? 0; + + /// Setter for unread count. + set unreadCount(int count) { + final reads = [..._channelState.read]; + final currentUserReadIndex = reads.indexWhere(_isCurrentUserRead); + reads[currentUserReadIndex] = + reads[currentUserReadIndex].copyWith(unreadMessages: count); + _channelState = _channelState.copyWith(read: reads); + } bool _countMessageAsUnread(Message message) { final userId = _channel.client.state.currentUser?.id; @@ -2118,7 +2123,6 @@ class ChannelClientState { /// Call this method to dispose this object. void dispose() { _debouncedUpdatePersistenceChannelState.cancel(); - _unreadCountController.close(); _retryQueue.dispose(); _subscriptions.forEach((s) => s.cancel()); _channelStateController.close(); diff --git a/packages/stream_chat/lib/src/client/client.dart b/packages/stream_chat/lib/src/client/client.dart index 623fa41c..29e500ce 100644 --- a/packages/stream_chat/lib/src/client/client.dart +++ b/packages/stream_chat/lib/src/client/client.dart @@ -395,6 +395,9 @@ class StreamChatClient { } void _handleHealthCheckEvent(Event event) { + final user = event.me; + if (user != null) state.currentUser = user; + final connectionId = event.connectionId; if (connectionId != null) { _connectionIdManager.setConnectionId(connectionId); From 9315b13a04cdc25b256dc923401f8671de6d882f Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Tue, 30 Nov 2021 23:41:18 +0530 Subject: [PATCH 5/7] chore(llc): 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 f5b78e2e..d27ac852 100644 --- a/packages/stream_chat/CHANGELOG.md +++ b/packages/stream_chat/CHANGELOG.md @@ -1,3 +1,10 @@ +## Upcoming + +🐞 Fixed + +- [[#799]](https://github.com/GetStream/stream-chat-flutter/issues/799) Fixed `totalUnreadCount` is not updating when + app is resumed from background mode + ## 3.3.0 ✅ Added From e5a1a74f072735778bd3ad192e442bb06c6a5775 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Wed, 1 Dec 2021 01:10:18 +0530 Subject: [PATCH 6/7] chore(llc): add index check in unreadCount setter. Signed-off-by: xsahil03x --- packages/stream_chat/lib/src/client/channel.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/stream_chat/lib/src/client/channel.dart b/packages/stream_chat/lib/src/client/channel.dart index af0703f2..657b8617 100644 --- a/packages/stream_chat/lib/src/client/channel.dart +++ b/packages/stream_chat/lib/src/client/channel.dart @@ -1860,6 +1860,9 @@ class ChannelClientState { set unreadCount(int count) { final reads = [..._channelState.read]; final currentUserReadIndex = reads.indexWhere(_isCurrentUserRead); + + if (currentUserReadIndex < 0) return; + reads[currentUserReadIndex] = reads[currentUserReadIndex].copyWith(unreadMessages: count); _channelState = _channelState.copyWith(read: reads); From 10115df9cdef1deadd963d310393a17ba140cd32 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Thu, 2 Dec 2021 12:37:48 +0100 Subject: [PATCH 7/7] fix(ui): update core dependency --- packages/stream_chat_flutter/CHANGELOG.md | 2 +- packages/stream_chat_flutter/pubspec.yaml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/stream_chat_flutter/CHANGELOG.md b/packages/stream_chat_flutter/CHANGELOG.md index 1904e48d..620ff07b 100644 --- a/packages/stream_chat_flutter/CHANGELOG.md +++ b/packages/stream_chat_flutter/CHANGELOG.md @@ -1,4 +1,4 @@ -## 3.3.0 +## 3.3.1 ✅ Added diff --git a/packages/stream_chat_flutter/pubspec.yaml b/packages/stream_chat_flutter/pubspec.yaml index 13300b2c..40894d3a 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: 3.3.0 +version: 3.3.1 repository: https://github.com/GetStream/stream-chat-flutter issue_tracker: https://github.com/GetStream/stream-chat-flutter/issues @@ -36,7 +36,7 @@ dependencies: rxdart: ^0.27.0 share_plus: ^3.0.4 shimmer: ^2.0.0 - stream_chat_flutter_core: ^3.2.0 + stream_chat_flutter_core: ^3.3.0 substring_highlight: ^1.0.26 synchronized: ^3.0.0 url_launcher: ^6.0.3