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)
Thu, Jan 23, 5:02 AM
Unknown Object (File)
Mon, Jan 20, 3:06 PM
Unknown Object (File)
Mon, Jan 20, 3:06 PM
Unknown Object (File)
Mon, Jan 20, 3:06 PM
Unknown Object (File)
Mon, Jan 20, 3:05 PM
Unknown Object (File)
Mon, Jan 20, 2:53 PM
Unknown Object (File)
Thu, Jan 9, 11:24 AM
Unknown Object (File)
Sat, Jan 4, 11:54 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
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

Why do we encode permissions differently in these cases?

275–280

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

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

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

275–280

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

Thanks! That makes sense