@@ -3,9 +3,11 @@ import 'dart:convert';
3
3
import 'package:flutter/material.dart' ;
4
4
import 'package:flutter_gen/gen_l10n/zulip_localizations.dart' ;
5
5
6
+ import '../api/model/initial_snapshot.dart' ;
6
7
import '../api/model/model.dart' ;
7
8
import '../model/content.dart' ;
8
9
import '../model/narrow.dart' ;
10
+ import '../model/store.dart' ;
9
11
import 'content.dart' ;
10
12
import 'message_list.dart' ;
11
13
import 'page.dart' ;
@@ -33,6 +35,36 @@ class ProfilePage extends StatelessWidget {
33
35
page: ProfilePage (userId: userId));
34
36
}
35
37
38
+ /// The given user's real email address, if known, for displaying in the UI.
39
+ ///
40
+ /// Returns null if [selfUser] isn't able to see [user] 's real email address.
41
+ ///
42
+ /// **Note:** Starting from Zulip version 7.0 (FL 163), there's a change in
43
+ /// the API about how [selfUser] can access [user] 's real email address.
44
+ /// Search for "delivery_email" in https://zulip.com/api/register-queue.
45
+ String ? _getDisplayEmailFor (User user, {required PerAccountStore store}) {
46
+ if (store.account.zulipFeatureLevel >= 163 ) {
47
+ // A non-null value means [selfUser] has access to [user]'s real email,
48
+ // while a null value means it doesn't have access to the email.
49
+ return user.deliveryEmail;
50
+ } else {
51
+ if (user.deliveryEmail != null ) {
52
+ // A non-null value means [selfUser] has access to [user]'s real email,
53
+ // while a null value doesn't necessarily mean it doesn't have access
54
+ // to the email, ....
55
+ return user.deliveryEmail;
56
+ } else if (store.emailAddressVisibility == EmailAddressVisibility .everyone) {
57
+ // ... we have to also check for [PerAccountStore.emailAddressVisibility].
58
+ // See:
59
+ // * https://github.com/zulip/zulip-mobile/pull/5515#discussion_r997731727
60
+ // * https://chat.zulip.org/#narrow/stream/378-api-design/topic/email.20address.20visibility/near/1296133
61
+ return user.email;
62
+ } else {
63
+ return null ;
64
+ }
65
+ }
66
+ }
67
+
36
68
@override
37
69
Widget build (BuildContext context) {
38
70
final zulipLocalizations = ZulipLocalizations .of (context);
@@ -42,6 +74,7 @@ class ProfilePage extends StatelessWidget {
42
74
return const _ProfileErrorPage ();
43
75
}
44
76
77
+ final displayEmail = _getDisplayEmailFor (user, store: store);
45
78
final items = [
46
79
Center (
47
80
child: Avatar (userId: userId, size: 200 , borderRadius: 200 / 8 )),
@@ -50,7 +83,10 @@ class ProfilePage extends StatelessWidget {
50
83
textAlign: TextAlign .center,
51
84
style: _TextStyles .primaryFieldText
52
85
.merge (weightVariableTextStyle (context, wght: 700 ))),
53
- // TODO(#291) render email field
86
+ if (displayEmail != null )
87
+ Text (displayEmail,
88
+ textAlign: TextAlign .center,
89
+ style: _TextStyles .primaryFieldText),
54
90
Text (roleToLabel (user.role, zulipLocalizations),
55
91
textAlign: TextAlign .center,
56
92
style: _TextStyles .primaryFieldText),
0 commit comments