Skip to content

Commit

Permalink
do not merge; 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 21, 2025
1 parent 0174c3a commit 02ea3f6
Show file tree
Hide file tree
Showing 11 changed files with 10 additions and 21 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
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
1 change: 0 additions & 1 deletion lib/widgets/compose_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,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
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 @@ -1123,13 +1121,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
2 changes: 1 addition & 1 deletion test/widgets/action_sheet_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,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
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
});
});
}
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 @@ -943,7 +943,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 @@ -952,7 +952,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 02ea3f6

Please sign in to comment.