Skip to content

Commit

Permalink
unread [nfc]: Give Unreads a reference to StreamStore
Browse files Browse the repository at this point in the history
  • Loading branch information
gnprice committed Dec 19, 2023
1 parent 60ac70c commit 7be6130
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
9 changes: 7 additions & 2 deletions lib/model/store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class PerAccountStore extends ChangeNotifier with StreamStore {
required ApiConnection connection,
required InitialSnapshot initialSnapshot,
}) {
final streams = StreamStoreImpl(initialSnapshot: initialSnapshot);
return PerAccountStore._(
account: account,
connection: connection,
Expand All @@ -162,13 +163,17 @@ class PerAccountStore extends ChangeNotifier with StreamStore {
realmEmoji: initialSnapshot.realmEmoji,
customProfileFields: _sortCustomProfileFields(initialSnapshot.customProfileFields),
userSettings: initialSnapshot.userSettings,
unreads: Unreads(initial: initialSnapshot.unreadMsgs, selfUserId: account.userId),
unreads: Unreads(
initial: initialSnapshot.unreadMsgs,
selfUserId: account.userId,
streamStore: streams,
),
users: Map.fromEntries(
initialSnapshot.realmUsers
.followedBy(initialSnapshot.realmNonActiveUsers)
.followedBy(initialSnapshot.crossRealmBots)
.map((user) => MapEntry(user.userId, user))),
streams: StreamStoreImpl(initialSnapshot: initialSnapshot),
streams: streams,
recentDmConversationsView: RecentDmConversationsView(
initial: initialSnapshot.recentPrivateConversations, selfUserId: account.userId),
);
Expand Down
11 changes: 10 additions & 1 deletion lib/model/unreads.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import '../api/model/events.dart';
import '../log.dart';
import 'algorithms.dart';
import 'narrow.dart';
import 'stream.dart';

/// The view-model for unread messages.
///
Expand Down Expand Up @@ -39,7 +40,11 @@ import 'narrow.dart';
// TODO When loading a message list with stream messages, check all the stream
// messages and refresh [mentions] (see [mentions] dartdoc).
class Unreads extends ChangeNotifier {
factory Unreads({required UnreadMessagesSnapshot initial, required selfUserId}) {
factory Unreads({
required UnreadMessagesSnapshot initial,
required selfUserId,
required StreamStore streamStore,
}) {
final streams = <int, Map<String, QueueList<int>>>{};
final dms = <DmNarrow, QueueList<int>>{};
final mentions = Set.of(initial.mentions);
Expand All @@ -62,6 +67,7 @@ class Unreads extends ChangeNotifier {
}

return Unreads._(
streamStore: streamStore,
streams: streams,
dms: dms,
mentions: mentions,
Expand All @@ -71,13 +77,16 @@ class Unreads extends ChangeNotifier {
}

Unreads._({
required this.streamStore,
required this.streams,
required this.dms,
required this.mentions,
required this.oldUnreadsMissing,
required this.selfUserId,
});

final StreamStore streamStore;

// TODO excluded for now; would need to handle nuances around muting etc.
// int count;

Expand Down
6 changes: 5 additions & 1 deletion test/model/unreads_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:zulip/api/model/events.dart';
import 'package:zulip/api/model/initial_snapshot.dart';
import 'package:zulip/api/model/model.dart';
import 'package:zulip/model/narrow.dart';
import 'package:zulip/model/store.dart';
import 'package:zulip/model/unreads.dart';

import '../example_data.dart' as eg;
Expand All @@ -14,6 +15,7 @@ void main() {
// These variables are the common state operated on by each test.
// Each test case calls [prepare] to initialize them.
late Unreads model;
late PerAccountStore streamStore; // TODO reduce this to StreamStore
late int notifiedCount;

void checkNotified({required int count}) {
Expand All @@ -34,8 +36,10 @@ void main() {
oldUnreadsMissing: false,
),
}) {
streamStore = eg.store();
notifiedCount = 0;
model = Unreads(initial: initial, selfUserId: eg.selfUser.userId)
model = Unreads(initial: initial,
selfUserId: eg.selfUser.userId, streamStore: streamStore)
..addListener(() {
notifiedCount++;
});
Expand Down

0 comments on commit 7be6130

Please sign in to comment.