Page MenuHomePhabricator

[lib] Introduce `minimallyEncodeRawThreadInfo(RawThreadInfo): MinimallyEncodedRawThreadInfo`
ClosedPublic

Authored by atul on Nov 6 2023, 3:27 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Nov 3, 10:25 AM
Unknown Object (File)
Sat, Nov 2, 9:46 AM
Unknown Object (File)
Fri, Nov 1, 7:42 AM
Unknown Object (File)
Oct 10 2024, 5:36 PM
Unknown Object (File)
Oct 10 2024, 5:36 PM
Unknown Object (File)
Oct 10 2024, 5:36 PM
Unknown Object (File)
Oct 10 2024, 5:36 PM
Unknown Object (File)
Oct 10 2024, 5:33 PM
Subscribers

Details

Summary

Handy utility function that will make encoding/decoding of permissions/role permissions much simpler at callsite and avoid polluting with a bunch of permission encoding related stuff in eg rawThreadInfosFromServerThreadInfos.


Depends on D9736

Test Plan

Single unit test for now, will add more after decode function is introduced.

Diff Detail

Repository
rCOMM Comm
Branch
arcpatch-D9737 (branched from master)
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

atul published this revision for review.Nov 6 2023, 3:28 PM
tomek added inline comments.
lib/permissions/minimally-encoded-thread-permissions.js
213–232 ↗(On Diff #32840)

Why do we encode permissions differently in these cases?

275–280 ↗(On Diff #32840)

It is ok as is, but you can consider using mapValues from lodash

This revision is now accepted and ready to land.Nov 7 2023, 1:40 AM
lib/permissions/minimally-encoded-thread-permissions.js
213–232 ↗(On Diff #32840)

For currentUserInfo and memberInfo, permissions are of type ThreadPermissionsInfo and look like:

know_of: { value: true, source: '1' },
visible: { value: true, source: '1' },
voiced: { value: true, source: '1' },

Whereas for roleInfo, they're of type ThreadPermissionsBlob which look like:

descendant_open_know_of: true,
descendant_open_visible: true,
descendant_opentoplevel_join_thread: true,
edit_entries: true,
edit_message: true,
edit_permissions: true,
edit_thread: true,
edit_thread_avatar: true,

It's definitely a bit confusing because of the naming of the types is similar and the "key" in all of the objects is permissions.

213–232 ↗(On Diff #32840)

(Let me know if there's something I'm missing and didn't answer question you were asking)

275–280 ↗(On Diff #32840)

Oh true, that's a lot cleaner! Will update this diff, thanks for flagging that

improve readability by using lodash mapValues

This revision was landed with ongoing or failed builds.Nov 7 2023, 10:08 AM
This revision was automatically updated to reflect the committed changes.
lib/permissions/minimally-encoded-thread-permissions.js
213–232 ↗(On Diff #32840)

Thanks! That makes sense