@@ -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,37 @@ 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 self-user 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 self-user can access [user] 's real email address.
44
+ /// Search for "delivery_email" in https://zulip.com/api/register-queue.
45
+ // TODO(server-7, FL >= 163): remove
46
+ String ? _getDisplayEmailFor (User user, {required PerAccountStore store}) {
47
+ if (store.account.zulipFeatureLevel >= 163 ) {
48
+ // A non-null value means [selfUser] has access to [user]'s real email,
49
+ // while a null value means it doesn't have access to the email.
50
+ return user.deliveryEmail;
51
+ } else {
52
+ if (user.deliveryEmail != null ) {
53
+ // A non-null value means [selfUser] has access to [user]'s real email,
54
+ // while a null value doesn't necessarily mean it doesn't have access
55
+ // to the email, ....
56
+ return user.deliveryEmail;
57
+ } else if (store.emailAddressVisibility == EmailAddressVisibility .everyone) {
58
+ // ... we have to also check for [PerAccountStore.emailAddressVisibility].
59
+ // See:
60
+ // * https://github.com/zulip/zulip-mobile/pull/5515#discussion_r997731727
61
+ // * https://chat.zulip.org/#narrow/stream/378-api-design/topic/email.20address.20visibility/near/1296133
62
+ return user.email;
63
+ } else {
64
+ return null ;
65
+ }
66
+ }
67
+ }
68
+
36
69
@override
37
70
Widget build (BuildContext context) {
38
71
final zulipLocalizations = ZulipLocalizations .of (context);
@@ -42,6 +75,7 @@ class ProfilePage extends StatelessWidget {
42
75
return const _ProfileErrorPage ();
43
76
}
44
77
78
+ final displayEmail = _getDisplayEmailFor (user, store: store);
45
79
final items = [
46
80
Center (
47
81
child: Avatar (userId: userId, size: 200 , borderRadius: 200 / 8 )),
@@ -50,7 +84,10 @@ class ProfilePage extends StatelessWidget {
50
84
textAlign: TextAlign .center,
51
85
style: _TextStyles .primaryFieldText
52
86
.merge (weightVariableTextStyle (context, wght: 700 ))),
53
- // TODO(#291) render email field
87
+ if (displayEmail != null )
88
+ Text (displayEmail,
89
+ textAlign: TextAlign .center,
90
+ style: _TextStyles .primaryFieldText),
54
91
Text (roleToLabel (user.role, zulipLocalizations),
55
92
textAlign: TextAlign .center,
56
93
style: _TextStyles .primaryFieldText),
0 commit comments