Skip to content

Commit b56b10c

Browse files
gnpriceGaurav-Kushwaha-1225
authored andcommitted
api [nfc]: Introduce TopicName.displayName, and use where needed
Each of these call sites will need to be updated for zulip#1250. Those sites can now be found by listing the references to this getter. As a bonus the type-checker will point out most of the places that need updates, because this getter will become nullable. (The exceptions are where it's used in a string interpolation, because `null.toString()` is valid and returns "null".)
1 parent 9d2c0d0 commit b56b10c

File tree

10 files changed

+27
-12
lines changed

10 files changed

+27
-12
lines changed

lib/api/model/model.dart

+12
Original file line numberDiff line numberDiff line change
@@ -659,8 +659,20 @@ enum MessageFlag {
659659
// TODO(#1250): Migrate all implicit uses as String; remove "implements String".
660660
extension type const TopicName(String _value) implements String {
661661
/// The string this topic is identified by in the Zulip API.
662+
///
663+
/// This should be used in constructing HTTP requests to the server,
664+
/// but rarely for other purposes. See [displayName] and [canonicalize].
662665
String get apiName => _value;
663666

667+
/// The string this topic is displayed as to the user in our UI.
668+
///
669+
/// At the moment this always equals [apiName].
670+
/// In the future this will become null for the "general chat" topic (#1250),
671+
/// so that UI code can identify when it needs to represent the topic
672+
/// specially in the way prescribed for "general chat".
673+
// TODO(#1250) carry out that plan
674+
String get displayName => _value;
675+
664676
/// The key to use for "same topic as" comparisons.
665677
String canonicalize() => apiName.toLowerCase();
666678

lib/model/autocomplete.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,8 @@ class TopicAutocompleteQuery extends AutocompleteQuery {
864864

865865
bool testTopic(TopicName topic) {
866866
// TODO(#881): Sort by match relevance, like web does.
867-
return topic != raw && topic.toLowerCase().contains(raw.toLowerCase());
867+
return topic.displayName != raw
868+
&& topic.displayName.toLowerCase().contains(raw.toLowerCase());
868869
}
869870

870871
@override

lib/model/narrow.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class TopicNarrow extends Narrow implements SendableNarrow {
114114
StreamDestination get destination => StreamDestination(streamId, topic);
115115

116116
@override
117-
String toString() => 'TopicNarrow($streamId, $topic)';
117+
String toString() => 'TopicNarrow($streamId, ${topic.displayName})';
118118

119119
@override
120120
bool operator ==(Object other) {

lib/notifications/display.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,9 @@ class NotificationDisplayManager {
264264
// the first.
265265
messagingStyle.conversationTitle = switch (data.recipient) {
266266
FcmMessageChannelRecipient(:var streamName?, :var topic) =>
267-
'#$streamName > $topic',
267+
'#$streamName > ${topic.displayName}',
268268
FcmMessageChannelRecipient(:var topic) =>
269-
'#(unknown channel) > $topic', // TODO get stream name from data
269+
'#(unknown channel) > ${topic.displayName}', // TODO get stream name from data
270270
FcmMessageDmRecipient(:var allRecipientIds) when allRecipientIds.length > 2 =>
271271
zulipLocalizations.notifGroupDmConversationLabel(
272272
data.senderFullName, allRecipientIds.length - 2), // TODO use others' names, from data

lib/widgets/autocomplete.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,6 @@ class TopicAutocomplete extends AutocompleteField<TopicAutocompleteQuery, TopicA
334334
},
335335
child: Padding(
336336
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
337-
child: Text(option.topic)));
337+
child: Text(option.topic.displayName)));
338338
}
339339
}

lib/widgets/compose_box.dart

+3-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class ComposeTopicController extends ComposeController<TopicValidationError> {
9191
}
9292

9393
void setTopic(TopicName newTopic) {
94-
value = TextEditingValue(text: newTopic);
94+
value = TextEditingValue(text: newTopic.displayName);
9595
}
9696
}
9797

@@ -550,7 +550,8 @@ class _FixedDestinationContentInput extends StatelessWidget {
550550
final store = PerAccountStoreWidget.of(context);
551551
final streamName = store.streams[streamId]?.name
552552
?? zulipLocalizations.composeBoxUnknownChannelName;
553-
return zulipLocalizations.composeBoxChannelContentHint(streamName, topic);
553+
return zulipLocalizations.composeBoxChannelContentHint(
554+
streamName, topic.displayName);
554555

555556
case DmNarrow(otherRecipientIds: []): // The self-1:1 thread.
556557
return zulipLocalizations.composeBoxSelfDmContentHint;

lib/widgets/inbox.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ class _TopicItem extends StatelessWidget {
524524
),
525525
maxLines: 2,
526526
overflow: TextOverflow.ellipsis,
527-
topic))),
527+
topic.displayName))),
528528
const SizedBox(width: 12),
529529
if (hasMention) const _IconMarker(icon: ZulipIcons.at_sign),
530530
// TODO(design) copies the "@" marker color; is there a better color?

lib/widgets/message_list.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ class MessageListAppBarTitle extends StatelessWidget {
344344
return Row(
345345
mainAxisSize: MainAxisSize.min,
346346
children: [
347-
Flexible(child: Text(topic, style: const TextStyle(
347+
Flexible(child: Text(topic.displayName, style: const TextStyle(
348348
fontSize: 13,
349349
).merge(weightVariableTextStyle(context)))),
350350
if (icon != null)
@@ -1091,7 +1091,7 @@ class StreamMessageRecipientHeader extends StatelessWidget {
10911091
child: Row(
10921092
children: [
10931093
Flexible(
1094-
child: Text(topic,
1094+
child: Text(topic.displayName,
10951095
// TODO: Give a way to see the whole topic (maybe a
10961096
// long-press interaction?)
10971097
overflow: TextOverflow.ellipsis,

test/api/model/model_checks.dart

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ extension MessageChecks on Subject<Message> {
4848

4949
extension TopicNameChecks on Subject<TopicName> {
5050
Subject<String> get apiName => has((x) => x.apiName, 'apiName');
51+
Subject<String> get displayName => has((x) => x.displayName, 'displayName');
5152
}
5253

5354
extension StreamMessageChecks on Subject<StreamMessage> {

test/widgets/autocomplete_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ void main() {
277277

278278
group('TopicAutocomplete', () {
279279
void checkTopicShown(GetStreamTopicsEntry topic, PerAccountStore store, {required bool expected}) {
280-
check(find.text(topic.name).evaluate().length).equals(expected ? 1 : 0);
280+
check(find.text(topic.name.displayName).evaluate().length).equals(expected ? 1 : 0);
281281
}
282282

283283
testWidgets('options appear, disappear, and change correctly', (WidgetTester tester) async {
@@ -302,7 +302,7 @@ void main() {
302302
await tester.tap(find.text('Topic three'));
303303
await tester.pumpAndSettle();
304304
check(tester.widget<TextField>(topicInputFinder).controller!.text)
305-
.equals(topic3.name);
305+
.equals(topic3.name.displayName);
306306
checkTopicShown(topic1, store, expected: false);
307307
checkTopicShown(topic2, store, expected: false);
308308
checkTopicShown(topic3, store, expected: true); // shown in `_TopicInput` once

0 commit comments

Comments
 (0)