Skip to content

Commit db7324b

Browse files
gnpricechrisbobbe
authored andcommitted
channel [nfc]: Expose debugTopicVisibility directly on store
This follows the pattern we generally use for other members of ChannelStore and MessageStore, and lets us eliminate the getter returning a ChannelStoreImpl. This pattern -- exposing all the data as members directly on the overall PerAccountStore, delegating to the underlying channel store and message store as needed -- is convenient because it means that code consuming the store doesn't have to worry about which sub-area of the store we've organized a given piece of data into: it's all just methods on the store. Noticed this was here while reviewing a PR that included a new similar deviation from this pattern: zulip#909 (comment)
1 parent 4929412 commit db7324b

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

lib/model/channel.dart

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'package:flutter/foundation.dart';
2+
13
import '../api/model/events.dart';
24
import '../api/model/initial_snapshot.dart';
35
import '../api/model/model.dart';
@@ -41,6 +43,16 @@ mixin ChannelStore {
4143
/// [isTopicVisibleInStream] and [isTopicVisible].
4244
UserTopicVisibilityPolicy topicVisibilityPolicy(int streamId, String topic);
4345

46+
/// The raw data structure underlying [topicVisibilityPolicy].
47+
///
48+
/// This is sometimes convenient for checks in tests.
49+
/// It differs from [topicVisibilityPolicy] in on the one hand omitting
50+
/// all topics where the value would be [UserTopicVisibilityPolicy.none],
51+
/// and on the other hand being a concrete, finite data structure that
52+
/// can be compared using `deepEquals`.
53+
@visibleForTesting
54+
Map<int, Map<String, UserTopicVisibilityPolicy>> get debugTopicVisibility;
55+
4456
/// Whether this topic should appear when already focusing on its stream.
4557
///
4658
/// This is determined purely by the user's visibility policy for the topic.
@@ -191,6 +203,9 @@ class ChannelStoreImpl with ChannelStore {
191203
@override
192204
final Map<int, Subscription> subscriptions;
193205

206+
@override
207+
Map<int, Map<String, UserTopicVisibilityPolicy>> get debugTopicVisibility => topicVisibility;
208+
194209
final Map<int, Map<String, UserTopicVisibilityPolicy>> topicVisibility;
195210

196211
@override

lib/model/store.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -355,12 +355,12 @@ class PerAccountStore extends ChangeNotifier with ChannelStore, MessageStore {
355355
@override
356356
UserTopicVisibilityPolicy topicVisibilityPolicy(int streamId, String topic) =>
357357
_channels.topicVisibilityPolicy(streamId, topic);
358+
@override
359+
Map<int, Map<String, UserTopicVisibilityPolicy>> get debugTopicVisibility =>
360+
_channels.debugTopicVisibility;
358361

359362
final ChannelStoreImpl _channels;
360363

361-
@visibleForTesting
362-
ChannelStoreImpl get debugChannelStore => _channels;
363-
364364
////////////////////////////////
365365
// Messages, and summaries of messages.
366366

test/model/channel_test.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ void main() {
295295
final expectedStore = eg.store(initialSnapshot: eg.initialSnapshot(
296296
userTopics: expected,
297297
));
298-
check(store.debugChannelStore.topicVisibility)
299-
.deepEquals(expectedStore.debugChannelStore.topicVisibility);
298+
check(store.debugTopicVisibility)
299+
.deepEquals(expectedStore.debugTopicVisibility);
300300
}
301301

302302
test('data structure', () {
@@ -308,7 +308,7 @@ void main() {
308308
eg.userTopicItem(stream2, 'topic 3', UserTopicVisibilityPolicy.unknown),
309309
eg.userTopicItem(stream2, 'topic 4', UserTopicVisibilityPolicy.followed),
310310
]));
311-
check(store.debugChannelStore.topicVisibility).deepEquals({
311+
check(store.debugTopicVisibility).deepEquals({
312312
stream1.streamId: {
313313
'topic 1': UserTopicVisibilityPolicy.muted,
314314
'topic 2': UserTopicVisibilityPolicy.unmuted,

0 commit comments

Comments
 (0)