Skip to content

Commit 57ef90f

Browse files
committed
unreads [nfc]: Factor out countInAllDms, for public use and as a helper
1 parent 3ae958e commit 57ef90f

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

lib/model/unreads.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,7 @@ class Unreads extends PerAccountStoreBase with ChangeNotifier {
160160
// TODO(#370): maintain this count incrementally, rather than recomputing from scratch
161161
int countInCombinedFeedNarrow() {
162162
int c = 0;
163-
for (final messageIds in dms.values) {
164-
c = c + messageIds.length;
165-
}
163+
c += countInAllDms();
166164
for (final MapEntry(key: streamId, value: topics) in streams.entries) {
167165
for (final MapEntry(key: topic, value: messageIds) in topics.entries) {
168166
if (channelStore.isTopicVisible(streamId, topic)) {
@@ -230,6 +228,14 @@ class Unreads extends PerAccountStoreBase with ChangeNotifier {
230228
// TODO: Implement unreads handling?
231229
int countInKeywordSearchNarrow() => 0;
232230

231+
int countInAllDms() {
232+
int c = 0;
233+
for (final messageIds in dms.values) {
234+
c += messageIds.length;
235+
}
236+
return c;
237+
}
238+
233239
int countInNarrow(Narrow narrow) {
234240
switch (narrow) {
235241
case CombinedFeedNarrow():

test/model/unreads_test.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,16 @@ void main() {
271271
]);
272272
check(model.countInStarredMessagesNarrow()).equals(0);
273273
});
274+
275+
test('countInAllDms', () async {
276+
prepare();
277+
fillWithMessages([
278+
eg.dmMessage(from: eg.otherUser, to: [eg.selfUser], flags: []),
279+
eg.dmMessage(from: eg.thirdUser, to: [eg.selfUser], flags: []),
280+
eg.dmMessage(from: eg.thirdUser, to: [eg.selfUser, eg.otherUser], flags: []),
281+
]);
282+
check(model.countInCombinedFeedNarrow()).equals(3);
283+
});
274284
});
275285

276286
group('isUnread', () {

0 commit comments

Comments
 (0)