Skip to content

Commit

Permalink
api: Make displayName nullable
Browse files Browse the repository at this point in the history
Signed-off-by: Zixuan James Li <[email protected]>
  • Loading branch information
PIG208 committed Feb 8, 2025
1 parent 8e113ad commit 9cc3d25
Show file tree
Hide file tree
Showing 13 changed files with 16 additions and 31 deletions.
2 changes: 1 addition & 1 deletion lib/api/model/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ extension type const TopicName(String _value) {
/// so that UI code can identify when it needs to represent the topic
/// specially in the way prescribed for "general chat".
// TODO(#1250) carry out that plan
String get displayName => _value;
String? get displayName => _value.isEmpty ? null : _value;

/// The key to use for "same topic as" comparisons.
String canonicalize() => apiName.toLowerCase();
Expand Down
2 changes: 0 additions & 2 deletions lib/model/autocomplete.dart
Original file line number Diff line number Diff line change
Expand Up @@ -942,15 +942,13 @@ class TopicAutocompleteQuery extends AutocompleteQuery {
bool testTopic(PerAccountStore store, TopicName topic) {
// TODO(#881): Sort by match relevance, like web does.

// ignore: unnecessary_null_comparison // null topic names soon to be enabled
if (topic.displayName == null) {
return store.realmEmptyTopicDisplayName.toLowerCase()
.contains(raw.toLowerCase());
}
// This checks for inequality because there is nothing to autocomplete to
// when `raw` already matches the topic exactly.
return topic.displayName != raw
// ignore: unnecessary_non_null_assertion // null topic names soon to be enabled
&& topic.displayName!.toLowerCase().contains(raw.toLowerCase());
}

Expand Down
1 change: 0 additions & 1 deletion lib/widgets/action_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ void showTopicActionSheet(BuildContext context, {
// TODO: check for other cases that may disallow this action (e.g.: time
// limit for editing topics).
final allowResolveUnresolve =
// ignore: unnecessary_null_comparison // null topic names soon to be enabled
message == null || message.topic.displayName != null;
if (someMessageIdInTopic != null && allowResolveUnresolve) {
optionButtons.add(ResolveUnresolveButton(pageContext: pageContext,
Expand Down
2 changes: 0 additions & 2 deletions lib/widgets/autocomplete.dart
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,11 @@ class TopicAutocomplete extends AutocompleteField<TopicAutocompleteQuery, TopicA
@override
Widget buildItem(BuildContext context, int index, TopicAutocompleteResult option) {
final Widget child;
// ignore: unnecessary_null_comparison // null topic names soon to be enabled
if (option.topic.displayName == null) {
final store = PerAccountStoreWidget.of(context);
child = Text(store.realmEmptyTopicDisplayName,
style: const TextStyle(fontStyle: FontStyle.italic));
} else {
// ignore: unnecessary_non_null_assertion // null topic names soon to be enabled
child = Text(option.topic.displayName!);
}

Expand Down
3 changes: 0 additions & 3 deletions lib/widgets/compose_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ class ComposeTopicController extends ComposeController<TopicValidationError> {
}

void setTopic(TopicName newTopic) {
// ignore: dead_null_aware_expression // null topic names soon to be enabled
value = TextEditingValue(text: newTopic.displayName ?? '');
}
}
Expand Down Expand Up @@ -608,7 +607,6 @@ class _StreamContentInputState extends State<_StreamContentInput> {
destination: TopicNarrow(widget.narrow.streamId, topic),
controller: widget.controller,
hintText: zulipLocalizations.composeBoxChannelContentHint(
// ignore: dead_null_aware_expression // null topic names soon to be enabled
'#$streamName > ${topic.displayName ?? store.realmEmptyTopicDisplayName}'));
}
}
Expand Down Expand Up @@ -674,7 +672,6 @@ class _FixedDestinationContentInput extends StatelessWidget {
final streamName = store.streams[streamId]?.name
?? zulipLocalizations.unknownChannelName;
return zulipLocalizations.composeBoxChannelContentHint(
// ignore: dead_null_aware_expression // null topic names soon to be enabled
'#$streamName > ${topic.displayName ?? store.realmEmptyTopicDisplayName}');

case DmNarrow(otherRecipientIds: []): // The self-1:1 thread.
Expand Down
2 changes: 0 additions & 2 deletions lib/widgets/inbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -537,15 +537,13 @@ class _TopicItem extends StatelessWidget {
child: Text(
style: TextStyle(
fontSize: 17,
// ignore: unnecessary_null_comparison // null topic names soon to be enabled
fontStyle: topic.displayName == null ? FontStyle.italic : null,
height: (20 / 17),
// TODO(design) check if this is the right variable
color: designVariables.labelMenuButton,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
// ignore: dead_null_aware_expression // null topic names soon to be enabled
topic.displayName ?? store.realmEmptyTopicDisplayName))),
const SizedBox(width: 12),
if (hasMention) const _IconMarker(icon: ZulipIcons.at_sign),
Expand Down
4 changes: 0 additions & 4 deletions lib/widgets/message_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,8 @@ class MessageListAppBarTitle extends StatelessWidget {
return Row(
mainAxisSize: MainAxisSize.min,
children: [
// ignore: dead_null_aware_expression // null topic names soon to be enabled
Flexible(child: Text(topic.displayName ?? store.realmEmptyTopicDisplayName, style: TextStyle(
fontSize: 13,
// ignore: unnecessary_null_comparison // null topic names soon to be enabled
fontStyle: topic.displayName == null ? FontStyle.italic : null,
).merge(weightVariableTextStyle(context)))),
if (icon != null)
Expand Down Expand Up @@ -1119,13 +1117,11 @@ class StreamMessageRecipientHeader extends StatelessWidget {
child: Row(
children: [
Flexible(
// ignore: dead_null_aware_expression // null topic names soon to be enabled
child: Text(topic.displayName ?? store.realmEmptyTopicDisplayName,
// TODO: Give a way to see the whole topic (maybe a
// long-press interaction?)
overflow: TextOverflow.ellipsis,
style: recipientHeaderTextStyle(context).copyWith(
// ignore: unnecessary_null_comparison // null topic names soon to be enabled
fontStyle: topic.displayName == null ? FontStyle.italic : null,
))),
const SizedBox(width: 4),
Expand Down
2 changes: 1 addition & 1 deletion test/api/model/model_checks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extension MessageChecks on Subject<Message> {

extension TopicNameChecks on Subject<TopicName> {
Subject<String> get apiName => has((x) => x.apiName, 'apiName');
Subject<String> get displayName => has((x) => x.displayName, 'displayName');
Subject<String?> get displayName => has((x) => x.displayName, 'displayName');
}

extension StreamMessageChecks on Subject<StreamMessage> {
Expand Down
5 changes: 2 additions & 3 deletions test/widgets/action_sheet_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ void main() {

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

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

testWidgets('show from recipient header', (tester) async {
await prepare();
Expand Down
8 changes: 4 additions & 4 deletions test/widgets/autocomplete_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ void main() {
await tester.tap(find.text('Topic three'));
await tester.pumpAndSettle();
check(tester.widget<TextField>(topicInputFinder).controller!.text)
.equals(topic3.name.displayName);
.equals(topic3.name.displayName!);
check(find.text('Topic one' )).findsNothing();
check(find.text('Topic two' )).findsNothing();
check(find.text('Topic three')).findsOne(); // shown in `_TopicInput` once
Expand Down Expand Up @@ -412,7 +412,7 @@ void main() {
await tester.pumpAndSettle();

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

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

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

testWidgets('autocomplete to general chat sets topic to empty string', (tester) async {
final topic = eg.getStreamTopicsEntry(name: '');
Expand All @@ -439,6 +439,6 @@ void main() {
await tester.tap(find.text(eg.defaultRealmEmptyTopicDisplayName));
await tester.pump(Duration.zero);
check(controller.value).text.equals('');
}, skip: true); // null topic names soon to be enabled
});
});
}
10 changes: 5 additions & 5 deletions test/widgets/compose_box_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -360,15 +360,15 @@ void main() {
checkComposeBoxHintTexts(tester,
topicHintText: eg.defaultRealmEmptyTopicDisplayName,
contentHintText: 'Message #${channel.name} > ${eg.defaultRealmEmptyTopicDisplayName}');
}, skip: true); // null topic names soon to be enabled
});

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

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

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

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

testWidgets('if topics are mandatory, reject "(no topic)"', (tester) async {
await setupAndTapSend(tester,
Expand Down
2 changes: 1 addition & 1 deletion test/widgets/inbox_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ void main() {
unreadMessages: [eg.streamMessage(stream: channel, topic: '')]);

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

group('topic visibility', () {
final channel = eg.stream();
Expand Down
4 changes: 2 additions & 2 deletions test/widgets/message_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ void main() {
await tester.pump();
check(findInMessageList('stream name')).single;
check(findInMessageList(eg.defaultRealmEmptyTopicDisplayName)).single;
}, skip: true); // null topic names soon to be enabled
});

testWidgets('show general chat for empty topics without channel name', (tester) async {
await setupMessageListPage(tester,
Expand All @@ -826,7 +826,7 @@ void main() {
await tester.pump();
check(findInMessageList('stream name')).isEmpty();
check(findInMessageList(eg.defaultRealmEmptyTopicDisplayName)).single;
}, skip: true); // null topic names soon to be enabled
});

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

0 comments on commit 9cc3d25

Please sign in to comment.