Skip to content

channel: Rename StreamStore to ChannelStore #801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions lib/model/stream.dart → lib/model/channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import '../api/model/events.dart';
import '../api/model/initial_snapshot.dart';
import '../api/model/model.dart';

/// The portion of [PerAccountStore] for streams, topics, and stuff about them.
/// The portion of [PerAccountStore] for channels, topics, and stuff about them.
///
/// This type is useful for expressing the needs of other parts of the
/// implementation of [PerAccountStore], to avoid circularity.
///
/// The data structures described here are implemented at [StreamStoreImpl].
mixin StreamStore {
/// The data structures described here are implemented at [ChannelStoreImpl].
mixin ChannelStore {
Map<int, ZulipStream> get streams;
Map<String, ZulipStream> get streamsByName;
Map<int, Subscription> get subscriptions;
Expand Down Expand Up @@ -67,13 +67,13 @@ mixin StreamStore {
}
}

/// The implementation of [StreamStore] that does the work.
/// The implementation of [ChannelStore] that does the work.
///
/// Generally the only code that should need this class is [PerAccountStore]
/// itself. Other code accesses this functionality through [PerAccountStore],
/// or through the mixin [StreamStore] which describes its interface.
class StreamStoreImpl with StreamStore {
factory StreamStoreImpl({required InitialSnapshot initialSnapshot}) {
/// or through the mixin [ChannelStore] which describes its interface.
class ChannelStoreImpl with ChannelStore {
factory ChannelStoreImpl({required InitialSnapshot initialSnapshot}) {
final subscriptions = Map.fromEntries(initialSnapshot.subscriptions.map(
(subscription) => MapEntry(subscription.streamId, subscription)));

Expand All @@ -92,15 +92,15 @@ class StreamStoreImpl with StreamStore {
forStream[item.topicName] = item.visibilityPolicy;
}

return StreamStoreImpl._(
return ChannelStoreImpl._(
streams: streams,
streamsByName: streams.map((_, stream) => MapEntry(stream.name, stream)),
subscriptions: subscriptions,
topicVisibility: topicVisibility,
);
}

StreamStoreImpl._({
ChannelStoreImpl._({
required this.streams,
required this.streamsByName,
required this.subscriptions,
Expand Down
4 changes: 2 additions & 2 deletions lib/model/internal_link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:json_annotation/json_annotation.dart';
import '../api/model/narrow.dart';
import 'narrow.dart';
import 'store.dart';
import 'stream.dart';
import 'channel.dart';

part 'internal_link.g.dart';

Expand Down Expand Up @@ -245,7 +245,7 @@ enum _NarrowOperator {
///
/// Returns null if the operand has an unexpected shape, or has the old shape
/// (stream name but no ID) and we don't know of a stream by the given name.
int? _parseStreamOperand(String operand, StreamStore store) {
int? _parseStreamOperand(String operand, ChannelStore store) {
// "New" (2018) format: ${stream_id}-${stream_name} .
final match = RegExp(r'^(\d+)(?:-.*)?$').firstMatch(operand);
final newFormatStreamId = (match != null) ? int.parse(match.group(1)!, radix: 10) : null;
Expand Down
32 changes: 16 additions & 16 deletions lib/model/store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import 'database.dart';
import 'message.dart';
import 'message_list.dart';
import 'recent_dm_conversations.dart';
import 'stream.dart';
import 'channel.dart';
import 'typing_status.dart';
import 'unreads.dart';

Expand Down Expand Up @@ -201,7 +201,7 @@ abstract class GlobalStore extends ChangeNotifier {
/// This class does not attempt to poll an event queue
/// to keep the data up to date. For that behavior, see
/// [UpdateMachine].
class PerAccountStore extends ChangeNotifier with StreamStore, MessageStore {
class PerAccountStore extends ChangeNotifier with ChannelStore, MessageStore {
/// Construct a store for the user's data, starting from the given snapshot.
///
/// The global store must already have been updated with
Expand All @@ -226,7 +226,7 @@ class PerAccountStore extends ChangeNotifier with StreamStore, MessageStore {
connection ??= globalStore.apiConnectionFromAccount(account);
assert(connection.zulipFeatureLevel == account.zulipFeatureLevel);

final streams = StreamStoreImpl(initialSnapshot: initialSnapshot);
final channels = ChannelStoreImpl(initialSnapshot: initialSnapshot);
return PerAccountStore._(
globalStore: globalStore,
connection: connection,
Expand All @@ -247,12 +247,12 @@ class PerAccountStore extends ChangeNotifier with StreamStore, MessageStore {
selfUserId: account.userId,
typingStartedExpiryPeriod: Duration(milliseconds: initialSnapshot.serverTypingStartedExpiryPeriodMilliseconds),
),
streams: streams,
channels: channels,
messages: MessageStoreImpl(),
unreads: Unreads(
initial: initialSnapshot.unreadMsgs,
selfUserId: account.userId,
streamStore: streams,
channelStore: channels,
),
recentDmConversationsView: RecentDmConversationsView(
initial: initialSnapshot.recentPrivateConversations, selfUserId: account.userId),
Expand All @@ -272,15 +272,15 @@ class PerAccountStore extends ChangeNotifier with StreamStore, MessageStore {
required this.userSettings,
required this.users,
required this.typingStatus,
required StreamStoreImpl streams,
required ChannelStoreImpl channels,
required MessageStoreImpl messages,
required this.unreads,
required this.recentDmConversationsView,
}) : assert(selfUserId == globalStore.getAccount(accountId)!.userId),
assert(realmUrl == globalStore.getAccount(accountId)!.realmUrl),
assert(realmUrl == connection.realmUrl),
_globalStore = globalStore,
_streams = streams,
_channels = channels,
_messages = messages;

////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -331,19 +331,19 @@ class PerAccountStore extends ChangeNotifier with StreamStore, MessageStore {
// Streams, topics, and stuff about them.

@override
Map<int, ZulipStream> get streams => _streams.streams;
Map<int, ZulipStream> get streams => _channels.streams;
@override
Map<String, ZulipStream> get streamsByName => _streams.streamsByName;
Map<String, ZulipStream> get streamsByName => _channels.streamsByName;
@override
Map<int, Subscription> get subscriptions => _streams.subscriptions;
Map<int, Subscription> get subscriptions => _channels.subscriptions;
@override
UserTopicVisibilityPolicy topicVisibilityPolicy(int streamId, String topic) =>
_streams.topicVisibilityPolicy(streamId, topic);
_channels.topicVisibilityPolicy(streamId, topic);

final StreamStoreImpl _streams;
final ChannelStoreImpl _channels;

@visibleForTesting
StreamStoreImpl get debugStreamStore => _streams;
ChannelStoreImpl get debugChannelStore => _channels;

////////////////////////////////
// Messages, and summaries of messages.
Expand Down Expand Up @@ -474,17 +474,17 @@ class PerAccountStore extends ChangeNotifier with StreamStore, MessageStore {

case StreamEvent():
assert(debugLog("server event: stream/${event.op}"));
_streams.handleStreamEvent(event);
_channels.handleStreamEvent(event);
notifyListeners();

case SubscriptionEvent():
assert(debugLog("server event: subscription/${event.op}"));
_streams.handleSubscriptionEvent(event);
_channels.handleSubscriptionEvent(event);
notifyListeners();

case UserTopicEvent():
assert(debugLog("server event: user_topic"));
_streams.handleUserTopicEvent(event);
_channels.handleUserTopicEvent(event);
notifyListeners();

case MessageEvent():
Expand Down
20 changes: 10 additions & 10 deletions lib/model/unreads.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import '../api/model/events.dart';
import '../log.dart';
import 'algorithms.dart';
import 'narrow.dart';
import 'stream.dart';
import 'channel.dart';

/// The view-model for unread messages.
///
Expand Down Expand Up @@ -39,7 +39,7 @@ class Unreads extends ChangeNotifier {
factory Unreads({
required UnreadMessagesSnapshot initial,
required int selfUserId,
required StreamStore streamStore,
required ChannelStore channelStore,
}) {
final streams = <int, Map<String, QueueList<int>>>{};
final dms = <DmNarrow, QueueList<int>>{};
Expand All @@ -63,7 +63,7 @@ class Unreads extends ChangeNotifier {
}

return Unreads._(
streamStore: streamStore,
channelStore: channelStore,
streams: streams,
dms: dms,
mentions: mentions,
Expand All @@ -73,15 +73,15 @@ class Unreads extends ChangeNotifier {
}

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

final StreamStore streamStore;
final ChannelStore channelStore;

// TODO excluded for now; would need to handle nuances around muting etc.
// int count;
Expand Down Expand Up @@ -136,7 +136,7 @@ class Unreads extends ChangeNotifier {
}
for (final MapEntry(key: streamId, value: topics) in streams.entries) {
for (final MapEntry(key: topic, value: messageIds) in topics.entries) {
if (streamStore.isTopicVisible(streamId, topic)) {
if (channelStore.isTopicVisible(streamId, topic)) {
c = c + messageIds.length;
}
}
Expand All @@ -145,7 +145,7 @@ class Unreads extends ChangeNotifier {
}

/// The "strict" unread count for this stream,
/// using [StreamStore.isTopicVisible].
/// using [ChannelStore.isTopicVisible].
///
/// If the stream is muted, this will count only topics that are
/// actively unmuted.
Expand All @@ -158,15 +158,15 @@ class Unreads extends ChangeNotifier {
if (topics == null) return 0;
int c = 0;
for (final entry in topics.entries) {
if (streamStore.isTopicVisible(streamId, entry.key)) {
if (channelStore.isTopicVisible(streamId, entry.key)) {
c = c + entry.value.length;
}
}
return c;
}

/// The "broad" unread count for this stream,
/// using [StreamStore.isTopicVisibleInStream].
/// using [ChannelStore.isTopicVisibleInStream].
///
/// This includes topics that have no visibility policy of their own,
/// even if the stream itself is muted.
Expand All @@ -179,7 +179,7 @@ class Unreads extends ChangeNotifier {
if (topics == null) return 0;
int c = 0;
for (final entry in topics.entries) {
if (streamStore.isTopicVisibleInStream(streamId, entry.key)) {
if (channelStore.isTopicVisibleInStream(streamId, entry.key)) {
c = c + entry.value.length;
}
}
Expand Down
10 changes: 5 additions & 5 deletions test/model/stream_test.dart → test/model/channel_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +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/store.dart';
import 'package:zulip/model/stream.dart';
import 'package:zulip/model/channel.dart';

import '../example_data.dart' as eg;
import 'test_store.dart';
Expand All @@ -14,7 +14,7 @@ void main() {
group('Unified stream/sub data', () {
/// Check that `streams`, `streamsByName`, and `subscriptions` all agree
/// and point to the same objects where applicable.
void checkUnified(StreamStore store) {
void checkUnified(ChannelStore store) {
check(store.streamsByName).length.equals(store.streams.length);
for (final MapEntry(key: streamId, value: stream)
in store.streams.entries) {
Expand Down Expand Up @@ -193,8 +193,8 @@ void main() {
final expectedStore = eg.store(initialSnapshot: eg.initialSnapshot(
userTopics: expected,
));
check(store.debugStreamStore.topicVisibility)
.deepEquals(expectedStore.debugStreamStore.topicVisibility);
check(store.debugChannelStore.topicVisibility)
.deepEquals(expectedStore.debugChannelStore.topicVisibility);
}

test('data structure', () {
Expand All @@ -206,7 +206,7 @@ void main() {
eg.userTopicItem(stream2, 'topic 3', UserTopicVisibilityPolicy.unknown),
eg.userTopicItem(stream2, 'topic 4', UserTopicVisibilityPolicy.followed),
]));
check(store.debugStreamStore.topicVisibility).deepEquals({
check(store.debugChannelStore.topicVisibility).deepEquals({
stream1.streamId: {
'topic 1': UserTopicVisibilityPolicy.muted,
'topic 2': UserTopicVisibilityPolicy.unmuted,
Expand Down
2 changes: 1 addition & 1 deletion test/model/store_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void main() {
});

group('PerAccountStore.handleEvent', () {
// Mostly this method just dispatches to StreamStore and MessageStore etc.,
// Mostly this method just dispatches to ChannelStore and MessageStore etc.,
// and so most of the tests live in the test files for those
// (but they call the handleEvent method because it's the entry point).

Expand Down
26 changes: 13 additions & 13 deletions test/model/unreads_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,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 PerAccountStore channelStore; // TODO reduce this to ChannelStore
late int notifiedCount;

void checkNotified({required int count}) {
Expand All @@ -37,10 +37,10 @@ void main() {
oldUnreadsMissing: false,
),
}) {
streamStore = eg.store();
channelStore = eg.store();
notifiedCount = 0;
model = Unreads(initial: initial,
selfUserId: eg.selfUser.userId, streamStore: streamStore)
selfUserId: eg.selfUser.userId, channelStore: channelStore)
..addListener(() {
notifiedCount++;
});
Expand Down Expand Up @@ -157,11 +157,11 @@ void main() {
final stream2 = eg.stream(streamId: 2, name: 'stream 2');
final stream3 = eg.stream(streamId: 3, name: 'stream 3');
prepare();
await streamStore.addStreams([stream1, stream2, stream3]);
await streamStore.addSubscription(eg.subscription(stream1));
await streamStore.addSubscription(eg.subscription(stream2));
await streamStore.addSubscription(eg.subscription(stream3, isMuted: true));
await streamStore.addUserTopic(stream1, 'a', UserTopicVisibilityPolicy.muted);
await channelStore.addStreams([stream1, stream2, stream3]);
await channelStore.addSubscription(eg.subscription(stream1));
await channelStore.addSubscription(eg.subscription(stream2));
await channelStore.addSubscription(eg.subscription(stream3, isMuted: true));
await channelStore.addUserTopic(stream1, 'a', UserTopicVisibilityPolicy.muted);
fillWithMessages([
eg.streamMessage(stream: stream1, topic: 'a', flags: []),
eg.streamMessage(stream: stream1, topic: 'b', flags: []),
Expand All @@ -177,10 +177,10 @@ void main() {
test('countInStream/Narrow', () async {
final stream = eg.stream();
prepare();
await streamStore.addStream(stream);
await streamStore.addSubscription(eg.subscription(stream));
await streamStore.addUserTopic(stream, 'a', UserTopicVisibilityPolicy.unmuted);
await streamStore.addUserTopic(stream, 'c', UserTopicVisibilityPolicy.muted);
await channelStore.addStream(stream);
await channelStore.addSubscription(eg.subscription(stream));
await channelStore.addUserTopic(stream, 'a', UserTopicVisibilityPolicy.unmuted);
await channelStore.addUserTopic(stream, 'c', UserTopicVisibilityPolicy.muted);
fillWithMessages([
eg.streamMessage(stream: stream, topic: 'a', flags: []),
eg.streamMessage(stream: stream, topic: 'a', flags: []),
Expand All @@ -192,7 +192,7 @@ void main() {
check(model.countInStream (stream.streamId)).equals(5);
check(model.countInStreamNarrow(stream.streamId)).equals(5);

await streamStore.handleEvent(SubscriptionUpdateEvent(id: 1,
await channelStore.handleEvent(SubscriptionUpdateEvent(id: 1,
streamId: stream.streamId,
property: SubscriptionProperty.isMuted, value: true));
check(model.countInStream (stream.streamId)).equals(2);
Expand Down