@@ -125,6 +125,50 @@ class Unreads extends ChangeNotifier {
125
125
126
126
int countInDmNarrow (DmNarrow narrow) => dms[narrow]? .length ?? 0 ;
127
127
128
+ // TODO(#346): account for muted topics and streams
129
+ int countInAllMessagesNarrow () {
130
+ int c = 0 ;
131
+ for (final messageIds in dms.values) {
132
+ c = c + messageIds.length;
133
+ }
134
+ for (final topics in streams.values) {
135
+ for (final messageIds in topics.values) {
136
+ c = c + messageIds.length;
137
+ }
138
+ }
139
+ return c;
140
+ }
141
+
142
+ // TODO(#346): account for muted topics and streams
143
+ int countInStreamNarrow (StreamNarrow narrow) {
144
+ final topics = streams[narrow.streamId];
145
+ if (topics == null ) return 0 ;
146
+ int c = 0 ;
147
+ for (final messageIds in topics.values) {
148
+ c = c + messageIds.length;
149
+ }
150
+ return c;
151
+ }
152
+
153
+ // TODO(#346): account for muted topics and streams
154
+ int countInTopicNarrow (TopicNarrow narrow) {
155
+ final topics = streams[narrow.streamId];
156
+ return topics? [narrow.topic]? .length ?? 0 ;
157
+ }
158
+
159
+ int countInNarrow (Narrow narrow) {
160
+ switch (narrow) {
161
+ case DmNarrow ():
162
+ return countInDmNarrow (narrow);
163
+ case AllMessagesNarrow ():
164
+ return countInAllMessagesNarrow ();
165
+ case StreamNarrow ():
166
+ return countInStreamNarrow (narrow);
167
+ case TopicNarrow ():
168
+ return countInTopicNarrow (narrow);
169
+ }
170
+ }
171
+
128
172
void handleMessageEvent (MessageEvent event) {
129
173
final message = event.message;
130
174
if (message.flags.contains (MessageFlag .read)) {
0 commit comments