Skip to content

profile: Display user email #844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 9, 2024

Conversation

sm-sayedi
Copy link
Collaborator

Fixes: #291

@sm-sayedi sm-sayedi added the buddy review GSoC buddy review needed. label Jul 27, 2024
@sm-sayedi sm-sayedi requested a review from Khader-1 July 27, 2024 05:53
Copy link
Collaborator

@Khader-1 Khader-1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sm-sayedi! LGTM!
Now moving on to mentor review with @hackerkid.

@Khader-1 Khader-1 requested a review from hackerkid July 27, 2024 08:07
@Khader-1 Khader-1 added mentor review GSoC mentor review needed. and removed buddy review GSoC buddy review needed. labels Jul 27, 2024
@sm-sayedi sm-sayedi added the maintainer review PR ready for review by Zulip maintainers label Jul 28, 2024
@sm-sayedi sm-sayedi requested a review from chrisbobbe July 28, 2024 14:15
@chrisbobbe
Copy link
Collaborator

Thanks! The issue links to zulip-mobile's implementation: https://github.com/zulip/zulip-mobile/blob/8133bf2b8/src/users/userSelectors.js#L318

Here's that function:

/**
 * The given user's real email address, if known, for displaying in the UI.
 *
 * Null if our user isn't able to see this user's real email address.
 */
export function getDisplayEmailForUser(realm: RealmState, user: UserOrBot): string | null {
  if (user.delivery_email !== undefined) {
    return user.delivery_email;
  } else if (realm.emailAddressVisibility === EmailAddressVisibility.Everyone) {
    // On future servers, we expect this case will never happen: we'll always include
    // a delivery_email when you have access, including when the visibility is Everyone
    // https://github.com/zulip/zulip-mobile/pull/5515#discussion_r997731727
    return user.email;
  } else {
    return null;
  }
}

What's the user-facing consequence of not including logic like the check on realm.emailAddressVisibility?

@sm-sayedi
Copy link
Collaborator Author

Quoting the documentation for delivery_email from https://zulip.com/api/register-queue:

delivery_email: string | null

The user's real email address. This value will be null if you cannot access user's real email address. For bot users, this field is always set to the real email of the bot, because bot users always have email_address_visibility set to everyone.

Changes: Prior to Zulip 7.0 (feature level 163), this field was present only when email_address_visibility was restricted and you had access to the user's real email. As of this feature level, this field is always present, including the case when email_address_visibility is set to everyone (and therefore not restricted).

So I think that check was only necessary before feature level 163.

@chrisbobbe
Copy link
Collaborator

Looks like FL 163 was released in Zulip Server 7: https://zulip.com/api/changelog#changes-in-zulip-70

We aim to support all the way back to Zulip Server 4: https://github.com/zulip/zulip-flutter?tab=readme-ov-file#editing-api-types

but we may bump that to 5 soon: #268

Even when we bump our lower bound to 5, though, we'll still have users running 5 and 6. So the FL 163 threshold is one we should pay attention to.

@sm-sayedi sm-sayedi force-pushed the issue-291-profile-display-email branch 2 times, most recently from 79ca6fe to 3541ab8 Compare August 5, 2024 07:46
@sm-sayedi
Copy link
Collaborator Author

Thanks for the review @chrisbobbe. Changes pushed. PTAL.

Copy link
Collaborator

@chrisbobbe chrisbobbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sm-sayedi!

Small comments below, and also let's isolate the API-types change into the api: … commit, and add PerAccountStore.emailAddressVisibility in a separate commit.

