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