Skip to content

Commit

Permalink
unreads: Add proposal for countInNarrow
Browse files Browse the repository at this point in the history
  • Loading branch information
sirpengi committed Nov 2, 2023
1 parent f09b8d9 commit 33c0f92
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/model/unreads.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,37 @@ class Unreads extends ChangeNotifier {

int countInDmNarrow(DmNarrow narrow) => dms[narrow]?.length ?? 0;

int countInNarrow(Narrow narrow) {
switch (narrow) {
case DmNarrow():
return dms[narrow]?.length ?? 0;
case AllMessagesNarrow():
int c = 0;
for (final model in dms.values) {
c = c + model.length;
}
for (final streamData in streams.values) {
for (final model in streamData.values) {
c = c + model.length;
}
}
return c;
case StreamNarrow():
final streamData = streams[narrow.streamId];
if (streamData == null) return 0;
int c = 0;
for (final model in streamData.values) {
c = c + model.length;
}
return c;
case TopicNarrow():
final streamData = streams[narrow.streamId];
if (streamData == null) return 0;
final model = streamData[narrow.topic];
return model?.length ?? 0;
}
}

void handleMessageEvent(MessageEvent event) {
final message = event.message;
if (message.flags.contains(MessageFlag.read)) {
Expand Down

0 comments on commit 33c0f92

Please sign in to comment.