/// the API about how [selfUser] can access [user]'s real email address.
/// Search for "delivery_email" in https://zulip.com/api/register-queue.
String? _getDisplayEmailFor(User user, {required PerAccountStore store}) {
if (store.account.zulipFeatureLevel >= 163) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's include a TODO(server-7) for removing the <163 case. That way, when we decide to bump our minimum-supported threshold to 7, this spot will naturally show up in a quick search for backwards-compatibility code that can be removed at that time.

/// **Note:** This field is removed in Zulip 7.0 (FL 163) and replaced with:
/// * https://zulip.com/api/update-settings#parameter-email_address_visibility
/// * https://zulip.com/api/update-realm-user-settings-defaults#parameter-email_address_visibility
final EmailAddressVisibility? emailAddressVisibility;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a // TODO(server-7): remove on this.

@@ -24,6 +24,15 @@ class InitialSnapshot {

final List<CustomProfileField> customProfileFields;

/// The realm-level policy for which a user can see other user's real email address.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having trouble parsing this summary line. How about:

Suggested change
/// The realm-level policy for which a user can see other user's real email address.
/// The realm-level policy, on pre-FL 163 servers, for visibility of real email addresses.

Comment on lines 31 to 34
/// **Note:** This field is removed in Zulip 7.0 (FL 163) and replaced with:
/// * https://zulip.com/api/update-settings#parameter-email_address_visibility
/// * https://zulip.com/api/update-realm-user-settings-defaults#parameter-email_address_visibility
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// **Note:** This field is removed in Zulip 7.0 (FL 163) and replaced with:
/// * https://zulip.com/api/update-settings#parameter-email_address_visibility
/// * https://zulip.com/api/update-realm-user-settings-defaults#parameter-email_address_visibility
/// This field is removed in Zulip 7.0 (FL 163) and replaced with a user-level
/// setting:
/// * https://zulip.com/api/update-settings#parameter-email_address_visibility
/// * https://zulip.com/api/update-realm-user-settings-defaults#parameter-email_address_visibility

@@ -33,6 +35,36 @@ class ProfilePage extends StatelessWidget {
page: ProfilePage(userId: userId));
}

/// The given user's real email address, if known, for displaying in the UI.
///
/// Returns null if [selfUser] isn't able to see [user]'s real email address.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

selfUser is formatted here as though it's an identifier in the function's code, but it isn't actually. So let's just say "the self-user".

(Here and below.)

@sm-sayedi sm-sayedi force-pushed the issue-291-profile-display-email branch from 3541ab8 to 7f8d368 Compare August 6, 2024 04:56
@sm-sayedi
Copy link
Collaborator Author

Thanks @chrisbobbe for the review! Comments addressed. Please have a look.

@sm-sayedi sm-sayedi requested a review from chrisbobbe August 6, 2024 05:05
Copy link
Collaborator

@chrisbobbe chrisbobbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! One nit below, and I'll mark this for Greg's review.

/// **Note:** Starting from Zulip version 7.0 (FL 163), there's a change in
/// the API about how self-user can access [user]'s real email address.
/// Search for "delivery_email" in https://zulip.com/api/register-queue.
// TODO(server-7, FL >= 163): remove
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// TODO(server-7, FL >= 163): remove
// TODO(server-7): remove; use user-level setting

(The form we've settled on is TODO(server-x); it doesn't need the feature level. All servers that are 7+ will have FL >= 163.)

@chrisbobbe chrisbobbe added integration review Added by maintainers when PR may be ready for integration and removed maintainer review PR ready for review by Zulip maintainers labels Aug 6, 2024
@sm-sayedi sm-sayedi force-pushed the issue-291-profile-display-email branch from 7f8d368 to e55ffa4 Compare August 8, 2024 19:03
@sm-sayedi sm-sayedi requested a review from gnprice August 8, 2024 19:27
Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sm-sayedi, and thanks @chrisbobbe for the previous reviews!

Generally this looks good. A few small comments below, and then this will be ready to merge.

@@ -311,6 +313,8 @@ class PerAccountStore extends ChangeNotifier with ChannelStore, MessageStore {
final Map<String, RealmDefaultExternalAccount> realmDefaultExternalAccounts;
Map<String, RealmEmojiItem> realmEmoji;
List<CustomProfileField> customProfileFields;
/// For docs, please see [InitialSnapshot.emailAddressVisibility].
final EmailAddressVisibility? emailAddressVisibility; // TODO(server-7): remove
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't quite right because in this revision it doesn't get updated when the setting changes. This value is an example of a realm setting:

But I don't want dealing with that to block this feature, or indeed to block launching the app. It's rare this setting will change, and the consequences of having an out-of-date value for a while are small. So let's just mark it with a TODO comment:

Suggested change
final EmailAddressVisibility? emailAddressVisibility; // TODO(server-7): remove
final EmailAddressVisibility? emailAddressVisibility; // TODO(#668) update this realm setting

(The TODO-server comment can be omitted because it's effectively covered by the one on InitialSnapshot.emailAddressVisibility — when we go to remove that, we'll necessarily notice we need to remove this at the same time.)

Comment on lines 45 to 47
// TODO(server-7): remove; use user-level setting
String? _getDisplayEmailFor(User user, {required PerAccountStore store}) {
if (store.account.zulipFeatureLevel >= 163) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// TODO(server-7): remove; use user-level setting
String? _getDisplayEmailFor(User user, {required PerAccountStore store}) {
if (store.account.zulipFeatureLevel >= 163) {
String? _getDisplayEmailFor(User user, {required PerAccountStore store}) {
if (store.account.zulipFeatureLevel >= 163) { // TODO(server-7)

Having the comment right at the condition is helpful for seeing that the condition is covered by a TODO-server comment.

The instruction "use user-level setting" isn't right for this spot — we won't be looking at the user's individual emailAddressVisibility setting, but rather just looking at their deliveryEmail. After all, that's what this code already does for modern servers. If there were something else we should be doing in the future, then for modern servers we should be doing that in the first place.

Comment on lines 38 to 44
/// The given user's real email address, if known, for displaying in the UI.
///
/// Returns null if self-user isn't able to see [user]'s real email address.
///
/// **Note:** Starting from Zulip version 7.0 (FL 163), there's a change in
/// the API about how self-user can access [user]'s real email address.
/// Search for "delivery_email" in https://zulip.com/api/register-queue.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// The given user's real email address, if known, for displaying in the UI.
///
/// Returns null if self-user isn't able to see [user]'s real email address.
///
/// **Note:** Starting from Zulip version 7.0 (FL 163), there's a change in
/// the API about how self-user can access [user]'s real email address.
/// Search for "delivery_email" in https://zulip.com/api/register-queue.
/// The given user's real email address, if known, for displaying in the UI.
///
/// Returns null if self-user isn't able to see [user]'s real email address.

The caller of this method doesn't need to know about that API change, right? It's something this method itself takes care of.

In that case it doesn't belong in a doc comment.

The reader for whom this information is relevant is one trying to understand the details of the method's implementation. That means the place this information could belong is in an implementation comment — // instead of ///, and inside the method's body. I think the code already covers the fact of the API change; but the comment in the modern-server case could benefit from the 'Search for "delivery_email" …' line.

This is for backward compatibility to the Zulip server versions prior to
Zulip 7.0 (FL 163) where there was realm-level `email_address_visibility`
policy for which a user can see other user's real email address. Search
for "email_address_visibility" in https://zulip.com/api/register-queue.

This will become handy in the next commit(s) where the user's real email
is shown in it's profile page.

Note: This field is removed in Zulip 7.0 (FL 163) and replaced with:
* https://zulip.com/api/update-settings#parameter-email_address_visibility
* https://zulip.com/api/update-realm-user-settings-defaults#parameter-email_address_visibility
@sm-sayedi sm-sayedi force-pushed the issue-291-profile-display-email branch from e55ffa4 to ba952c3 Compare August 9, 2024 17:50
@sm-sayedi
Copy link
Collaborator Author

Thanks @gnprice for the review! Changes pushed!

@gnprice
Copy link
Member

gnprice commented Aug 9, 2024

Thanks for the revision! Looks good — merging.

@gnprice gnprice merged commit ba952c3 into zulip:main Aug 9, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration review Added by maintainers when PR may be ready for integration mentor review GSoC mentor review needed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

profile: Display email
4 participants