Skip to content

Commit c1f662f

Browse files
committed
Adds notifivation feed group meta request
The new model `NotificationFeedMeta` adds a way to request only the meta information (unread/unseen) of a notification feed with the smallest possible payload.
1 parent 6743455 commit c1f662f

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

packages/stream_feed/lib/src/client/notification_feed.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:stream_feed/src/core/models/enrichment_flags.dart';
99
import 'package:stream_feed/src/core/models/feed_id.dart';
1010
import 'package:stream_feed/src/core/models/filter.dart';
1111
import 'package:stream_feed/src/core/models/group.dart';
12+
import 'package:stream_feed/src/core/models/notification_feed_meta.dart';
1213
import 'package:stream_feed/src/core/util/default.dart';
1314
import 'package:stream_feed/src/core/util/token_helper.dart';
1415

@@ -98,6 +99,22 @@ class NotificationFeed extends AggregatedFeed {
9899
return data;
99100
}
100101

102+
/// Retrieves unread an unseen count of notification feeds
103+
Future<NotificationFeedMeta> getUnreadUnseenCounts({
104+
Filter? filter,
105+
ActivityMarker? marker,
106+
}) async {
107+
final options = {
108+
'limit': 0,
109+
...filter?.params ?? Default.filter.params,
110+
...marker?.params ?? Default.marker.params,
111+
};
112+
final token = userToken ??
113+
TokenHelper.buildFeedToken(secret!, TokenAction.read, feedId);
114+
final result = await feed.getActivities(token, feedId, options);
115+
return NotificationFeedMeta.fromJson(result.data!);
116+
}
117+
101118
/// Retrieve activities with reaction enrichment
102119
///
103120
/// {@macro filter}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import 'package:json_annotation/json_annotation.dart';
2+
3+
part 'notification_feed_meta.g.dart';
4+
5+
@JsonSerializable(createToJson: false)
6+
class NotificationFeedMeta {
7+
NotificationFeedMeta({
8+
required this.unreadCount,
9+
required this.unseenCount,
10+
});
11+
12+
factory NotificationFeedMeta.fromJson(Map json) =>
13+
_$NotificationFeedMetaFromJson(json);
14+
15+
@JsonKey(name: 'unread')
16+
final int unreadCount;
17+
18+
@JsonKey(name: 'unseen')
19+
final int unseenCount;
20+
}

packages/stream_feed/lib/src/core/models/notification_feed_meta.g.dart

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)