Merge pull request #801 from GetStream/fix/unread-count
fix(llc): totalUnreadCount is not updating when app is resumed from background mode
This commit is contained in:
@@ -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
|
## 3.3.0
|
||||||
|
|
||||||
✅ Added
|
✅ Added
|
||||||
|
|||||||
@@ -1466,8 +1466,6 @@ class ChannelClientState {
|
|||||||
|
|
||||||
_listenMemberRemoved();
|
_listenMemberRemoved();
|
||||||
|
|
||||||
_computeUnread();
|
|
||||||
|
|
||||||
_startCleaning();
|
_startCleaning();
|
||||||
|
|
||||||
_startCleaningPinnedMessages();
|
_startCleaningPinnedMessages();
|
||||||
@@ -1490,15 +1488,6 @@ class ChannelClientState {
|
|||||||
|
|
||||||
final _subscriptions = <StreamSubscription>[];
|
final _subscriptions = <StreamSubscription>[];
|
||||||
|
|
||||||
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 {
|
void _checkExpiredAttachmentMessages(ChannelState channelState) async {
|
||||||
final expiredAttachmentMessagesId = channelState.messages
|
final expiredAttachmentMessagesId = channelState.messages
|
||||||
.where((m) =>
|
.where((m) =>
|
||||||
@@ -1850,15 +1839,34 @@ class ChannelClientState {
|
|||||||
/// Channel read list as a stream.
|
/// Channel read list as a stream.
|
||||||
Stream<List<Read>> get readStream => channelStateStream.map((cs) => cs.read);
|
Stream<List<Read>> get readStream => channelStateStream.map((cs) => cs.read);
|
||||||
|
|
||||||
final BehaviorSubject<int> _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<Read?> get currentUserReadStream =>
|
||||||
|
readStream.map((read) => read.firstWhereOrNull(_isCurrentUserRead));
|
||||||
|
|
||||||
/// Unread count getter as a stream.
|
/// Unread count getter as a stream.
|
||||||
Stream<int> get unreadCountStream => _unreadCountController.stream.distinct();
|
Stream<int> get unreadCountStream =>
|
||||||
|
currentUserReadStream.map((read) => read?.unreadMessages ?? 0);
|
||||||
|
|
||||||
/// Unread count getter.
|
/// 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);
|
||||||
|
|
||||||
|
if (currentUserReadIndex < 0) return;
|
||||||
|
|
||||||
|
reads[currentUserReadIndex] =
|
||||||
|
reads[currentUserReadIndex].copyWith(unreadMessages: count);
|
||||||
|
_channelState = _channelState.copyWith(read: reads);
|
||||||
|
}
|
||||||
|
|
||||||
bool _countMessageAsUnread(Message message) {
|
bool _countMessageAsUnread(Message message) {
|
||||||
final userId = _channel.client.state.currentUser?.id;
|
final userId = _channel.client.state.currentUser?.id;
|
||||||
@@ -2118,7 +2126,6 @@ class ChannelClientState {
|
|||||||
/// Call this method to dispose this object.
|
/// Call this method to dispose this object.
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_debouncedUpdatePersistenceChannelState.cancel();
|
_debouncedUpdatePersistenceChannelState.cancel();
|
||||||
_unreadCountController.close();
|
|
||||||
_retryQueue.dispose();
|
_retryQueue.dispose();
|
||||||
_subscriptions.forEach((s) => s.cancel());
|
_subscriptions.forEach((s) => s.cancel());
|
||||||
_channelStateController.close();
|
_channelStateController.close();
|
||||||
|
|||||||
@@ -395,6 +395,9 @@ class StreamChatClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _handleHealthCheckEvent(Event event) {
|
void _handleHealthCheckEvent(Event event) {
|
||||||
|
final user = event.me;
|
||||||
|
if (user != null) state.currentUser = user;
|
||||||
|
|
||||||
final connectionId = event.connectionId;
|
final connectionId = event.connectionId;
|
||||||
if (connectionId != null) {
|
if (connectionId != null) {
|
||||||
_connectionIdManager.setConnectionId(connectionId);
|
_connectionIdManager.setConnectionId(connectionId);
|
||||||
|
|||||||
Reference in New Issue
Block a user