Skip to content

Commit e4db89d

Browse files
committed
users: Have userDisplayEmail handle unknown users
Like userDisplayName does. And remove a null-check `store.getUser(userId)!` at one of the callers... I think that's *probably* NFC, for the reason given in a comment ("must exist because UserMentionAutocompleteResult"). But it's possible this is actually a small bugfix involving a rare race involving our batch-processing of autocomplete results. Related: #716
1 parent 3669b15 commit e4db89d

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

lib/model/store.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -675,10 +675,13 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
675675
return byDate.difference(dateJoined).inDays >= realmWaitingPeriodThreshold;
676676
}
677677

678-
/// The given user's real email address, if known, for displaying in the UI.
678+
/// The user's real email address, if known, for displaying in the UI.
679679
///
680-
/// Returns null if self-user isn't able to see [user]'s real email address.
681-
String? userDisplayEmail(User user) {
680+
/// Returns null if self-user isn't able to see the user's real email address,
681+
/// or if the user isn't actually a user we know about.
682+
String? userDisplayEmail(int userId) {
683+
final user = getUser(userId);
684+
if (user == null) return null;
682685
if (zulipFeatureLevel >= 163) { // TODO(server-7)
683686
// A non-null value means self-user has access to [user]'s real email,
684687
// while a null value means it doesn't have access to the email.

lib/widgets/autocomplete.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,9 @@ class _MentionAutocompleteItem extends StatelessWidget {
275275
String? sublabel;
276276
switch (option) {
277277
case UserMentionAutocompleteResult(:var userId):
278-
final user = store.getUser(userId)!; // must exist because UserMentionAutocompleteResult
279278
avatar = Avatar(userId: userId, size: 36, borderRadius: 4);
280-
label = user.fullName;
281-
sublabel = store.userDisplayEmail(user);
279+
label = store.userDisplayName(userId);
280+
sublabel = store.userDisplayEmail(userId);
282281
case WildcardMentionAutocompleteResult(:var wildcardOption):
283282
avatar = SizedBox.square(dimension: 36,
284283
child: const Icon(ZulipIcons.three_person, size: 24));

lib/widgets/profile.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ProfilePage extends StatelessWidget {
4444
return const _ProfileErrorPage();
4545
}
4646

47-
final displayEmail = store.userDisplayEmail(user);
47+
final displayEmail = store.userDisplayEmail(userId);
4848
final items = [
4949
Center(
5050
child: Avatar(userId: userId, size: 200, borderRadius: 200 / 8)),

0 commit comments

Comments
 (0)