diff --git a/lib/model/stream.dart b/lib/model/channel.dart similarity index 94% rename from lib/model/stream.dart rename to lib/model/channel.dart index 887155988d..adaab8ad24 100644 --- a/lib/model/stream.dart +++ b/lib/model/channel.dart @@ -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 get streams; Map get streamsByName; Map get subscriptions; @@ -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))); @@ -92,7 +92,7 @@ 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, @@ -100,7 +100,7 @@ class StreamStoreImpl with StreamStore { ); } - StreamStoreImpl._({ + ChannelStoreImpl._({ required this.streams, required this.streamsByName, required this.subscriptions, diff --git a/lib/model/internal_link.dart b/lib/model/internal_link.dart index cacf8ec3ee..6f617a3786 100644 --- a/lib/model/internal_link.dart +++ b/lib/model/internal_link.dart @@ -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'; @@ -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; diff --git a/lib/model/store.dart b/lib/model/store.dart index af5b4485e5..0b27a91e9e 100644 --- a/lib/model/store.dart +++ b/lib/model/store.dart @@ -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'; @@ -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 @@ -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, @@ -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), @@ -272,7 +272,7 @@ 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, @@ -280,7 +280,7 @@ class PerAccountStore extends ChangeNotifier with StreamStore, MessageStore { assert(realmUrl == globalStore.getAccount(accountId)!.realmUrl), assert(realmUrl == connection.realmUrl), _globalStore = globalStore, - _streams = streams, + _channels = channels, _messages = messages; //////////////////////////////////////////////////////////////// @@ -331,19 +331,19 @@ class PerAccountStore extends ChangeNotifier with StreamStore, MessageStore { // Streams, topics, and stuff about them. @override - Map get streams => _streams.streams; + Map get streams => _channels.streams; @override - Map get streamsByName => _streams.streamsByName; + Map get streamsByName => _channels.streamsByName; @override - Map get subscriptions => _streams.subscriptions; + Map 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. @@ -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(): diff --git a/lib/model/unreads.dart b/lib/model/unreads.dart index 6310141c3b..eccfa4b072 100644 --- a/lib/model/unreads.dart +++ b/lib/model/unreads.dart @@ -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. /// @@ -39,7 +39,7 @@ class Unreads extends ChangeNotifier { factory Unreads({ required UnreadMessagesSnapshot initial, required int selfUserId, - required StreamStore streamStore, + required ChannelStore channelStore, }) { final streams = >>{}; final dms = >{}; @@ -63,7 +63,7 @@ class Unreads extends ChangeNotifier { } return Unreads._( - streamStore: streamStore, + channelStore: channelStore, streams: streams, dms: dms, mentions: mentions, @@ -73,7 +73,7 @@ class Unreads extends ChangeNotifier { } Unreads._({ - required this.streamStore, + required this.channelStore, required this.streams, required this.dms, required this.mentions, @@ -81,7 +81,7 @@ class Unreads extends ChangeNotifier { required this.selfUserId, }); - final StreamStore streamStore; + final ChannelStore channelStore; // TODO excluded for now; would need to handle nuances around muting etc. // int count; @@ -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; } } @@ -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. @@ -158,7 +158,7 @@ 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; } } @@ -166,7 +166,7 @@ class Unreads extends ChangeNotifier { } /// 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. @@ -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; } } diff --git a/test/model/stream_test.dart b/test/model/channel_test.dart similarity index 97% rename from test/model/stream_test.dart rename to test/model/channel_test.dart index d6a2c5df10..d8dc3c07f4 100644 --- a/test/model/stream_test.dart +++ b/test/model/channel_test.dart @@ -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'; @@ -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) { @@ -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', () { @@ -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, diff --git a/test/model/store_test.dart b/test/model/store_test.dart index 3f7cd11af8..06e0fa6851 100644 --- a/test/model/store_test.dart +++ b/test/model/store_test.dart @@ -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). diff --git a/test/model/unreads_test.dart b/test/model/unreads_test.dart index 254333fb1f..4c2bfa5aa5 100644 --- a/test/model/unreads_test.dart +++ b/test/model/unreads_test.dart @@ -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}) { @@ -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++; }); @@ -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: []), @@ -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: []), @@ -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);