Skip to content

Commit 26f5b51

Browse files
msglist: Normalize topic name when opening message list
Fixes: #1717
1 parent ad790ef commit 26f5b51

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/widgets/message_list.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:async';
22

33
import 'package:collection/collection.dart';
44
import 'package:flutter/material.dart';
5+
import 'package:flutter/scheduler.dart';
56
import 'package:flutter_color_models/flutter_color_models.dart';
67
import 'package:intl/intl.dart' hide TextDirection;
78

@@ -772,8 +773,17 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
772773
}
773774

774775
void _initModel(PerAccountStore store, Anchor anchor) {
776+
// Normalize topic name if this is a TopicNarrow. See #1717.
777+
var narrow = widget.narrow;
778+
if (narrow is TopicNarrow) {
779+
narrow = narrow.processTopicLikeServer(
780+
zulipFeatureLevel: store.zulipFeatureLevel,
781+
realmEmptyTopicDisplayName: store.zulipFeatureLevel > 334
782+
? store.realmEmptyTopicDisplayName
783+
: null);
784+
}
775785
_model = MessageListView.init(store: store,
776-
narrow: widget.narrow, anchor: anchor);
786+
narrow: narrow, anchor: anchor);
777787
model.addListener(_modelChanged);
778788
model.fetchInitial();
779789
}
@@ -794,6 +804,7 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
794804

795805
if (model.narrow != widget.narrow) {
796806
// Either:
807+
// - We normalized the topic name in `_initModel` above.
797808
// - A message move event occurred, where propagate mode is
798809
// [PropagateMode.changeAll] or [PropagateMode.changeLater]. Or:
799810
// - We fetched a "with" / topic-permalink narrow, and the response

test/widgets/message_list_test.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,17 @@ void main() {
158158
check(state.narrow).equals(ChannelNarrow(stream.streamId));
159159
});
160160

161+
testWidgets('MessageListPageState.narrow (general chat)', (tester) async {
162+
final stream = eg.stream();
163+
final topic = eg.defaultRealmEmptyTopicDisplayName;
164+
final topicNarrow = eg.topicNarrow(stream.streamId, topic);
165+
await setupMessageListPage(tester, narrow: topicNarrow,
166+
streams: [stream],
167+
messages: [eg.streamMessage(stream: stream, topic: topic, content: "<p>a message</p>")]);
168+
final state = MessageListPage.ancestorOf(tester.element(find.text("a message")));
169+
check(state.narrow).equals(eg.topicNarrow(stream.streamId, ''));
170+
});
171+
161172
testWidgets('composeBoxState finds compose box', (tester) async {
162173
final stream = eg.stream();
163174
await setupMessageListPage(tester, narrow: ChannelNarrow(stream.streamId),

0 commit comments

Comments
 (0)