Skip to content

Commit 7f8d368

Browse files
committed
profile: Display user email
Fixes: zulip#291
1 parent f3faf90 commit 7f8d368

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

lib/widgets/profile.dart

+38-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import 'dart:convert';
33
import 'package:flutter/material.dart';
44
import 'package:flutter_gen/gen_l10n/zulip_localizations.dart';
55

6+
import '../api/model/initial_snapshot.dart';
67
import '../api/model/model.dart';
78
import '../model/content.dart';
89
import '../model/narrow.dart';
10+
import '../model/store.dart';
911
import 'content.dart';
1012
import 'message_list.dart';
1113
import 'page.dart';
@@ -33,6 +35,37 @@ class ProfilePage extends StatelessWidget {
3335
page: ProfilePage(userId: userId));
3436
}
3537

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+
3669
@override
3770
Widget build(BuildContext context) {
3871
final zulipLocalizations = ZulipLocalizations.of(context);
@@ -42,6 +75,7 @@ class ProfilePage extends StatelessWidget {
4275
return const _ProfileErrorPage();
4376
}
4477

78+
final displayEmail = _getDisplayEmailFor(user, store: store);
4579
final items = [
4680
Center(
4781
child: Avatar(userId: userId, size: 200, borderRadius: 200 / 8)),
@@ -50,7 +84,10 @@ class ProfilePage extends StatelessWidget {
5084
textAlign: TextAlign.center,
5185
style: _TextStyles.primaryFieldText
5286
.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),
5491
Text(roleToLabel(user.role, zulipLocalizations),
5592
textAlign: TextAlign.center,
5693
style: _TextStyles.primaryFieldText),

test/widgets/profile_test.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,14 @@ void main() {
7171

7272
group('ProfilePage', () {
7373
testWidgets('page builds; profile page renders', (WidgetTester tester) async {
74-
final user = eg.user(userId: 1, fullName: 'test user');
74+
final user = eg.user(userId: 1, fullName: 'test user',
75+
deliveryEmail: '[email protected]');
7576

7677
await setupPage(tester, users: [user], pageUserId: user.userId);
7778

7879
check(because: 'find user avatar', find.byType(Avatar).evaluate()).length.equals(1);
7980
check(because: 'find user name', find.text('test user').evaluate()).isNotEmpty();
81+
check(because: 'find user delivery email', find.text('[email protected]').evaluate()).isNotEmpty();
8082
});
8183

8284
testWidgets('page builds; profile page renders with profileData', (WidgetTester tester) async {

0 commit comments

Comments
 (0)