Page MenuHomePhabricator

D12763.diff
No OneTemporary

D12763.diff

diff --git a/lib/utils/member-info-utils-test-data.js b/lib/utils/member-info-utils-test-data.js
new file mode 100644
--- /dev/null
+++ b/lib/utils/member-info-utils-test-data.js
@@ -0,0 +1,215 @@
+// @flow
+
+import type { RawThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js';
+
+const rawThreadInfoWithMemberPermissions: any = {
+ minimallyEncoded: true,
+ id: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|1',
+ type: 12,
+ name: 'GENESIS',
+ description:
+ 'This is the first community on Comm. In the future it will be possible to create chats outside of a community, but for now all of these chats get set with GENESIS as their parent. GENESIS is hosted on Ashoat’s keyserver.',
+ color: '008f83',
+ creationTime: 3764,
+ parentThreadID: null,
+ containingThreadID: null,
+ community: null,
+ members: [
+ {
+ id: '83814',
+ role: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|83795',
+ permissions: '3',
+ isSender: false,
+ minimallyEncoded: true,
+ },
+ {
+ id: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38',
+ role: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|83820',
+ permissions: '2f7fff',
+ isSender: true,
+ minimallyEncoded: true,
+ },
+ {
+ id: '83814',
+ role: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|83820',
+ permissions: '3027f',
+ isSender: false,
+ minimallyEncoded: true,
+ },
+ ],
+ roles: {
+ '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|83795': {
+ id: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|83795',
+ name: 'Members',
+ permissions: ['000', '010', '005', '015', '0a7'],
+ minimallyEncoded: true,
+ specialRole: 1,
+ },
+ '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|83796': {
+ id: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|83796',
+ name: 'Admins',
+ permissions: [
+ '000',
+ '010',
+ '020',
+ '100',
+ '110',
+ '030',
+ '040',
+ '060',
+ '050',
+ '120',
+ '080',
+ '090',
+ '070',
+ '0d0',
+ '0e0',
+ '130',
+ '140',
+ '150',
+ '160',
+ '004',
+ '014',
+ '0a6',
+ '0a8',
+ '024',
+ '034',
+ '044',
+ '064',
+ '054',
+ '124',
+ '086',
+ '096',
+ '0c4',
+ '074',
+ '0b4',
+ '0d4',
+ '0e4',
+ '134',
+ '156',
+ '0c0',
+ ],
+ minimallyEncoded: true,
+ specialRole: 2,
+ },
+ },
+ currentUser: {
+ role: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|83795',
+ permissions: '3',
+ subscription: {
+ home: true,
+ pushNotifs: true,
+ },
+ unread: false,
+ minimallyEncoded: true,
+ },
+ repliesCount: 0,
+ pinnedCount: 0,
+};
+
+const rawThreadInfoSansMemberPermissions: RawThreadInfo = {
+ minimallyEncoded: true,
+ id: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|1',
+ type: 12,
+ name: 'GENESIS',
+ description:
+ 'This is the first community on Comm. In the future it will be possible to create chats outside of a community, but for now all of these chats get set with GENESIS as their parent. GENESIS is hosted on Ashoat’s keyserver.',
+ color: '008f83',
+ creationTime: 3764,
+ parentThreadID: null,
+ containingThreadID: null,
+ community: null,
+ members: [
+ {
+ id: '83814',
+ role: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|83795',
+ isSender: false,
+ minimallyEncoded: true,
+ },
+ {
+ id: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38',
+ role: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|83820',
+ isSender: true,
+ minimallyEncoded: true,
+ },
+ {
+ id: '83814',
+ role: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|83820',
+ isSender: false,
+ minimallyEncoded: true,
+ },
+ ],
+ roles: {
+ '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|83795': {
+ id: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|83795',
+ name: 'Members',
+ permissions: ['000', '010', '005', '015', '0a7'],
+ minimallyEncoded: true,
+ specialRole: 1,
+ },
+ '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|83796': {
+ id: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|83796',
+ name: 'Admins',
+ permissions: [
+ '000',
+ '010',
+ '020',
+ '100',
+ '110',
+ '030',
+ '040',
+ '060',
+ '050',
+ '120',
+ '080',
+ '090',
+ '070',
+ '0d0',
+ '0e0',
+ '130',
+ '140',
+ '150',
+ '160',
+ '004',
+ '014',
+ '0a6',
+ '0a8',
+ '024',
+ '034',
+ '044',
+ '064',
+ '054',
+ '124',
+ '086',
+ '096',
+ '0c4',
+ '074',
+ '0b4',
+ '0d4',
+ '0e4',
+ '134',
+ '156',
+ '0c0',
+ ],
+ minimallyEncoded: true,
+ specialRole: 2,
+ },
+ },
+ currentUser: {
+ role: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|83795',
+ permissions: '3',
+ subscription: {
+ home: true,
+ pushNotifs: true,
+ },
+ unread: false,
+ minimallyEncoded: true,
+ },
+ repliesCount: 0,
+ pinnedCount: 0,
+};
+
+export {
+ rawThreadInfoWithMemberPermissions,
+ rawThreadInfoSansMemberPermissions,
+};
diff --git a/lib/utils/member-info-utils.js b/lib/utils/member-info-utils.js
--- a/lib/utils/member-info-utils.js
+++ b/lib/utils/member-info-utils.js
@@ -3,6 +3,7 @@
import type {
MemberInfoSansPermissions,
MemberInfoWithPermissions,
+ ThinRawThreadInfo,
} from '../types/minimally-encoded-thread-permissions-types.js';
function stripPermissionsFromMemberInfo(
@@ -12,4 +13,21 @@
return rest;
}
-export { stripPermissionsFromMemberInfo };
+export type ThinRawThreadInfoWithPermissions = $ReadOnly<{
+ ...ThinRawThreadInfo,
+ +members: $ReadOnlyArray<MemberInfoWithPermissions>,
+}>;
+
+function stripMemberPermissionsFromRawThreadInfo(
+ rawThreadInfo: ThinRawThreadInfoWithPermissions,
+): ThinRawThreadInfo {
+ return {
+ ...rawThreadInfo,
+ members: rawThreadInfo.members.map(stripPermissionsFromMemberInfo),
+ };
+}
+
+export {
+ stripPermissionsFromMemberInfo,
+ stripMemberPermissionsFromRawThreadInfo,
+};
diff --git a/lib/utils/member-info-utils.test.js b/lib/utils/member-info-utils.test.js
--- a/lib/utils/member-info-utils.test.js
+++ b/lib/utils/member-info-utils.test.js
@@ -1,9 +1,17 @@
// @flow
-import { stripPermissionsFromMemberInfo } from './member-info-utils.js';
+import {
+ rawThreadInfoSansMemberPermissions,
+ rawThreadInfoWithMemberPermissions,
+} from './member-info-utils-test-data.js';
+import {
+ stripMemberPermissionsFromRawThreadInfo,
+ stripPermissionsFromMemberInfo,
+} from './member-info-utils.js';
import type {
MemberInfoSansPermissions,
MemberInfoWithPermissions,
+ RawThreadInfo,
} from '../types/minimally-encoded-thread-permissions-types.js';
describe('stripPermissionsFromMemberInfo', () => {
@@ -27,3 +35,14 @@
});
});
});
+
+describe('stripMemberPermissionsFromRawThreadInfo', () => {
+ test('should produce valid RawThreadInfo', () => {
+ const strippedRawThreadInfo: RawThreadInfo =
+ stripMemberPermissionsFromRawThreadInfo(
+ rawThreadInfoWithMemberPermissions,
+ );
+
+ expect(strippedRawThreadInfo).toEqual(rawThreadInfoSansMemberPermissions);
+ });
+});

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 23, 8:24 PM (20 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2572339
Default Alt Text
D12763.diff (7 KB)

Event Timeline