Page MenuHomePhabricator

D12788.diff
No OneTemporary

D12788.diff

diff --git a/lib/utils/member-info-utils-test-data.js b/lib/utils/member-info-utils-test-data.js
--- a/lib/utils/member-info-utils-test-data.js
+++ b/lib/utils/member-info-utils-test-data.js
@@ -1,6 +1,10 @@
// @flow
-import type { RawThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js';
+import { type ThreadStoreWithMemberPermissions } from './member-info-utils.js';
+import type {
+ RawThreadInfo,
+ ThinRawThreadInfo,
+} from '../types/minimally-encoded-thread-permissions-types.js';
const rawThreadInfoWithMemberPermissions: any = {
minimallyEncoded: true,
@@ -209,7 +213,557 @@
pinnedCount: 0,
};
+const keyedThreadStoreInfos: ThreadStoreWithMemberPermissions = {
+ '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|1': {
+ 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: 4622361304,
+ parentThreadID: null,
+ containingThreadID: null,
+ community: null,
+ members: [
+ {
+ id: '84051',
+ role: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|83795',
+ permissions: '3',
+ 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,
+ },
+ '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84060': {
+ minimallyEncoded: true,
+ id: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84060',
+ type: 6,
+ name: '',
+ description: '',
+ color: '575757',
+ creationTime: 4622361304,
+ parentThreadID: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|1',
+ containingThreadID: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|1',
+ community: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|1',
+ members: [
+ {
+ id: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38',
+ role: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84061',
+ permissions: '2f7fff',
+ isSender: true,
+ minimallyEncoded: true,
+ },
+ {
+ id: '84051',
+ role: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84061',
+ permissions: '3027f',
+ isSender: false,
+ minimallyEncoded: true,
+ },
+ ],
+ roles: {
+ '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84061': {
+ id: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84061',
+ name: 'Members',
+ permissions: [
+ '000',
+ '010',
+ '020',
+ '100',
+ '110',
+ '030',
+ '040',
+ '060',
+ '050',
+ '090',
+ '005',
+ '015',
+ '0a9',
+ ],
+ minimallyEncoded: true,
+ specialRole: 1,
+ },
+ },
+ currentUser: {
+ role: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84061',
+ permissions: '3027f',
+ subscription: { home: true, pushNotifs: true },
+ unread: false,
+ minimallyEncoded: true,
+ },
+ repliesCount: 0,
+ pinnedCount: 0,
+ },
+ '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84062': {
+ minimallyEncoded: true,
+ id: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84062',
+ type: 7,
+ name: '',
+ description:
+ 'This is your private chat, where you can set reminders and jot notes in private!',
+ color: '5c9f5f',
+ creationTime: 4622361304,
+ parentThreadID: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|1',
+ containingThreadID: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|1',
+ community: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|1',
+ members: [
+ {
+ id: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38',
+ role: null,
+ permissions: '2c7fff',
+ isSender: false,
+ minimallyEncoded: true,
+ },
+ {
+ id: '84051',
+ role: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84063',
+ permissions: '3026f',
+ isSender: false,
+ minimallyEncoded: true,
+ },
+ ],
+ roles: {
+ '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84063': {
+ id: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84063',
+ name: 'Members',
+ permissions: [
+ '000',
+ '010',
+ '020',
+ '100',
+ '110',
+ '060',
+ '050',
+ '090',
+ '030',
+ '005',
+ '015',
+ '0a9',
+ ],
+ minimallyEncoded: true,
+ specialRole: 1,
+ },
+ },
+ currentUser: {
+ role: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84063',
+ permissions: '3026f',
+ subscription: { home: true, pushNotifs: true },
+ unread: false,
+ minimallyEncoded: true,
+ },
+ repliesCount: 0,
+ pinnedCount: 0,
+ },
+ '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84096': {
+ minimallyEncoded: true,
+ id: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84096',
+ type: 6,
+ name: '',
+ description: '',
+ color: '648caa',
+ creationTime: 4622361304,
+ parentThreadID: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|1',
+ containingThreadID: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|1',
+ community: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|1',
+ members: [
+ {
+ id: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38',
+ role: null,
+ permissions: '2c7fff',
+ isSender: false,
+ minimallyEncoded: true,
+ },
+ {
+ id: '83990',
+ role: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84097',
+ permissions: '3027f',
+ isSender: false,
+ minimallyEncoded: true,
+ },
+ {
+ id: '84051',
+ role: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84097',
+ permissions: '3027f',
+ isSender: true,
+ minimallyEncoded: true,
+ },
+ ],
+ roles: {
+ '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84097': {
+ id: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84097',
+ name: 'Members',
+ permissions: [
+ '000',
+ '010',
+ '020',
+ '100',
+ '110',
+ '030',
+ '040',
+ '060',
+ '050',
+ '090',
+ '005',
+ '015',
+ '0a9',
+ ],
+ minimallyEncoded: true,
+ specialRole: 1,
+ },
+ },
+ currentUser: {
+ role: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84097',
+ permissions: '3027f',
+ subscription: { home: true, pushNotifs: true },
+ unread: false,
+ minimallyEncoded: true,
+ },
+ repliesCount: 0,
+ pinnedCount: 0,
+ },
+};
+
+const keyedThreadStoreInfosSansMemberPermissions: {
+ +[id: string]: ThinRawThreadInfo,
+} = {
+ '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|1': {
+ 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: 4622361304,
+ parentThreadID: null,
+ containingThreadID: null,
+ community: null,
+ members: [
+ {
+ id: '84051',
+ role: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|83795',
+ 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,
+ },
+ '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84060': {
+ minimallyEncoded: true,
+ id: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84060',
+ type: 6,
+ name: '',
+ description: '',
+ color: '575757',
+ creationTime: 4622361304,
+ parentThreadID: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|1',
+ containingThreadID: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|1',
+ community: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|1',
+ members: [
+ {
+ id: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38',
+ role: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84061',
+ isSender: true,
+ minimallyEncoded: true,
+ },
+ {
+ id: '84051',
+ role: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84061',
+ isSender: false,
+ minimallyEncoded: true,
+ },
+ ],
+ roles: {
+ '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84061': {
+ id: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84061',
+ name: 'Members',
+ permissions: [
+ '000',
+ '010',
+ '020',
+ '100',
+ '110',
+ '030',
+ '040',
+ '060',
+ '050',
+ '090',
+ '005',
+ '015',
+ '0a9',
+ ],
+ minimallyEncoded: true,
+ specialRole: 1,
+ },
+ },
+ currentUser: {
+ role: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84061',
+ permissions: '3027f',
+ subscription: { home: true, pushNotifs: true },
+ unread: false,
+ minimallyEncoded: true,
+ },
+ repliesCount: 0,
+ pinnedCount: 0,
+ },
+ '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84062': {
+ minimallyEncoded: true,
+ id: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84062',
+ type: 7,
+ name: '',
+ description:
+ 'This is your private chat, where you can set reminders and jot notes in private!',
+ color: '5c9f5f',
+ creationTime: 4622361304,
+ parentThreadID: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|1',
+ containingThreadID: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|1',
+ community: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|1',
+ members: [
+ {
+ id: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38',
+ role: null,
+ isSender: false,
+ minimallyEncoded: true,
+ },
+ {
+ id: '84051',
+ role: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84063',
+ isSender: false,
+ minimallyEncoded: true,
+ },
+ ],
+ roles: {
+ '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84063': {
+ id: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84063',
+ name: 'Members',
+ permissions: [
+ '000',
+ '010',
+ '020',
+ '100',
+ '110',
+ '060',
+ '050',
+ '090',
+ '030',
+ '005',
+ '015',
+ '0a9',
+ ],
+ minimallyEncoded: true,
+ specialRole: 1,
+ },
+ },
+ currentUser: {
+ role: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84063',
+ permissions: '3026f',
+ subscription: { home: true, pushNotifs: true },
+ unread: false,
+ minimallyEncoded: true,
+ },
+ repliesCount: 0,
+ pinnedCount: 0,
+ },
+ '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84096': {
+ minimallyEncoded: true,
+ id: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84096',
+ type: 6,
+ name: '',
+ description: '',
+ color: '648caa',
+ creationTime: 4622361304,
+ parentThreadID: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|1',
+ containingThreadID: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|1',
+ community: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|1',
+ members: [
+ {
+ id: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38',
+ role: null,
+ isSender: false,
+ minimallyEncoded: true,
+ },
+ {
+ id: '83990',
+ role: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84097',
+ isSender: false,
+ minimallyEncoded: true,
+ },
+ {
+ id: '84051',
+ role: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84097',
+ isSender: true,
+ minimallyEncoded: true,
+ },
+ ],
+ roles: {
+ '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84097': {
+ id: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84097',
+ name: 'Members',
+ permissions: [
+ '000',
+ '010',
+ '020',
+ '100',
+ '110',
+ '030',
+ '040',
+ '060',
+ '050',
+ '090',
+ '005',
+ '015',
+ '0a9',
+ ],
+ minimallyEncoded: true,
+ specialRole: 1,
+ },
+ },
+ currentUser: {
+ role: '76F9CE14-9106-4DD3-A69C-CFDC8E9CAC38|84097',
+ permissions: '3027f',
+ subscription: { home: true, pushNotifs: true },
+ unread: false,
+ minimallyEncoded: true,
+ },
+ repliesCount: 0,
+ pinnedCount: 0,
+ },
+};
+
export {
rawThreadInfoWithMemberPermissions,
rawThreadInfoSansMemberPermissions,
+ keyedThreadStoreInfos,
+ keyedThreadStoreInfosSansMemberPermissions,
};
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,8 +3,10 @@
import type {
MemberInfoSansPermissions,
MemberInfoWithPermissions,
+ RawThreadInfo,
ThinRawThreadInfo,
} from '../types/minimally-encoded-thread-permissions-types.js';
+import type { RawThreadInfos } from '../types/thread-types.js';
function stripPermissionsFromMemberInfo(
memberInfo: MemberInfoWithPermissions,
@@ -27,7 +29,28 @@
};
}
+export type ThreadStoreWithMemberPermissions = {
+ +[id: string]: ThinRawThreadInfoWithPermissions,
+};
+// NOTE: Don't modify this function without understanding
+// how it may affect existing client migrations.
+function stripMemberPermissionsFromRawThreadInfos(
+ threadStoreInfos: ThreadStoreWithMemberPermissions,
+): RawThreadInfos {
+ const strippedThreadStoreInfos: { [id: string]: RawThreadInfo } = {};
+
+ for (const threadID in threadStoreInfos) {
+ const rawThreadInfo: ThinRawThreadInfoWithPermissions =
+ threadStoreInfos[threadID];
+ const updatedRawThreadInfo: ThinRawThreadInfo =
+ stripMemberPermissionsFromRawThreadInfo(rawThreadInfo);
+ strippedThreadStoreInfos[threadID] = updatedRawThreadInfo;
+ }
+
+ return strippedThreadStoreInfos;
+}
export {
stripPermissionsFromMemberInfo,
stripMemberPermissionsFromRawThreadInfo,
+ stripMemberPermissionsFromRawThreadInfos,
};
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,11 +1,14 @@
// @flow
import {
+ keyedThreadStoreInfos,
+ keyedThreadStoreInfosSansMemberPermissions,
rawThreadInfoSansMemberPermissions,
rawThreadInfoWithMemberPermissions,
} from './member-info-utils-test-data.js';
import {
stripMemberPermissionsFromRawThreadInfo,
+ stripMemberPermissionsFromRawThreadInfos,
stripPermissionsFromMemberInfo,
} from './member-info-utils.js';
import type {
@@ -46,3 +49,14 @@
expect(strippedRawThreadInfo).toEqual(rawThreadInfoSansMemberPermissions);
});
});
+
+describe('stripMemberPermissionsFromRawThreadInfos', () => {
+ test('should strip member permissions from RawThreadInfos', () => {
+ const strippedRawThreadInfos = stripMemberPermissionsFromRawThreadInfos(
+ keyedThreadStoreInfos,
+ );
+ expect(strippedRawThreadInfos).toEqual(
+ keyedThreadStoreInfosSansMemberPermissions,
+ );
+ });
+});

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 27, 7:34 AM (20 h, 48 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2589425
Default Alt Text
D12788.diff (17 KB)

Event Timeline