Skip to content

Conversation

@pinarol
Copy link
Contributor

@pinarol pinarol commented Oct 30, 2024

Fixes #

Integrates the Gravatar Quick Editor into Jetpack.
Changes are behind the remote feature flag: gravatar_quick_editor

RPReplay_Final1730303727.MP4
RPReplay_Final1730303545.MP4

Technical Details

The new structure depends on the Quick Editor's update callback and fires a notification GravatarQEAvatarUpdateNotification. The UI components that render the avatar subscribe to that notification. Once received, they fetch the latest version of the avatar from the BE. To achieve this we introduce a way to forceRefresh the avatar, which wasn't present before. To achieve forceRefresh we add a cache buster query parameter otherwise the backend cache gets in the way and the latest version of the avatar can't be fetched.

To test:

Enable the feature flag "Gravatar Quick Editor" in Me > App Settings > Debug > Feature Flags (It's enabled by default in DEBUG config)
Log out from the Jetpack app
Log in with a new email (Highly recommend getting a temp email via https://tempmail.so/us , you should go to your inbox in your mobile device since the login depends on a magic link)
Use the email magic link to continue to the app
Observe: You landed on the signup epilogue, the avatar placeholder has a + on it and tapping on the avatar opens the Quick Editor.
Upload & change the avatar via the Quick Editor
Observe: The avatar on the signup page also gets updated
Close the Quick Editor
Continue to the app

Go to Me > My Profile
Tap either on the avatar or on the "Update profile photo" button
Observe: Quick Editor opens
Upload & change the avatar via the Quick Editor
Observe: The avatars on the main app gets updated as well (the one on the profile header, and the "Me" tab bar item at the bottom)

Appearance Test
Go to Me > App Settings > Appearance
Switch the appearance
Go to Me > My Profile
Tap either on the avatar or on the "Update profile photo" button
Observe: Quick Editor opens and the appearance matched with the app.

Disable the feature flag "Gravatar Quick Editor" in Me > App Settings > Debug > Feature Flags

Repeat the tests ☝️
This time instead of the Gravatar Quick Editor you should observe that the system photo picker appears and the selected image is uploaded & set as the avatar.

Regression Notes

  1. Potential unintended areas of impact
    The existing upload flow

  2. What I did to test those areas of impact (or what existing automated tests I relied on)
    Tested with the feature flag off

  3. What automated tests I added (or what prevented me from doing so)
    x

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding unit tests for my changes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

Testing checklist:

  • WordPress.com sites and self-hosted Jetpack sites.
  • Portrait and landscape orientations.
  • Light and dark modes.
  • Fonts: Larger, smaller and bold text.
  • High contrast.
  • VoiceOver.
  • Languages with large words or with letters/accents not frequently used in English.
  • Right-to-left languages. (Even if translation isn’t complete, formatting should still respect the right-to-left layout)
  • iPhone and iPad.
  • Multi-tasking: Split view and Slide over. (iPad)

@pinarol pinarol added this to the 25.6 milestone Oct 30, 2024
@pinarol pinarol self-assigned this Oct 30, 2024
@wpmobilebot
Copy link
Contributor

wpmobilebot commented Oct 30, 2024

WordPress Alpha📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
App NameWordPress Alpha WordPress Alpha
ConfigurationRelease-Alpha
Build Numberpr23729-157f792
Version25.4.2
Bundle IDorg.wordpress.alpha
Commit157f792
App Center BuildWPiOS - One-Offs #11057
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Oct 30, 2024

Jetpack Alpha📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
App NameJetpack Alpha Jetpack Alpha
ConfigurationRelease-Alpha
Build Numberpr23729-157f792
Version25.4.2
Bundle IDcom.jetpack.alpha
Commit157f792
App Center Buildjetpack-installable-builds #10097
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

Add email check when handling the notification

`GravatarQEAvatarUpdateNotification`
# Conflicts:
#	WordPress/Classes/Utility/BuildInformation/RemoteFeatureFlag.swift
@pinarol pinarol added the Gravatar Gravatar SDK related updates label Oct 31, 2024
@pinarol pinarol marked this pull request as ready for review October 31, 2024 16:19
@pinarol
Copy link
Contributor Author

pinarol commented Oct 31, 2024

cc: @kean @crazytonyli

@pinarol pinarol added this to the 25.7 milestone Nov 11, 2024
Copy link
Contributor Author

@pinarol pinarol left a comment

Choose a reason for hiding this comment

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

Thanks for the review @crazytonyli 🙇 This is ready for another look. (I was AFK last week so this is a bit of a late response)

Task {
// Purge the cache otherwise the old avatars remain around.
await ImageDownloader.shared.clearURLSessionCache()
await ImageDownloader.shared.clearMemoryCache()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Despite being connected to the same email, avatars scattered throughout the app have usually different URLs depending on the query parameters like size, default image option, rating etc.

And unfortunately URLCache or NSCache doesn't give us chance to iterate over the cache keys and filter based on host and path. We need to know the exact URL to remove an entry which we don't.

Alternatively, we can remove these calls altogether but this causes some avatars to remain old in different places of the app which looks inconsistent and faulty. Also, killing & reopening the app can bring in the old avatar since URLCache has a disk cache. So I recommend keeping these purge operations but let me know if you prefer otherwise.

}
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not so sure about these changes. @kean Can you have a look please?

Copy link
Contributor

Choose a reason for hiding this comment

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

The app clears caches on onAvatarUpdated and they will be automatically re-populated later. I'm not sure it's worth adding complexity and making task getter internal for this scenario.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Normally we shouldn't need this yes. But unfortunately there's a delay at the backend that causes the old avatar to return for like 25 seconds after selecting a different avatar. So the old avatar comes back on the next request that doesn't have the cache buster parameter and looks like this:

I reported this issue to systems and following it. In the meantime I update the memory cache for the cache buster-less version of the URL so the correct image can be shown next time.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this doesn't look great, especially since it replaced the new avatar with the old one. I don't see anything particular wrong with adding this bit of code, so I'm going to leave it up to you.

@crazytonyli
Copy link
Contributor

@pinarol Thanks for addressing my comments. They look good to me. I'm not familiar with the image downloading implementation, and asked Alex to have to a look. ⬆️

@pinarol pinarol requested a review from kean November 14, 2024 10:01
Copy link
Contributor

@kean kean left a comment

Choose a reason for hiding this comment

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

LGTM with a couple of minor comments.

Some additional feedback:

  • Clearing all caches isn't ideal but seems acceptable for this scenario. Ideally, it would use a separate cache and/or would rely on HTTP caching.
  • (UX) It's a bit odd that after you upload a new image, it doesn't change your profile picture.
  • There is no way to delete an avatar (pretty sure it is also the case in production)

}
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

The app clears caches on onAvatarUpdated and they will be automatically re-populated later. I'm not sure it's worth adding complexity and making task getter internal for this scenario.

didSet {
if let email = gravatarEmail {
gravatarImageView.downloadGravatar(for: email, gravatarRating: .x)
downloadAvatar()
Copy link
Contributor

Choose a reason for hiding this comment

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

It produces a new Xcode warning (email unused).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I missed this. Fixed. 👍

@pinarol
Copy link
Contributor Author

pinarol commented Nov 15, 2024

Thanks for the review @kean !

(UX) It's a bit odd that after you upload a new image, it doesn't change your profile picture.

Yeah this is the same with web's Avatar Quick Editor as well as in gravatar.com, and a consistent UX was targeted. If no avatar is selected though, the uploaded avatar will be set immediately. But if there's already a selected avatar, the user needs to deliberately change the selection. A kind of precaution to prevent unintended changes to the user's global avatar.

There is no way to delete an avatar (pretty sure it is also the case in production)

This is coming in a couple of months. For now, avatars can be deleted via gravatar.com only. We are waiting for the corresponding REST endpoint and we'll be adding this feature to the QE along with some other improvements.

@pinarol pinarol modified the milestones: 25.7, 25.6 Nov 15, 2024
@dangermattic
Copy link
Collaborator

dangermattic commented Nov 15, 2024

1 Warning
⚠️ This PR is assigned to the milestone 25.6. This milestone is due in less than 4 days.
Please make sure to get it merged by then or assign it to a milestone with a later deadline.

Generated by 🚫 Danger

@pinarol pinarol modified the milestones: 25.6, 25.7 Nov 15, 2024
@kean
Copy link
Contributor

kean commented Nov 15, 2024

But if there's already a selected avatar, the user needs to deliberately change the selection. A kind of precaution to prevent unintended changes to the user's global avatar.

It just it appeared broken to me. You can change it back is a single click, so does it need a precaution? If it's not a precaution, it's not clear what user scenario it solves by making a two-step process.

For now, avatars can be deleted via gravatar.com only.

It's be nice if it also includes removing your current avatar as I couldn't find a way to do it.

@pinarol
Copy link
Contributor Author

pinarol commented Nov 15, 2024

It just it appeared broken to me. You can change it back is a single click, so does it need a precaution? If it's not a precaution, it's not clear what user scenario it solves by making a two-step process.

Let me take this feedback to our designer. I know that we want a unified experience between web/iOS/Android so I can't change this for iOS only but I am sure we can consider and discuss this.

It's be nice if it also includes removing your current avatar as I couldn't find a way to do it.

You mean on the web? https://gravatar.com/profile/avatars
Because I can do it by removing the selected avatar:

Screenshot 2024-11-15 at 16 02 35

@pinarol pinarol added this pull request to the merge queue Nov 15, 2024
Merged via the queue into trunk with commit 41b8062 Nov 15, 2024
26 of 28 checks passed
@pinarol pinarol deleted the wppinar/integrate-gravatar-quick-editor branch November 15, 2024 13:50
@kean
Copy link
Contributor

kean commented Nov 15, 2024

You mean on the web? https://gravatar.com/profile/avatars. Because I can do it by removing the selected avatar:

Yeah, it would be nice to add soon too, but I think it needs a separate way to "remove current avatar" though without actually deleting it.

Overall, the new experience looks pretty great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Gravatar Gravatar SDK related updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants