Skip to content

Commit c34eeab

Browse files
committed
api: Make displayName nullable
Signed-off-by: Zixuan James Li <[email protected]>
1 parent 2d620f3 commit c34eeab

12 files changed

+15
-29
lines changed

lib/api/model/model.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ extension type const TopicName(String _value) {
690690
/// so that UI code can identify when it needs to represent the topic
691691
/// specially in the way prescribed for "general chat".
692692
// TODO(#1250) carry out that plan
693-
String get displayName => _value;
693+
String? get displayName => _value.isEmpty ? null : _value;
694694

695695
/// The key to use for "same topic as" comparisons.
696696
String canonicalize() => apiName.toLowerCase();

lib/model/autocomplete.dart

-2
Original file line numberDiff line numberDiff line change
@@ -865,13 +865,11 @@ class TopicAutocompleteQuery extends AutocompleteQuery {
865865
bool testTopic(PerAccountStore store, TopicName topic) {
866866
// TODO(#881): Sort by match relevance, like web does.
867867

868-
// ignore: unnecessary_null_comparison // null topic names soon to be enabled
869868
if (topic.displayName == null) {
870869
return store.realmEmptyTopicDisplayName.toLowerCase()
871870
.contains(raw.toLowerCase());
872871
}
873872
return topic.displayName != raw
874-
// ignore: unnecessary_non_null_assertion // null topic names soon to be enabled
875873
&& topic.displayName!.toLowerCase().contains(raw.toLowerCase());
876874
}
877875

lib/widgets/autocomplete.dart

-2
Original file line numberDiff line numberDiff line change
@@ -329,13 +329,11 @@ class TopicAutocomplete extends AutocompleteField<TopicAutocompleteQuery, TopicA
329329
@override
330330
Widget buildItem(BuildContext context, int index, TopicAutocompleteResult option) {
331331
final Widget child;
332-
// ignore: unnecessary_null_comparison // null topic names soon to be enabled
333332
if (option.topic.displayName == null) {
334333
final store = PerAccountStoreWidget.of(context);
335334
child = Text(store.realmEmptyTopicDisplayName,
336335
style: const TextStyle(fontStyle: FontStyle.italic));
337336
} else {
338-
// ignore: unnecessary_non_null_assertion // null topic names soon to be enabled
339337
child = Text(option.topic.displayName!);
340338
}
341339

lib/widgets/compose_box.dart

-4
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ class ComposeTopicController extends ComposeController<TopicValidationError> {
129129
}
130130

131131
void setTopic(TopicName newTopic) {
132-
// ignore: dead_null_aware_expression // null topic names soon to be enabled
133132
value = TextEditingValue(text: newTopic.displayName ?? '');
134133
}
135134
}
@@ -440,7 +439,6 @@ class _ContentInputState extends State<_ContentInput> with WidgetsBindingObserve
440439
color: designVariables.textInput.withFadedAlpha(0.5));
441440

442441
if (widget.destination.destination
443-
// ignore: constant_pattern_never_matches_value_type // null topic names soon to be enabled
444442
case StreamDestination(topic: TopicName(displayName: null))) {
445443
// TODO(#1285): This applies to the entire hint text; ideally we'd only
446444
// want to italize the "general chat" text, but this requires
@@ -546,7 +544,6 @@ class _StreamContentInputState extends State<_StreamContentInput> {
546544
destination: TopicNarrow(widget.narrow.streamId, topic),
547545
controller: widget.controller,
548546
hintText: zulipLocalizations.composeBoxChannelContentHint(
549-
// ignore: dead_null_aware_expression // null topic names soon to be enabled
550547
streamName, topic.displayName ?? store.realmEmptyTopicDisplayName));
551548
}
552549
}
@@ -612,7 +609,6 @@ class _FixedDestinationContentInput extends StatelessWidget {
612609
final streamName = store.streams[streamId]?.name
613610
?? zulipLocalizations.composeBoxUnknownChannelName;
614611
return zulipLocalizations.composeBoxChannelContentHint(
615-
// ignore: dead_null_aware_expression // null topic names soon to be enabled
616612
streamName, topic.displayName ?? store.realmEmptyTopicDisplayName);
617613

618614
case DmNarrow(otherRecipientIds: []): // The self-1:1 thread.

lib/widgets/inbox.dart

-2
Original file line numberDiff line numberDiff line change
@@ -526,15 +526,13 @@ class _TopicItem extends StatelessWidget {
526526
child: Text(
527527
style: TextStyle(
528528
fontSize: 17,
529-
// ignore: unnecessary_null_comparison // null topic names soon to be enabled
530529
fontStyle: (topic.displayName == null) ? FontStyle.italic : null,
531530
height: (20 / 17),
532531
// TODO(design) check if this is the right variable
533532
color: designVariables.labelMenuButton,
534533
),
535534
maxLines: 2,
536535
overflow: TextOverflow.ellipsis,
537-
// ignore: dead_null_aware_expression // null topic names soon to be enabled
538536
topic.displayName ?? store.realmEmptyTopicDisplayName))),
539537
const SizedBox(width: 12),
540538
if (hasMention) const _IconMarker(icon: ZulipIcons.at_sign),

