Skip to content
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

QuickEditor: Fix AvatarStorage.updateAvatar to not override the selected value #527

Merged
merged 1 commit into from
Jan 13, 2025

Conversation

hamorillo
Copy link
Contributor

Closes #526

Description

The PATCH to update avatars doesn't receive the email, so, in the backend, we can't decide if that's the avatar selected for the email we are working with.

In the AvatarStorage.updateAvatar method, we should only use the value from the updatedAvatar if it's not null. Otherwise, we should keep the stored avatar's selected value.

Before
Kapture.2025-01-09.at.17.15.03.mp4
After
Kapture.2025-01-10.at.10.45.48.mp4

Testing Steps

  1. Open the QE
  2. Select an avatar (if you don't have one selected already)
  3. Modify the rating of the selected avatar
  4. Verify that you still see the avatar as selected when the rating is modified
  5. Open the AltTextPage and modify the AltText for the selected avatar
  6. Verify that you still see the avatar as selected when the AltText is modified

@hamorillo hamorillo added Bug Something isn't working [Feature] Gravatar-Quickeditor Gravatar Quick Editor module labels Jan 10, 2025
@hamorillo hamorillo added this to the 2.3.0 milestone Jan 10, 2025
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Jan 10, 2025

📲 You can test the changes from this Pull Request in Gravatar Demo by scanning the QR code below to install the corresponding build.
App Name Gravatar Demo
Commit3037fc3
Direct Downloadgravatar-demo-prototype-build-pr527-3037fc3.apk

Copy link
Contributor

@AdamGrzybkowski AdamGrzybkowski left a comment

Choose a reason for hiding this comment

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

Great this requires modification only at the storage level!

avatarToUpdate
// If the avatarToUpdate has a selected value, use it.
// Otherwise, use the stored avatar selected value.
avatarToUpdate.copy(selected = avatarToUpdate.selected ?: avatar.selected)
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 This solution works but I see a potential issue. This would stop working if backend started sending back the selcted value as false instead of null. If we only copied here the values that can actually change (rating and the alt_text) we would be much safer.

This might be unlikely scenario, but technically could happen.

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would stop working if backend started sending back the selcted value as false instead of null.

In my opinion, that would be a bug on the backend because, as we've seen, we don't know if it is selected or not. If the backend sends that value as false/true, it is because that's the correct value, and we should update it.

Anyway, I'm not entirely against only updating rating and alt_text, but I was looking at the updateAvatar method as a more abstract one that, if, for example, the URL changes, can update the URL too. (Just as an example).

I can refactor this if you still feel that approach is much safer. 🙂

Copy link
Contributor

Choose a reason for hiding this comment

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

In my opinion, that would be a bug on the backend because, as we've seen, we don't know if it is selected or not. If the backend sends that value as false/true, it is because that's the correct value, and we should update it.

I agree.

I can refactor this if you still feel that approach is much safer.

No need to, let's stick with this one.

…not null

The PATCH to update avatars doesn't receive the email, so we can't decide if that's the selected avatar for the e-mail we are working with.

In the AvatarStorage.updateAvatar method, we should use the value from the updatedAvatar only if it's not null. Otherwise, we should keep the stored avatar's selected value.
@hamorillo hamorillo force-pushed the hamorillo/526-not-override-whole-updated-avatar branch from 622663a to 3037fc3 Compare January 13, 2025 13:15
@hamorillo hamorillo merged commit 7564076 into trunk Jan 13, 2025
17 checks passed
@hamorillo hamorillo deleted the hamorillo/526-not-override-whole-updated-avatar branch January 13, 2025 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working [Feature] Gravatar-Quickeditor Gravatar Quick Editor module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

QuickEditor: AvatarStore.updateAvatar should omit selected value
3 participants