Skip to content

Commit 7d0c6bc

Browse files
fombalangPIG208
authored andcommitted
user [nfc]: Move getDisplayEmailFor method to lib/model/store.dart
Moved method to PerAccountStore, renamed method from getDisplayEmailFor to userDisplayEmail and refactored usages to remove duplication.
1 parent 6bbe74f commit 7d0c6bc

File tree

2 files changed

+28
-29
lines changed

2 files changed

+28
-29
lines changed

lib/model/store.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,33 @@ class PerAccountStore extends ChangeNotifier with EmojiStore, UserStore, Channel
498498
return byDate.difference(dateJoined).inDays >= realmWaitingPeriodThreshold;
499499
}
500500

501+
/// The given user's real email address, if known, for displaying in the UI.
502+
///
503+
/// Returns null if self-user isn't able to see [user]'s real email address.
504+
String? userDisplayEmail(User user) {
505+
if (zulipFeatureLevel >= 163) { // TODO(server-7)
506+
// A non-null value means self-user has access to [user]'s real email,
507+
// while a null value means it doesn't have access to the email.
508+
// Search for "delivery_email" in https://zulip.com/api/register-queue.
509+
return user.deliveryEmail;
510+
} else {
511+
if (user.deliveryEmail != null) {
512+
// A non-null value means self-user has access to [user]'s real email,
513+
// while a null value doesn't necessarily mean it doesn't have access
514+
// to the email, ....
515+
return user.deliveryEmail;
516+
} else if (emailAddressVisibility == EmailAddressVisibility.everyone) {
517+
// ... we have to also check for [PerAccountStore.emailAddressVisibility].
518+
// See:
519+
// * https://github.com/zulip/zulip-mobile/pull/5515#discussion_r997731727
520+
// * https://chat.zulip.org/#narrow/stream/378-api-design/topic/email.20address.20visibility/near/1296133
521+
return user.email;
522+
} else {
523+
return null;
524+
}
525+
}
526+
}
527+
501528
////////////////////////////////
502529
// Streams, topics, and stuff about them.
503530

lib/widgets/profile.dart

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ import 'dart:convert';
22

33
import 'package:flutter/material.dart';
44

5-
import '../api/model/initial_snapshot.dart';
65
import '../api/model/model.dart';
76
import '../generated/l10n/zulip_localizations.dart';
87
import '../model/content.dart';
98
import '../model/narrow.dart';
10-
import '../model/store.dart';
119
import 'app_bar.dart';
1210
import 'content.dart';
1311
import 'message_list.dart';
@@ -36,32 +34,6 @@ class ProfilePage extends StatelessWidget {
3634
page: ProfilePage(userId: userId));
3735
}
3836

39-
/// The given user's real email address, if known, for displaying in the UI.
40-
///
41-
/// Returns null if self-user isn't able to see [user]'s real email address.
42-
String? _getDisplayEmailFor(User user, {required PerAccountStore store}) {
43-
if (store.zulipFeatureLevel >= 163) { // TODO(server-7)
44-
// A non-null value means self-user has access to [user]'s real email,
45-
// while a null value means it doesn't have access to the email.
46-
// Search for "delivery_email" in https://zulip.com/api/register-queue.
47-
return user.deliveryEmail;
48-
} else {
49-
if (user.deliveryEmail != null) {
50-
// A non-null value means self-user has access to [user]'s real email,
51-
// while a null value doesn't necessarily mean it doesn't have access
52-
// to the email, ....
53-
return user.deliveryEmail;
54-
} else if (store.emailAddressVisibility == EmailAddressVisibility.everyone) {
55-
// ... we have to also check for [PerAccountStore.emailAddressVisibility].
56-
// See:
57-
// * https://github.com/zulip/zulip-mobile/pull/5515#discussion_r997731727
58-
// * https://chat.zulip.org/#narrow/stream/378-api-design/topic/email.20address.20visibility/near/1296133
59-
return user.email;
60-
} else {
61-
return null;
62-
}
63-
}
64-
}
6537

6638
@override
6739
Widget build(BuildContext context) {
@@ -72,7 +44,7 @@ class ProfilePage extends StatelessWidget {
7244
return const _ProfileErrorPage();
7345
}
7446

75-
final displayEmail = _getDisplayEmailFor(user, store: store);
47+
final displayEmail = store.userDisplayEmail(user);
7648
final items = [
7749
Center(
7850
child: Avatar(userId: userId, size: 200, borderRadius: 200 / 8)),

0 commit comments

Comments
 (0)