Page MenuHomePhabricator

D9589.id32375.diff
No OneTemporary

D9589.id32375.diff

diff --git a/lib/permissions/minimally-encoded-thread-permissions.js b/lib/permissions/minimally-encoded-thread-permissions.js
--- a/lib/permissions/minimally-encoded-thread-permissions.js
+++ b/lib/permissions/minimally-encoded-thread-permissions.js
@@ -34,9 +34,9 @@
manage_invite_links: BigInt(1) << BigInt(20),
});
-// TODO (atul): Update flow to `194.0.0` for bigint support
-// $FlowIssue bigint-unsupported
-const permissionsToBitmask = (permissions: ThreadPermissionsInfo): bigint => {
+const permissionsToBitmaskHex = (
+ permissions: ThreadPermissionsInfo,
+): string => {
let bitmask = BigInt(0);
for (const [key, permission] of entries(permissions)) {
if (permission.value && key in minimallyEncodedThreadPermissions) {
@@ -49,15 +49,14 @@
bitmask |= minimallyEncodedThreadPermissions[key];
}
}
- return bitmask;
+ return bitmask.toString(16);
};
const hasPermission = (
- // TODO (atul): Update flow to `194.0.0` for bigint support
- // $FlowIssue bigint-unsupported
- permissionsBitmask: bigint,
+ permissionsBitmaskHex: string,
permission: ThreadPermission,
): boolean => {
+ const permissionsBitmask = BigInt(`0x${permissionsBitmaskHex}`);
if (!(permission in minimallyEncodedThreadPermissions)) {
return false;
}
@@ -73,6 +72,6 @@
export {
minimallyEncodedThreadPermissions,
- permissionsToBitmask,
+ permissionsToBitmaskHex,
hasPermission,
};
diff --git a/lib/permissions/minimally-encoded-thread-permissions.test.js b/lib/permissions/minimally-encoded-thread-permissions.test.js
--- a/lib/permissions/minimally-encoded-thread-permissions.test.js
+++ b/lib/permissions/minimally-encoded-thread-permissions.test.js
@@ -2,7 +2,7 @@
import {
hasPermission,
- permissionsToBitmask,
+ permissionsToBitmaskHex,
} from './minimally-encoded-thread-permissions.js';
describe('minimallyEncodedThreadPermissions', () => {
@@ -28,8 +28,8 @@
};
it('should encode ThreadPermissionsInfo as bitmask', () => {
- const permissionsBitmask = permissionsToBitmask(permissions);
- expect(permissionsBitmask.toString(2)).toBe('110111001111111111');
+ const permissionsBitmask = permissionsToBitmaskHex(permissions);
+ expect(permissionsBitmask).toBe('373ff');
expect(hasPermission(permissionsBitmask, 'know_of')).toBe(true);
expect(hasPermission(permissionsBitmask, 'visible')).toBe(true);
expect(hasPermission(permissionsBitmask, 'voiced')).toBe(true);

File Metadata

Mime Type
text/plain
Expires
Mon, Nov 25, 10:54 PM (21 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2580915
Default Alt Text
D9589.id32375.diff (2 KB)

Event Timeline