lib/widgets/message_list.dart

-4
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,8 @@ class MessageListAppBarTitle extends StatelessWidget {
362362
return Row(
363363
mainAxisSize: MainAxisSize.min,
364364
children: [
365-
// ignore: dead_null_aware_expression // null topic names soon to be enabled
366365
Flexible(child: Text(topic.displayName ?? store.realmEmptyTopicDisplayName, style: TextStyle(
367366
fontSize: 13,
368-
// ignore: unnecessary_null_comparison // null topic names soon to be enabled
369367
fontStyle: (topic.displayName == null) ? FontStyle.italic : null,
370368
).merge(weightVariableTextStyle(context)))),
371369
if (icon != null)
@@ -1097,13 +1095,11 @@ class StreamMessageRecipientHeader extends StatelessWidget {
10971095
child: Row(
10981096
children: [
10991097
Flexible(
1100-
// ignore: dead_null_aware_expression // null topic names soon to be enabled
11011098
child: Text(topic.displayName ?? store.realmEmptyTopicDisplayName,
11021099
// TODO: Give a way to see the whole topic (maybe a
11031100
// long-press interaction?)
11041101
overflow: TextOverflow.ellipsis,
11051102
style: recipientHeaderTextStyle(context).copyWith(
1106-
// ignore: unnecessary_null_comparison // null topic names soon to be enabled
11071103
fontStyle: (topic.displayName == null) ? FontStyle.italic : null,
11081104
))),
11091105
const SizedBox(width: 4),

test/api/model/model_checks.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +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');
51+
Subject<String?> get displayName => has((x) => x.displayName, 'displayName');
5252
}
5353

5454
extension StreamMessageChecks on Subject<StreamMessage> {

test/widgets/action_sheet_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ void main() {
209209

210210
await tester.longPress(find.descendant(
211211
of: find.byType(RecipientHeader),
212-
matching: find.text(effectiveMessage.topic.displayName)));
212+
matching: find.text(effectiveMessage.topic.displayName!)));
213213
// sheet appears onscreen; default duration of bottom-sheet enter animation
214214
await tester.pump(const Duration(milliseconds: 250));
215215
}

test/widgets/autocomplete_test.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ void main() {
297297
await tester.tap(find.text('Topic three'));
298298
await tester.pumpAndSettle();
299299
check(tester.widget<TextField>(topicInputFinder).controller!.text)
300-
.equals(topic3.name.displayName);
300+
.equals(topic3.name.displayName!);
301301
check(find.text('Topic one' )).findsNothing();
302302
check(find.text('Topic two' )).findsNothing();
303303
check(find.text('Topic three')).findsOne(); // shown in `_TopicInput` once
@@ -354,7 +354,7 @@ void main() {
354354
await tester.pumpAndSettle();
355355

356356
check(find.text(eg.defaultRealmEmptyTopicDisplayName)).findsOne();
357-
}, skip: true); // null topic names soon to be enabled
357+
});
358358

359359
testWidgets('match general chat in autocomplete', (tester) async {
360360
final topic = eg.getStreamTopicsEntry(name: '');
@@ -366,7 +366,7 @@ void main() {
366366
await tester.pumpAndSettle();
367367

368368
check(find.text(eg.defaultRealmEmptyTopicDisplayName)).findsOne();
369-
}, skip: true); // null topic names soon to be enabled
369+
});
370370

371371
testWidgets('autocomplete to general chat sets topic to empty string', (tester) async {
372372
final topic = eg.getStreamTopicsEntry(name: '');
@@ -383,6 +383,6 @@ void main() {
383383
check(controller.value).text.equals('');
384384

385385
await tester.pump(Duration.zero);
386-
}, skip: true); // null topic names soon to be enabled
386+
});
387387
});
388388
}

