Skip to content

Commit c4a0ad9

Browse files
chrisbobbegnprice
authored andcommitted
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 a922f56 commit c4a0ad9

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
@@ -693,10 +693,13 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
693693
return byDate.difference(dateJoined).inDays >= realmWaitingPeriodThreshold;
694694
}
695695

696-
/// The given user's real email address, if known, for displaying in the UI.
696+
/// The user's real email address, if known, for displaying in the UI.
697697
///
698-
/// Returns null if self-user isn't able to see [user]'s real email address.
699-
String? userDisplayEmail(User user) {
698+
/// Returns null if self-user isn't able to see the user's real email address,
699+
/// or if the user isn't actually a user we know about.
700+
String? userDisplayEmail(int userId) {
701+
final user = getUser(userId);
702+
if (user == null) return null;
700703
if (zulipFeatureLevel >= 163) { // TODO(server-7)
701704
// A non-null value means self-user has access to [user]'s real email,
702705
// 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
@@ -47,7 +47,7 @@ class ProfilePage extends StatelessWidget {
4747
final nameStyle = _TextStyles.primaryFieldText
4848
.merge(weightVariableTextStyle(context, wght: 700));
4949

50-
final displayEmail = store.userDisplayEmail(user);
50+
final displayEmail = store.userDisplayEmail(userId);
5151
final items = [
5252
Center(
5353
child: Avatar(

0 commit comments

Comments
 (0)