fix(llc): Fix unread count not updating when the current user is set.
Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
@@ -1366,16 +1366,7 @@ class ClientState {
|
||||
.where((event) =>
|
||||
event.me != null && event.type != EventType.healthCheck)
|
||||
.map((e) => e.me!)
|
||||
.listen((user) {
|
||||
currentUser = currentUser?.merge(user) ?? user;
|
||||
final totalUnreadCount = user.totalUnreadCount;
|
||||
_totalUnreadCountController.add(totalUnreadCount);
|
||||
|
||||
final unreadChannels = user.unreadChannels;
|
||||
if (unreadChannels != null) {
|
||||
_unreadChannelsController.add(unreadChannels);
|
||||
}
|
||||
}),
|
||||
.listen((user) => currentUser = currentUser?.merge(user) ?? user),
|
||||
_client
|
||||
.on()
|
||||
.map((event) => event.unreadChannels)
|
||||
@@ -1441,6 +1432,7 @@ class ClientState {
|
||||
/// Sets the user currently interacting with the client
|
||||
/// note: this fully overrides the [currentUser]
|
||||
set currentUser(OwnUser? user) {
|
||||
_computeUnreadCounts(user);
|
||||
_currentUserController.add(user);
|
||||
}
|
||||
|
||||
@@ -1506,6 +1498,18 @@ class ClientState {
|
||||
_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 _currentUserController = BehaviorSubject<OwnUser?>();
|
||||
final _usersController = BehaviorSubject<Map<String, User>>.seeded({});
|
||||
|
||||
@@ -17,7 +17,7 @@ class OwnUser extends User {
|
||||
this.devices = const [],
|
||||
this.mutes = const [],
|
||||
this.totalUnreadCount = 0,
|
||||
this.unreadChannels,
|
||||
this.unreadChannels = 0,
|
||||
this.channelMutes = const [],
|
||||
required String id,
|
||||
String? role,
|
||||
@@ -151,8 +151,8 @@ class OwnUser extends User {
|
||||
final int totalUnreadCount;
|
||||
|
||||
/// Total unread channels by the user.
|
||||
@JsonKey(includeIfNull: false)
|
||||
final int? unreadChannels;
|
||||
@JsonKey(includeIfNull: false, defaultValue: 0)
|
||||
final int unreadChannels;
|
||||
|
||||
/// Known top level fields.
|
||||
///
|
||||
|
||||
@@ -17,7 +17,7 @@ OwnUser _$OwnUserFromJson(Map<String, dynamic> json) {
|
||||
.toList() ??
|
||||
[],
|
||||
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>?)
|
||||
?.map((e) => Mute.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
|
||||
Reference in New Issue
Block a user