Page MenuHomePhabricator

[lib] Remove branching from `threadInfoFromRawThreadInfo(...)`
ClosedPublic

Authored by atul on Jan 18 2024, 11:26 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mar 5 2024, 2:37 PM
Unknown Object (File)
Mar 5 2024, 1:37 PM
Unknown Object (File)
Mar 5 2024, 1:37 PM
Unknown Object (File)
Mar 5 2024, 1:37 PM
Unknown Object (File)
Mar 5 2024, 1:37 PM
Unknown Object (File)
Mar 5 2024, 1:37 PM
Unknown Object (File)
Mar 5 2024, 1:37 PM
Unknown Object (File)
Feb 13 2024, 6:48 AM
Subscribers
None

Details

Summary

Part of threadInfoFromRawThreadInfo(...).

Required changes to createPendingThread and sendPushNotifs.


Depends on D10715

Test Plan

flow, will make sure push notifs continue to work as expected.

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

fix massive issue that flow didn't catch..

atul published this revision for review.Jan 18 2024, 11:40 AM
atul added inline comments.
keyserver/src/push/send.js
139–143 ↗(On Diff #35839)

By passing { minimallyEncodePermissions: true } to rawThreadInfoFromServerThreadInfo we're "guaranteed" to get minimally encoded RawThreadInfos back.

If we don't, that would indicate something has gone very wrong... so I think it's acceptable to use an invariant here.

We could explore parameterizing rawThreadInfoFromServerThreadInfo based on options.minimallyEncodePermissions, but I'm not sure how to do that.

CC @ashoat

lib/shared/thread-utils.js
366 ↗(On Diff #35839)

Wow... glad I caught that role wasn't minimallyEncoded in the first revision of this diff (I guess first diff of this revision). flow didn't report any issues and we would've had malformed RawThreadInfos.

Will take a sec, but going to write/generate some unit tests for this function.

ashoat requested changes to this revision.Jan 21 2024, 8:43 PM

Passing back for those unit tests and a question inline

keyserver/src/push/send.js
139–143 ↗(On Diff #35839)

Is there a reason we have to use such a peculiar API that is difficult to type?

As an alternative, what if we just had two functions, one that returned a minimally-encoded type and one that didn't?

lib/shared/thread-utils.js
366 ↗(On Diff #35839)

Would be good to investigate how Flow missed this. Unit tests sound like a good idea too

This revision now requires changes to proceed.Jan 21 2024, 8:43 PM
atul planned changes to this revision.Jan 23 2024, 2:30 PM
atul requested review of this revision.Jan 25 2024, 11:28 AM
atul added inline comments.
keyserver/src/push/send.js
139–143 ↗(On Diff #35839)

Is there a reason we have to use such a peculiar API that is difficult to type?

It's because rawThreadInfoFromServerThreadInfo accepts RawThreadInfoOptions:

6b5333.png (640×1 px, 142 KB)

which are passed in based on version checks at rawThreadInfoFromServerThreadInfo callsite:

d37ed4.png (1×1 px, 398 KB)

I think it makes sense to maintain the symmetry w/ the other options that are passed in via codeVersion. Would the alternative be adding a separate argument to the function to toggle between encodings?

As an alternative, what if we just had two functions, one that returned a minimally-encoded type and one that didn't?

Would we want to duplicate functionality between the two, or would we want one function to be a wrapper around the other that either encodes/decodes the thread infos?


FWIW will be updating rawThreadInfoFromServerThreadInfo as part of future "encoded permissions in memberships table" project, so it might make sense to sequence then?

lib/shared/thread-utils.js
366 ↗(On Diff #35839)

Added unit test in D10818. Will create a task to document the flow issue and jot down any notes from investigating.

This revision is now accepted and ready to land.Jan 25 2024, 5:45 PM