Skip to content

Commit

Permalink
narrow: Rename AllMessagesNarrow to CombinedFeedNarrow
Browse files Browse the repository at this point in the history
Fixes: zulip#676
  • Loading branch information
Lalit3716 committed May 21, 2024
1 parent 10d0fe8 commit d07d3d5
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 55 deletions.
2 changes: 1 addition & 1 deletion integration_test/unreadmarker_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void main() {
child: PerAccountStoreWidget(
accountId: eg.selfAccount.id,
placeholder: const LoadingPlaceholderPage(),
child: const MessageListPage(narrow: AllMessagesNarrow())))));
child: const MessageListPage(narrow: CombinedFeedNarrow())))));
await tester.pumpAndSettle();
return messages;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/model/message_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ class MessageListView with ChangeNotifier, _MessageSequence {
/// See also [_allMessagesVisible].
bool _messageVisible(Message message) {
switch (narrow) {
case AllMessagesNarrow():
case CombinedFeedNarrow():
return switch (message) {
StreamMessage() =>
store.isTopicVisible(message.streamId, message.subject),
Expand All @@ -355,7 +355,7 @@ class MessageListView with ChangeNotifier, _MessageSequence {
/// This is useful for an optimization.
bool get _allMessagesVisible {
switch (narrow) {
case AllMessagesNarrow():
case CombinedFeedNarrow():
case StreamNarrow():
return false;

Expand Down
14 changes: 5 additions & 9 deletions lib/model/narrow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,9 @@ sealed class SendableNarrow extends Narrow {
MessageDestination get destination;
}

/// The narrow called "All messages" in the UI.
///
/// This does not literally mean all messages, or even all messages
/// that the user has access to: in particular it excludes muted streams
/// and topics.
class AllMessagesNarrow extends Narrow {
const AllMessagesNarrow();
/// The narrow called "Combined feed" in the UI.
class CombinedFeedNarrow extends Narrow {
const CombinedFeedNarrow();

@override
bool containsMessage(Message message) {
Expand All @@ -57,13 +53,13 @@ class AllMessagesNarrow extends Narrow {

@override
bool operator ==(Object other) {
if (other is! AllMessagesNarrow) return false;
if (other is! CombinedFeedNarrow) return false;
// Conceptually there's only one value of this type.
return true;
}

@override
int get hashCode => 'AllMessagesNarrow'.hashCode;
int get hashCode => 'CombinedFeedNarrow'.hashCode;
}

class StreamNarrow extends Narrow {
Expand Down
2 changes: 1 addition & 1 deletion lib/model/unreads.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class Unreads extends ChangeNotifier {

int countInNarrow(Narrow narrow) {
switch (narrow) {
case AllMessagesNarrow():
case CombinedFeedNarrow():
return countInAllMessagesNarrow();
case StreamNarrow():
return countInStreamNarrow(narrow.streamId);
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class HomePage extends StatelessWidget {
ElevatedButton(
onPressed: () => Navigator.push(context,
MessageListPage.buildRoute(context: context,
narrow: const AllMessagesNarrow())),
narrow: const CombinedFeedNarrow())),
child: Text(zulipLocalizations.combinedFeedPageTitle)),
const SizedBox(height: 16),
ElevatedButton(
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/compose_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ class ComposeBox extends StatelessWidget {
return _FixedDestinationComposeBox(key: controllerKey, narrow: narrow);
} else if (narrow is DmNarrow) {
return _FixedDestinationComposeBox(key: controllerKey, narrow: narrow);
} else if (narrow is AllMessagesNarrow) {
} else if (narrow is CombinedFeedNarrow) {
return const SizedBox.shrink();
} else {
throw Exception("impossible narrow"); // TODO(dart-3): show this statically
Expand Down
12 changes: 6 additions & 6 deletions lib/widgets/message_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class _MessageListPageState extends State<MessageListPage> {
final Color? appBarBackgroundColor;
bool removeAppBarBottomBorder = false;
switch(widget.narrow) {
case AllMessagesNarrow():
case CombinedFeedNarrow():
appBarBackgroundColor = null; // i.e., inherit

case StreamNarrow(:final streamId):
Expand Down Expand Up @@ -106,7 +106,7 @@ class _MessageListPageState extends State<MessageListPage> {
// if those details get complicated, refactor to avoid copying.
// TODO(#311) If we have a bottom nav, it will pad the bottom
// inset, and this should always be true.
removeBottom: widget.narrow is! AllMessagesNarrow,
removeBottom: widget.narrow is! CombinedFeedNarrow,

child: Expanded(
child: MessageList(narrow: widget.narrow))),
Expand Down Expand Up @@ -142,7 +142,7 @@ class MessageListAppBarTitle extends StatelessWidget {
final zulipLocalizations = ZulipLocalizations.of(context);

switch (narrow) {
case AllMessagesNarrow():
case CombinedFeedNarrow():
return Text(zulipLocalizations.combinedFeedPageTitle);

case StreamNarrow(:var streamId):
Expand Down Expand Up @@ -449,7 +449,7 @@ class MarkAsReadWidget extends StatelessWidget {
return;
}
if (!context.mounted) return;
if (narrow is AllMessagesNarrow && !useLegacy) {
if (narrow is CombinedFeedNarrow && !useLegacy) {
PerAccountStoreWidget.of(context).unreads.handleAllMessagesReadSuccess();
}
}
Expand Down Expand Up @@ -509,7 +509,7 @@ class RecipientHeader extends StatelessWidget {
final message = this.message;
return switch (message) {
StreamMessage() => StreamMessageRecipientHeader(message: message,
showStream: narrow is AllMessagesNarrow),
showStream: narrow is CombinedFeedNarrow),
DmMessage() => DmRecipientHeader(message: message),
};
}
Expand Down Expand Up @@ -1082,7 +1082,7 @@ Future<void> _legacyMarkNarrowAsRead(BuildContext context, Narrow narrow) async
final store = PerAccountStoreWidget.of(context);
final connection = store.connection;
switch (narrow) {
case AllMessagesNarrow():
case CombinedFeedNarrow():
await markAllAsRead(connection);
case StreamNarrow(:final streamId):
await markStreamAsRead(connection, streamId: streamId);
Expand Down
10 changes: 5 additions & 5 deletions test/api/route/messages_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void main() {
check(jsonEncode(narrow)).equals(expected);
}

checkNarrow(const AllMessagesNarrow().apiEncode(), jsonEncode([]));
checkNarrow(const CombinedFeedNarrow().apiEncode(), jsonEncode([]));
checkNarrow(const StreamNarrow(12).apiEncode(), jsonEncode([
{'operator': 'stream', 'operand': 12},
]));
Expand Down Expand Up @@ -246,7 +246,7 @@ void main() {
return FakeApiConnection.with_((connection) async {
connection.prepare(json: fakeResult.toJson());
await checkGetMessages(connection,
narrow: const AllMessagesNarrow().apiEncode(),
narrow: const CombinedFeedNarrow().apiEncode(),
anchor: AnchorCode.newest, numBefore: 10, numAfter: 20,
expected: {
'narrow': jsonEncode([]),
Expand Down Expand Up @@ -278,7 +278,7 @@ void main() {
return FakeApiConnection.with_((connection) async {
connection.prepare(json: fakeResult.toJson());
await checkGetMessages(connection,
narrow: const AllMessagesNarrow().apiEncode(),
narrow: const CombinedFeedNarrow().apiEncode(),
anchor: const NumericAnchor(42),
numBefore: 10, numAfter: 20,
expected: {
Expand Down Expand Up @@ -582,7 +582,7 @@ void main() {
await checkUpdateMessageFlagsForNarrow(connection,
anchor: AnchorCode.oldest,
numBefore: 0, numAfter: 20,
narrow: const AllMessagesNarrow().apiEncode(),
narrow: const CombinedFeedNarrow().apiEncode(),
op: UpdateMessageFlagsOp.add, flag: MessageFlag.read,
expected: {
'anchor': 'oldest',
Expand Down Expand Up @@ -622,7 +622,7 @@ void main() {
await checkUpdateMessageFlagsForNarrow(connection,
anchor: const NumericAnchor(42),
numBefore: 0, numAfter: 20,
narrow: const AllMessagesNarrow().apiEncode(),
narrow: const CombinedFeedNarrow().apiEncode(),
op: UpdateMessageFlagsOp.add, flag: MessageFlag.read,
expected: {
'anchor': '42',
Expand Down
10 changes: 5 additions & 5 deletions test/model/autocomplete_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void main() {
});

test('MentionAutocompleteView misc', () async {
const narrow = AllMessagesNarrow();
const narrow = CombinedFeedNarrow();
final store = eg.store()
..addUsers([eg.selfUser, eg.otherUser, eg.thirdUser]);
final view = MentionAutocompleteView.init(store: store, narrow: narrow);
Expand All @@ -183,7 +183,7 @@ void main() {

test('MentionAutocompleteView not starve timers', () {
fakeAsync((binding) {
const narrow = AllMessagesNarrow();
const narrow = CombinedFeedNarrow();
final store = eg.store()
..addUsers([eg.selfUser, eg.otherUser, eg.thirdUser]);
final view = MentionAutocompleteView.init(store: store, narrow: narrow);
Expand Down Expand Up @@ -218,7 +218,7 @@ void main() {
});

test('MentionAutocompleteView yield between batches of 1000', () async {
const narrow = AllMessagesNarrow();
const narrow = CombinedFeedNarrow();
final store = eg.store();
for (int i = 0; i < 2500; i++) {
store.addUser(eg.user(userId: i, email: 'user$i@example.com', fullName: 'User $i'));
Expand All @@ -241,7 +241,7 @@ void main() {
});

test('MentionAutocompleteView new query during computation replaces old', () async {
const narrow = AllMessagesNarrow();
const narrow = CombinedFeedNarrow();
final store = eg.store();
for (int i = 0; i < 1500; i++) {
store.addUser(eg.user(userId: i, email: 'user$i@example.com', fullName: 'User $i'));
Expand Down Expand Up @@ -275,7 +275,7 @@ void main() {
});

test('MentionAutocompleteView mutating store.users while in progress causes retry', () async {
const narrow = AllMessagesNarrow();
const narrow = CombinedFeedNarrow();
final store = eg.store();
for (int i = 0; i < 1500; i++) {
store.addUser(eg.user(userId: i, email: 'user$i@example.com', fullName: 'User $i'));
Expand Down
6 changes: 3 additions & 3 deletions test/model/compose_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,11 @@ hello
});

group('narrowLink', () {
test('AllMessagesNarrow', () {
test('CombinedFeedNarrow', () {
final store = eg.store();
check(narrowLink(store, const AllMessagesNarrow()))
check(narrowLink(store, const CombinedFeedNarrow()))
.equals(store.realmUrl.resolve('#narrow'));
check(narrowLink(store, const AllMessagesNarrow(), nearMessageId: 1))
check(narrowLink(store, const CombinedFeedNarrow(), nearMessageId: 1))
.equals(store.realmUrl.resolve('#narrow/near/1'));
});

Expand Down
18 changes: 9 additions & 9 deletions test/model/message_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void main() async {
void checkNotifiedOnce() => checkNotified(count: 1);

/// Initialize [model] and the rest of the test state.
void prepare({Narrow narrow = const AllMessagesNarrow()}) {
void prepare({Narrow narrow = const CombinedFeedNarrow()}) {
final stream = eg.stream();
subscription = eg.subscription(stream);
store = eg.store()
Expand Down Expand Up @@ -86,7 +86,7 @@ void main() async {
}

test('fetchInitial', () async {
const narrow = AllMessagesNarrow();
const narrow = CombinedFeedNarrow();
prepare(narrow: narrow);
connection.prepare(json: newestResult(
foundOldest: false,
Expand Down Expand Up @@ -139,7 +139,7 @@ void main() async {
});

test('fetchOlder', () async {
const narrow = AllMessagesNarrow();
const narrow = CombinedFeedNarrow();
prepare(narrow: narrow);
await prepareMessages(foundOldest: false,
messages: List.generate(100, (i) => eg.streamMessage(id: 1000 + i)));
Expand Down Expand Up @@ -167,7 +167,7 @@ void main() async {
});

test('fetchOlder nop when already fetching', () async {
const narrow = AllMessagesNarrow();
const narrow = CombinedFeedNarrow();
prepare(narrow: narrow);
await prepareMessages(foundOldest: false,
messages: List.generate(100, (i) => eg.streamMessage(id: 1000 + i)));
Expand Down Expand Up @@ -197,7 +197,7 @@ void main() async {
});

test('fetchOlder nop when already haveOldest true', () async {
prepare(narrow: const AllMessagesNarrow());
prepare(narrow: const CombinedFeedNarrow());
await prepareMessages(foundOldest: true, messages:
List.generate(30, (i) => eg.streamMessage()));
check(model)
Expand All @@ -215,7 +215,7 @@ void main() async {
});

test('fetchOlder handles servers not understanding includeAnchor', () async {
const narrow = AllMessagesNarrow();
const narrow = CombinedFeedNarrow();
prepare(narrow: narrow);
await prepareMessages(foundOldest: false,
messages: List.generate(100, (i) => eg.streamMessage(id: 1000 + i)));
Expand Down Expand Up @@ -554,10 +554,10 @@ void main() async {
});

group('stream/topic muting', () {
test('in AllMessagesNarrow', () async {
test('in CombinedFeedNarrow', () async {
final stream1 = eg.stream(streamId: 1, name: 'stream 1');
final stream2 = eg.stream(streamId: 2, name: 'stream 2');
prepare(narrow: const AllMessagesNarrow());
prepare(narrow: const CombinedFeedNarrow());
store.addStreams([stream1, stream2]);
store.addSubscription(eg.subscription(stream1));
store.addUserTopic(stream1, 'B', UserTopicVisibilityPolicy.muted);
Expand Down Expand Up @@ -922,7 +922,7 @@ void checkInvariants(MessageListView model) {

if (message is! StreamMessage) continue;
switch (model.narrow) {
case AllMessagesNarrow():
case CombinedFeedNarrow():
check(model.store.isTopicVisible(message.streamId, message.subject))
.isTrue();
case StreamNarrow():
Expand Down
4 changes: 2 additions & 2 deletions test/widgets/action_sheet_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,9 @@ void main() {
));
});

testWidgets('not offered in AllMessagesNarrow (composing to reply is not yet supported)', (WidgetTester tester) async {
testWidgets('not offered in CombinedFeedNarrow (composing to reply is not yet supported)', (WidgetTester tester) async {
final message = eg.streamMessage();
await setupToMessageActionSheet(tester, message: message, narrow: const AllMessagesNarrow());
await setupToMessageActionSheet(tester, message: message, narrow: const CombinedFeedNarrow());
check(findQuoteAndReplyButton(tester)).isNull();
});
});
Expand Down
Loading

0 comments on commit d07d3d5

Please sign in to comment.