Merge pull request #1696 from GetStream/feat/countUnreadMentions

feat(llc): add support for `channel.countUnreadMentions()`.
This commit is contained in:
Sahil Kumar
2023-08-04 18:12:24 +05:30
committed by GitHub
5 changed files with 33 additions and 0 deletions
+7
View File
@@ -1,3 +1,10 @@
## Upcoming
✅ Added
- Added support for `channel.countUnreadMentions()` to get the count of unread messages mentioning the current user on a
channel. [#1692](https://github.com/GetStream/stream-chat-flutter/issues/1692)
## 6.7.0
✅ Added
@@ -2334,6 +2334,26 @@ class ChannelClientState {
!isThreadMessage;
}
/// Counts the number of unread messages mentioning the current user.
///
/// **NOTE**: The method relies on the [Channel.messages] list and doesn't do
/// any API call. Therefore, the count might be not reliable as it relies on
/// the local data.
int countUnreadMentions() {
final lastRead = currentUserRead?.lastRead;
final userId = _channel.client.state.currentUser?.id;
var count = 0;
for (final message in messages) {
if (_countMessageAsUnread(message) &&
(lastRead == null || message.createdAt.isAfter(lastRead)) &&
message.mentionedUsers.any((user) => user.id == userId) == true) {
count++;
}
}
return count;
}
/// Update threads with updated information about messages.
void updateThreadInfo(String parentId, List<Message> messages) {
final newThreads = Map<String, List<Message>>.from(threads);
@@ -1,3 +1,5 @@
// ignore_for_file: invalid_use_of_protected_member
import 'package:dio/dio.dart';
import 'package:stream_chat/src/core/http/interceptor/additional_headers_interceptor.dart';
import 'package:stream_chat/stream_chat.dart';
@@ -1,3 +1,5 @@
// ignore_for_file: invalid_use_of_protected_member
import 'package:dio/dio.dart';
import 'package:mocktail/mocktail.dart';
import 'package:stream_chat/src/core/http/interceptor/auth_interceptor.dart';
@@ -1,3 +1,5 @@
// ignore_for_file: invalid_use_of_protected_member
import 'package:dio/dio.dart';
import 'package:mocktail/mocktail.dart';
import 'package:stream_chat/src/core/http/connection_id_manager.dart';