test/widgets/compose_box_test.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -350,15 +350,15 @@ void main() {
350350
checkComposeBoxHintTexts(tester,
351351
topicHintText: eg.defaultRealmEmptyTopicDisplayName,
352352
contentHintText: 'Message #${channel.name} > ${eg.defaultRealmEmptyTopicDisplayName}');
353-
}, skip: true); // null topic names soon to be enabled
353+
});
354354

355355
testWidgets('to ChannelNarrow without topic; mandatory topics', (tester) async {
356356
await prepare(tester, narrow: ChannelNarrow(channel.streamId),
357357
mandatoryTopics: true);
358358
checkComposeBoxHintTexts(tester,
359359
topicHintText: 'Topic',
360360
contentHintText: 'Message #${channel.name} > ${eg.defaultRealmEmptyTopicDisplayName}');
361-
}, skip: true); // null topic names soon to be enabled
361+
});
362362

363363
testWidgets('legacy: to ChannelNarrow without topic', (tester) async {
364364
await prepare(tester, narrow: ChannelNarrow(channel.streamId),
@@ -390,7 +390,7 @@ void main() {
390390
narrow: TopicNarrow(channel.streamId, TopicName('')));
391391
checkComposeBoxHintTexts(tester, contentHintText:
392392
'Message #${channel.name} > ${eg.defaultRealmEmptyTopicDisplayName}');
393-
}, skip: true); // null topic names soon to be enabled
393+
});
394394

395395
testWidgets('to DmNarrow with self', (tester) async {
396396
await prepare(tester, narrow: DmNarrow.withUser(
@@ -706,7 +706,7 @@ void main() {
706706
..method.equals('POST')
707707
..url.path.equals('/api/v1/messages')
708708
..bodyFields['topic'].equals('');
709-
}, skip: true); // null topic names soon to be enabled
709+
});
710710

711711
testWidgets('legacy: empty topic -> "(no topic)"', (tester) async {
712712
await setupAndTapSend(tester,
@@ -731,7 +731,7 @@ void main() {
731731
topicInputText: eg.defaultRealmEmptyTopicDisplayName,
732732
mandatoryTopics: true);
733733
checkMessageNotSent(tester);
734-
}, skip: true); // null topic names soon to be enabled
734+
});
735735

736736
testWidgets('if topics are mandatory, reject "(no topic)"', (tester) async {
737737
await setupAndTapSend(tester,

test/widgets/inbox_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ void main() {
318318
unreadMessages: [eg.streamMessage(stream: channel, topic: '')]);
319319

320320
check(find.text(eg.defaultRealmEmptyTopicDisplayName)).findsOne();
321-
}, skip: true); // null topic names soon to be enabled
321+
});
322322
});
323323

324324
group('topic visibility', () {

test/widgets/message_list_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ void main() {
817817
await tester.pump();
818818
check(findInMessageList('stream name')).length.equals(1);
819819
check(findInMessageList(eg.defaultRealmEmptyTopicDisplayName)).length.equals(1);
820-
}, skip: true); // null topic names soon to be enabled
820+
});
821821

822822
testWidgets('show general chat for empty topics without channel name', (tester) async {
823823
await setupMessageListPage(tester,
@@ -826,7 +826,7 @@ void main() {
826826
await tester.pump();
827827
check(findInMessageList('stream name')).length.equals(0);
828828
check(findInMessageList(eg.defaultRealmEmptyTopicDisplayName)).length.equals(1);
829-
}, skip: true); // null topic names soon to be enabled
829+
});
830830

831831
testWidgets('show topic visibility icon when followed', (tester) async {
832832
await setupMessageListPage(tester,

0 commit comments

Comments
 (0)