Skip to content

Commit 9cc3d25

Browse files
committed
api: Make displayName nullable
Signed-off-by: Zixuan James Li <[email protected]>
1 parent 8e113ad commit 9cc3d25

13 files changed

+16
-31
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
@@ -942,15 +942,13 @@ class TopicAutocompleteQuery extends AutocompleteQuery {
942942
bool testTopic(PerAccountStore store, TopicName topic) {
943943
// TODO(#881): Sort by match relevance, like web does.
944944

945-
// ignore: unnecessary_null_comparison // null topic names soon to be enabled
946945
if (topic.displayName == null) {
947946
return store.realmEmptyTopicDisplayName.toLowerCase()
948947
.contains(raw.toLowerCase());
949948
}
950949
// This checks for inequality because there is nothing to autocomplete to
951950
// when `raw` already matches the topic exactly.
952951
return topic.displayName != raw
953-
// ignore: unnecessary_non_null_assertion // null topic names soon to be enabled
954952
&& topic.displayName!.toLowerCase().contains(raw.toLowerCase());
955953
}
956954

lib/widgets/action_sheet.dart

-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ void showTopicActionSheet(BuildContext context, {
253253
// TODO: check for other cases that may disallow this action (e.g.: time
254254
// limit for editing topics).
255255
final allowResolveUnresolve =
256-
// ignore: unnecessary_null_comparison // null topic names soon to be enabled
257256
message == null || message.topic.displayName != null;
258257
if (someMessageIdInTopic != null && allowResolveUnresolve) {
259258
optionButtons.add(ResolveUnresolveButton(pageContext: pageContext,

lib/widgets/autocomplete.dart

-2
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,11 @@ class TopicAutocomplete extends AutocompleteField<TopicAutocompleteQuery, TopicA
366366
@override
367367
Widget buildItem(BuildContext context, int index, TopicAutocompleteResult option) {
368368
final Widget child;
369-
// ignore: unnecessary_null_comparison // null topic names soon to be enabled
370369
if (option.topic.displayName == null) {
371370
final store = PerAccountStoreWidget.of(context);
372371
child = Text(store.realmEmptyTopicDisplayName,
373372
style: const TextStyle(fontStyle: FontStyle.italic));
374373
} else {
375-
// ignore: unnecessary_non_null_assertion // null topic names soon to be enabled
376374
child = Text(option.topic.displayName!);
377375
}
378376

lib/widgets/compose_box.dart

-3
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ class ComposeTopicController extends ComposeController<TopicValidationError> {
196196
}
197197

198198
void setTopic(TopicName newTopic) {
199-
// ignore: dead_null_aware_expression // null topic names soon to be enabled
200199
value = TextEditingValue(text: newTopic.displayName ?? '');
201200
}
202201
}
@@ -608,7 +607,6 @@ class _StreamContentInputState extends State<_StreamContentInput> {
608607
destination: TopicNarrow(widget.narrow.streamId, topic),
609608
controller: widget.controller,
610609
hintText: zulipLocalizations.composeBoxChannelContentHint(
611-
// ignore: dead_null_aware_expression // null topic names soon to be enabled
612610
'#$streamName > ${topic.displayName ?? store.realmEmptyTopicDisplayName}'));
613611
}
614612
}
@@ -674,7 +672,6 @@ class _FixedDestinationContentInput extends StatelessWidget {
674672
final streamName = store.streams[streamId]?.name
675673
?? zulipLocalizations.unknownChannelName;
676674
return zulipLocalizations.composeBoxChannelContentHint(
677-
// ignore: dead_null_aware_expression // null topic names soon to be enabled
678675
'#$streamName > ${topic.displayName ?? store.realmEmptyTopicDisplayName}');
679676

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

lib/widgets/inbox.dart

-2
Original file line numberDiff line numberDiff line change
@@ -537,15 +537,13 @@ class _TopicItem extends StatelessWidget {
537537
child: Text(
538538
style: TextStyle(
539539
fontSize: 17,
540-
// ignore: unnecessary_null_comparison // null topic names soon to be enabled
541540
fontStyle: topic.displayName == null ? FontStyle.italic : null,
542541
height: (20 / 17),
543542
// TODO(design) check if this is the right variable
544543
color: designVariables.labelMenuButton,
545544
),
546545
maxLines: 2,
547546
overflow: TextOverflow.ellipsis,
548-
// ignore: dead_null_aware_expression // null topic names soon to be enabled
549547
topic.displayName ?? store.realmEmptyTopicDisplayName))),
550548
const SizedBox(width: 12),
551549
if (hasMention) const _IconMarker(icon: ZulipIcons.at_sign),

lib/widgets/message_list.dart

-4
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,8 @@ class MessageListAppBarTitle extends StatelessWidget {
366366
return Row(
367367
mainAxisSize: MainAxisSize.min,
368368
children: [
369-
// ignore: dead_null_aware_expression // null topic names soon to be enabled
370369
Flexible(child: Text(topic.displayName ?? store.realmEmptyTopicDisplayName, style: TextStyle(
371370
fontSize: 13,
372-
// ignore: unnecessary_null_comparison // null topic names soon to be enabled
373371
fontStyle: topic.displayName == null ? FontStyle.italic : null,
374372
).merge(weightVariableTextStyle(context)))),
375373
if (icon != null)
@@ -1119,13 +1117,11 @@ class StreamMessageRecipientHeader extends StatelessWidget {
11191117
child: Row(
11201118
children: [
11211119
Flexible(
1122-
// ignore: dead_null_aware_expression // null topic names soon to be enabled
11231120
child: Text(topic.displayName ?? store.realmEmptyTopicDisplayName,
11241121
// TODO: Give a way to see the whole topic (maybe a
11251122
// long-press interaction?)
11261123
overflow: TextOverflow.ellipsis,
11271124
style: recipientHeaderTextStyle(context).copyWith(
1128-
// ignore: unnecessary_null_comparison // null topic names soon to be enabled
11291125
fontStyle: topic.displayName == null ? FontStyle.italic : null,
11301126
))),
11311127
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

+2-3
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ void main() {
190190

191191
final topicRow = find.descendant(
192192
of: find.byType(ZulipAppBar),
193-
// ignore: dead_null_aware_expression // null topic names soon to be enabled
194193
matching: find.text(topicName.displayName ?? eg.defaultRealmEmptyTopicDisplayName));
195194
await tester.longPress(topicRow);
196195
// sheet appears onscreen; default duration of bottom-sheet enter animation
@@ -211,7 +210,7 @@ void main() {
211210

212211
await tester.longPress(find.descendant(
213212
of: find.byType(RecipientHeader),
214-
matching: find.text(effectiveMessage.topic.displayName)));
213+
matching: find.text(effectiveMessage.topic.displayName!)));
215214
// sheet appears onscreen; default duration of bottom-sheet enter animation
216215
await tester.pump(const Duration(milliseconds: 250));
217216
}
@@ -275,7 +274,7 @@ void main() {
275274
messages: [message]);
276275
check(findButtonForLabel('Mark as resolved')).findsNothing();
277276
check(findButtonForLabel('Mark as unresolved')).findsNothing();
278-
}, skip: true); // null topic names soon to be enabled
277+
});
279278

280279
testWidgets('show from recipient header', (tester) async {
281280
await prepare();

test/widgets/autocomplete_test.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ void main() {
355355
await tester.tap(find.text('Topic three'));
356356
await tester.pumpAndSettle();
357357
check(tester.widget<TextField>(topicInputFinder).controller!.text)
358-
.equals(topic3.name.displayName);
358+
.equals(topic3.name.displayName!);
359359
check(find.text('Topic one' )).findsNothing();
360360
check(find.text('Topic two' )).findsNothing();
361361
check(find.text('Topic three')).findsOne(); // shown in `_TopicInput` once
@@ -412,7 +412,7 @@ void main() {
412412
await tester.pumpAndSettle();
413413

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

417417
testWidgets('match general chat in autocomplete', (tester) async {
418418
final topic = eg.getStreamTopicsEntry(name: '');
@@ -424,7 +424,7 @@ void main() {
424424
await tester.pumpAndSettle();
425425

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

429429
testWidgets('autocomplete to general chat sets topic to empty string', (tester) async {
430430
final topic = eg.getStreamTopicsEntry(name: '');
@@ -439,6 +439,6 @@ void main() {
439439
await tester.tap(find.text(eg.defaultRealmEmptyTopicDisplayName));
440440
await tester.pump(Duration.zero);
441441
check(controller.value).text.equals('');
442-
}, skip: true); // null topic names soon to be enabled
442+
});
443443
});
444444
}

test/widgets/compose_box_test.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -360,15 +360,15 @@ void main() {
360360
checkComposeBoxHintTexts(tester,
361361
topicHintText: eg.defaultRealmEmptyTopicDisplayName,
362362
contentHintText: 'Message #${channel.name} > ${eg.defaultRealmEmptyTopicDisplayName}');
363-
}, skip: true); // null topic names soon to be enabled
363+
});
364364

365365
testWidgets('to ChannelNarrow with empty topic (mandatory topics)', (tester) async {
366366
await prepare(tester, narrow: ChannelNarrow(channel.streamId),
367367
mandatoryTopics: true);
368368
checkComposeBoxHintTexts(tester,
369369
topicHintText: 'Topic',
370370
contentHintText: 'Message #${channel.name} > ${eg.defaultRealmEmptyTopicDisplayName}');
371-
}, skip: true); // null topic names soon to be enabled
371+
});
372372

373373
testWidgets('legacy: to ChannelNarrow with empty topic', (tester) async {
374374
await prepare(tester, narrow: ChannelNarrow(channel.streamId),
@@ -404,7 +404,7 @@ void main() {
404404
mandatoryTopics: false);
405405
checkComposeBoxHintTexts(tester, contentHintText:
406406
'Message #${channel.name} > ${eg.defaultRealmEmptyTopicDisplayName}');
407-
}, skip: true); // null topic names soon to be enabled
407+
});
408408

409409
testWidgets('to DmNarrow with self', (tester) async {
410410
await prepare(tester, narrow: DmNarrow.withUser(
@@ -723,7 +723,7 @@ void main() {
723723
..method.equals('POST')
724724
..url.path.equals('/api/v1/messages')
725725
..bodyFields['topic'].equals('');
726-
}, skip: true); // null topic names soon to be enabled
726+
});
727727

728728
testWidgets('legacy: empty topic -> "(no topic)"', (tester) async {
729729
await setupAndTapSend(tester,
@@ -748,7 +748,7 @@ void main() {
748748
topicInputText: eg.defaultRealmEmptyTopicDisplayName,
749749
mandatoryTopics: true);
750750
checkMessageNotSent(tester);
751-
}, skip: true); // null topic names soon to be enabled
751+
});
752752

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

test/widgets/inbox_test.dart

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

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

320320
group('topic visibility', () {
321321
final channel = eg.stream();

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')).single;
819819
check(findInMessageList(eg.defaultRealmEmptyTopicDisplayName)).single;
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')).isEmpty();
828828
check(findInMessageList(eg.defaultRealmEmptyTopicDisplayName)).single;
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)