Page MenuHomePhabricator

[keyserver] Update `user-fetchers` to handle image avatars
ClosedPublic

Authored by atul on Apr 11 2023, 12:30 PM.
Tags
None
Referenced Files
F2193234: D7385.id25015.diff
Thu, Jul 4, 9:27 PM
Unknown Object (File)
Wed, Jul 3, 7:38 AM
Unknown Object (File)
Wed, Jul 3, 6:59 AM
Unknown Object (File)
Sun, Jun 30, 9:04 PM
Unknown Object (File)
Sun, Jun 30, 2:03 PM
Unknown Object (File)
Sun, Jun 30, 2:40 AM
Unknown Object (File)
Sat, Jun 29, 7:01 AM
Unknown Object (File)
Wed, Jun 26, 8:32 AM
Subscribers

Details

Summary

Update the queries in user-fetchers to fetch upload_id and upload_secret from uploads table to create upload URL and include in ClientAvatar.

Test Plan

Set breakpoints after each query and observed the result set and that the ClientAvatars were constructed correctly.

Verified that I was able to see image avatars on native client:

Simulator Screenshot - Fresh iPhone 14 Pro - 2023-04-11 at 15.29.10.png (2×1 px, 169 KB)

Simulator Screenshot - Fresh iPhone 14 Pro - 2023-04-11 at 15.30.05.png (2×1 px, 160 KB)

Simulator Screenshot - Fresh iPhone 14 Pro - 2023-04-11 at 15.29.25.png (2×1 px, 193 KB)

Simulator Screenshot - Fresh iPhone 14 Pro - 2023-04-11 at 15.29.06.png (2×1 px, 187 KB)

Simulator Screenshot - Fresh iPhone 14 Pro - 2023-04-11 at 15.29.57.png (2×1 px, 291 KB)

Simulator Screenshot - Fresh iPhone 14 Pro - 2023-04-11 at 15.29.15.png (2×1 px, 337 KB)

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

atul published this revision for review.EditedApr 11 2023, 12:39 PM

This was originally split up in a much cleaner way.

  1. Introduce convertDBAvatarToClientAvatar utility and corresponding unit tests
  2. Update user-fetchers queries to fetch avatar uploads and construct ClientImageAvatar with convertDBAvatarToClientAvatar

I generally prefer the pattern of breaking down my work, writing whatever self-contained abstractions/functions/utilities are necessary, and then composing them together... but whatever 🤷‍♂️

ashoat added inline comments.
keyserver/src/fetchers/user-fetchers.js
36 ↗(On Diff #25007)

Can you remove the trailing space at the end of this line here?

40 ↗(On Diff #25007)

Is there a risk of this returning multiple rows? I guess when we set a new avatar, we make sure to "orphan" any previous image avatars?

Looking at it more closely, it looks like none of the code will "crash" if we have multiple uploads, but the behavior is pretty undefined in those cases. fetchUserInfos and fetchKnownUserInfos will return the avatar from the last row that matches, whereas fetchLoggedInUserInfo will return the avatar from the first row that matches

60 ↗(On Diff #25007)

row.upload_secret should already be a string... no need to call toString()

104 ↗(On Diff #25007)

Remove trailing space

158 ↗(On Diff #25007)

row.upload_secret should already be a string... no need to call toString()

320–330 ↗(On Diff #25007)

This code is repeated in 3 places. Should we introduce a utility function that takes dbAvatar, uploadID, and uploadSecret, and returns clientAvatar?

(Can be done in a later diff if you prefer)

325 ↗(On Diff #25007)

row.upload_secret should already be a string... no need to call toString()

This revision is now accepted and ready to land.Apr 11 2023, 12:55 PM
keyserver/src/fetchers/user-fetchers.js
40 ↗(On Diff #25007)

Is there a risk of this returning multiple rows? I guess when we set a new avatar, we make sure to "orphan" any previous image avatars?

A. We make sure that we set the avatar and unset previous avatars in a single transaction to make that it's atomic.
B. To ensure that it's deterministic, we can check the uploadID in ImageAvatarDBContent matches up with the ID of the upload in the result set. In the previous version of this stack, convertDBAvatarToClientAvatar had an invariant that made sure that we were getting the right image for the right avatar. I'll create a followup task to pull out the common logic here into a utility function, add unit tests, and add that invariant.

keyserver/src/fetchers/user-fetchers.js
40 ↗(On Diff #25007)

"orphan"

I think people are trying to move away from the use of the word "orphan" in this context, "disconnected" may be a suitable alternative.

capitalize AS everywhere