fix(llc): Fix unread count not updating when the current user is set.
Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
@@ -14,6 +14,10 @@
|
|||||||
|
|
||||||
- Added `Filter.contains` and `Filter.empty`
|
- Added `Filter.contains` and `Filter.empty`
|
||||||
|
|
||||||
|
🐞 Fixed
|
||||||
|
|
||||||
|
- [[#659]](https://github.com/GetStream/stream-chat-flutter/issues/659) Fixed unread count not updating correctly.
|
||||||
|
|
||||||
## 2.2.1
|
## 2.2.1
|
||||||
|
|
||||||
🐞 Fixed
|
🐞 Fixed
|
||||||
|
|||||||
@@ -1366,16 +1366,7 @@ class ClientState {
|
|||||||
.where((event) =>
|
.where((event) =>
|
||||||
event.me != null && event.type != EventType.healthCheck)
|
event.me != null && event.type != EventType.healthCheck)
|
||||||
.map((e) => e.me!)
|
.map((e) => e.me!)
|
||||||
.listen((user) {
|
.listen((user) => currentUser = currentUser?.merge(user) ?? user),
|
||||||
currentUser = currentUser?.merge(user) ?? user;
|
|
||||||
final totalUnreadCount = user.totalUnreadCount;
|
|
||||||
_totalUnreadCountController.add(totalUnreadCount);
|
|
||||||
|
|
||||||
final unreadChannels = user.unreadChannels;
|
|
||||||
if (unreadChannels != null) {
|
|
||||||
_unreadChannelsController.add(unreadChannels);
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
_client
|
_client
|
||||||
.on()
|
.on()
|
||||||
.map((event) => event.unreadChannels)
|
.map((event) => event.unreadChannels)
|
||||||
@@ -1441,6 +1432,7 @@ class ClientState {
|
|||||||
/// Sets the user currently interacting with the client
|
/// Sets the user currently interacting with the client
|
||||||
/// note: this fully overrides the [currentUser]
|
/// note: this fully overrides the [currentUser]
|
||||||
set currentUser(OwnUser? user) {
|
set currentUser(OwnUser? user) {
|
||||||
|
_computeUnreadCounts(user);
|
||||||
_currentUserController.add(user);
|
_currentUserController.add(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1506,6 +1498,18 @@ class ClientState {
|
|||||||
_channelsController.add(newChannels);
|
_channelsController.add(newChannels);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _computeUnreadCounts(OwnUser? user) {
|
||||||
|
final totalUnreadCount = user?.totalUnreadCount;
|
||||||
|
if (totalUnreadCount != null) {
|
||||||
|
_totalUnreadCountController.add(totalUnreadCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
final unreadChannels = user?.unreadChannels;
|
||||||
|
if (unreadChannels != null) {
|
||||||
|
_unreadChannelsController.add(unreadChannels);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final _channelsController = BehaviorSubject<Map<String, Channel>>.seeded({});
|
final _channelsController = BehaviorSubject<Map<String, Channel>>.seeded({});
|
||||||
final _currentUserController = BehaviorSubject<OwnUser?>();
|
final _currentUserController = BehaviorSubject<OwnUser?>();
|
||||||
final _usersController = BehaviorSubject<Map<String, User>>.seeded({});
|
final _usersController = BehaviorSubject<Map<String, User>>.seeded({});
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class OwnUser extends User {
|
|||||||
this.devices = const [],
|
this.devices = const [],
|
||||||
this.mutes = const [],
|
this.mutes = const [],
|
||||||
this.totalUnreadCount = 0,
|
this.totalUnreadCount = 0,
|
||||||
this.unreadChannels,
|
this.unreadChannels = 0,
|
||||||
this.channelMutes = const [],
|
this.channelMutes = const [],
|
||||||
required String id,
|
required String id,
|
||||||
String? role,
|
String? role,
|
||||||
@@ -151,8 +151,8 @@ class OwnUser extends User {
|
|||||||
final int totalUnreadCount;
|
final int totalUnreadCount;
|
||||||
|
|
||||||
/// Total unread channels by the user.
|
/// Total unread channels by the user.
|
||||||
@JsonKey(includeIfNull: false)
|
@JsonKey(includeIfNull: false, defaultValue: 0)
|
||||||
final int? unreadChannels;
|
final int unreadChannels;
|
||||||
|
|
||||||
/// Known top level fields.
|
/// Known top level fields.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ OwnUser _$OwnUserFromJson(Map<String, dynamic> json) {
|
|||||||
.toList() ??
|
.toList() ??
|
||||||
[],
|
[],
|
||||||
totalUnreadCount: json['total_unread_count'] as int? ?? 0,
|
totalUnreadCount: json['total_unread_count'] as int? ?? 0,
|
||||||
unreadChannels: json['unread_channels'] as int?,
|
unreadChannels: json['unread_channels'] as int? ?? 0,
|
||||||
channelMutes: (json['channel_mutes'] as List<dynamic>?)
|
channelMutes: (json['channel_mutes'] as List<dynamic>?)
|
||||||
?.map((e) => Mute.fromJson(e as Map<String, dynamic>))
|
?.map((e) => Mute.fromJson(e as Map<String, dynamic>))
|
||||||
.toList() ??
|
.toList() ??
|
||||||
|
|||||||
@@ -2313,5 +2313,27 @@ void main() {
|
|||||||
)).called(1);
|
)).called(1);
|
||||||
verifyNoMoreInteractions(api.message);
|
verifyNoMoreInteractions(api.message);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test(
|
||||||
|
'''setting the `currentUser` should also compute and update the unreadCounts''',
|
||||||
|
() {
|
||||||
|
final state = client.state;
|
||||||
|
final initialUser = OwnUser.fromUser(user);
|
||||||
|
|
||||||
|
expect(state.currentUser, initialUser);
|
||||||
|
expect(state.totalUnreadCount, 0);
|
||||||
|
expect(state.unreadChannels, 0);
|
||||||
|
|
||||||
|
final updateUser = initialUser.copyWith(
|
||||||
|
totalUnreadCount: 33,
|
||||||
|
unreadChannels: 33,
|
||||||
|
);
|
||||||
|
state.currentUser = updateUser;
|
||||||
|
|
||||||
|
expect(state.currentUser, updateUser);
|
||||||
|
expect(state.totalUnreadCount, 33);
|
||||||
|
expect(state.unreadChannels, 33);
|
||||||
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user