Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3368022
D12790.id44977.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D12790.id44977.diff
View Options
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
@@ -4,6 +4,7 @@
MemberInfoSansPermissions,
MemberInfoWithPermissions,
RawThreadInfo,
+ ThickRawThreadInfo,
ThinRawThreadInfo,
} from '../types/minimally-encoded-thread-permissions-types.js';
import type { RawThreadInfos } from '../types/thread-types.js';
@@ -30,7 +31,7 @@
}
export type ThreadStoreWithMemberPermissions = {
- +[id: string]: ThinRawThreadInfoWithPermissions,
+ +[id: string]: ThinRawThreadInfoWithPermissions | ThickRawThreadInfo,
};
// NOTE: Don't modify this function without understanding
// how it may affect existing client migrations.
@@ -40,8 +41,13 @@
const strippedThreadStoreInfos: { [id: string]: RawThreadInfo } = {};
for (const threadID in threadStoreInfos) {
- const rawThreadInfo: ThinRawThreadInfoWithPermissions =
- threadStoreInfos[threadID];
+ const rawThreadInfo = threadStoreInfos[threadID];
+
+ if (rawThreadInfo.thick) {
+ strippedThreadStoreInfos[threadID] = rawThreadInfo;
+ continue;
+ }
+
const updatedRawThreadInfo: ThinRawThreadInfo =
stripMemberPermissionsFromRawThreadInfo(rawThreadInfo);
strippedThreadStoreInfos[threadID] = updatedRawThreadInfo;
diff --git a/native/redux/persist.js b/native/redux/persist.js
--- a/native/redux/persist.js
+++ b/native/redux/persist.js
@@ -1492,6 +1492,10 @@
},
ops: {},
}): MigrationFunction<NavInfo, AppState>),
+ [84]: (async (state: AppState) => ({
+ state,
+ ops: {},
+ }): MigrationFunction<NavInfo, AppState>),
});
// NOTE: renaming this object, and especially the `version` property
diff --git a/web/redux/persist.js b/web/redux/persist.js
--- a/web/redux/persist.js
+++ b/web/redux/persist.js
@@ -1,6 +1,7 @@
// @flow
import invariant from 'invariant';
+import _keyBy from 'lodash/fp/keyBy.js';
import { getStoredState, purgeStoredState } from 'redux-persist';
import storage from 'redux-persist/es/storage/index.js';
import type { PersistConfig } from 'redux-persist/src/types.js';
@@ -16,7 +17,10 @@
type ClientDBMessageStoreOperation,
type MessageStoreOperation,
} from 'lib/ops/message-store-ops.js';
-import type { ClientDBThreadStoreOperation } from 'lib/ops/thread-store-ops.js';
+import type {
+ ClientDBThreadStoreOperation,
+ ThreadStoreOperation,
+} from 'lib/ops/thread-store-ops.js';
import { patchRawThreadInfoWithSpecialRole } from 'lib/permissions/special-roles.js';
import { createUpdateDBOpsForThreadStoreThreadInfos } from 'lib/shared/redux/client-db-utils.js';
import { deprecatedUpdateRolesAndPermissions } from 'lib/shared/redux/deprecated-update-roles-and-permissions.js';
@@ -30,11 +34,16 @@
import type { WebNavInfo } from 'lib/types/nav-types.js';
import { cookieTypes } from 'lib/types/session-types.js';
import { defaultConnectionInfo } from 'lib/types/socket-types.js';
+import type { StoreOperations } from 'lib/types/store-ops-types.js';
import { defaultGlobalThemeInfo } from 'lib/types/theme-types.js';
-import type { ClientDBThreadInfo } from 'lib/types/thread-types.js';
+import type {
+ ClientDBThreadInfo,
+ RawThreadInfos,
+} from 'lib/types/thread-types.js';
import { getConfig } from 'lib/utils/config.js';
import { parseCookies } from 'lib/utils/cookie-utils.js';
import { isDev } from 'lib/utils/dev-utils.js';
+import { stripMemberPermissionsFromRawThreadInfos } from 'lib/utils/member-info-utils.js';
import {
generateIDSchemaMigrationOpsForDrafts,
convertDraftStoreToNewIDSchema,
@@ -43,7 +52,7 @@
type MigrationFunction,
type MigrationsManifest,
} from 'lib/utils/migration-utils.js';
-import { entries } from 'lib/utils/objects.js';
+import { entries, values } from 'lib/utils/objects.js';
import {
convertClientDBThreadInfoToRawThreadInfo,
convertRawThreadInfoToClientDBThreadInfo,
@@ -644,6 +653,71 @@
},
ops: {},
}): MigrationFunction<WebNavInfo, AppState>),
+ [84]: (async (state: AppState) => {
+ const sharedWorker = await getCommSharedWorker();
+ const isDatabaseSupported = await sharedWorker.isSupported();
+
+ if (!isDatabaseSupported) {
+ return {
+ state,
+ ops: {},
+ };
+ }
+
+ const stores = await sharedWorker.schedule({
+ type: workerRequestMessageTypes.GET_CLIENT_STORE,
+ });
+
+ const clientDBThreadInfos: ?$ReadOnlyArray<ClientDBThreadInfo> =
+ stores?.store?.threads;
+
+ if (
+ clientDBThreadInfos === null ||
+ clientDBThreadInfos === undefined ||
+ clientDBThreadInfos.length === 0
+ ) {
+ return {
+ state,
+ ops: {},
+ };
+ }
+
+ // 1. Translate `ClientDBThreadInfo`s to `RawThreadInfo`s.
+ const rawThreadInfos = clientDBThreadInfos.map(
+ convertClientDBThreadInfoToRawThreadInfo,
+ );
+
+ // 2. Convert `RawThreadInfo`s to a map of `threadID` => `threadInfo`.
+ const keyedRawThreadInfos = _keyBy('id')(rawThreadInfos);
+
+ // This isn't actually accurate, but we force this cast here because the
+ // types for createUpdateDBOpsForThreadStoreThreadInfos assume they're
+ // converting from a client DB that contains RawThreadInfos. In fact, at
+ // this point the client DB contains ThinRawThreadInfoWithPermissions.
+ const stripMemberPermissions: RawThreadInfos => RawThreadInfos =
+ (stripMemberPermissionsFromRawThreadInfos: any);
+
+ // 3. Apply `stripMemberPermissions` to `ThreadInfo`s.
+ const updatedKeyedRawThreadInfos =
+ stripMemberPermissions(keyedRawThreadInfos);
+
+ // 4. Convert the updated `RawThreadInfos` back into an array.
+ const updatedKeyedRawThreadInfosArray = values(updatedKeyedRawThreadInfos);
+
+ // 5. Construct `ThreadStoreOperation`s.
+ const threadOperations: ThreadStoreOperation[] = [{ type: 'remove_all' }];
+ for (const rawThreadInfo of updatedKeyedRawThreadInfosArray) {
+ threadOperations.push({
+ type: 'replace',
+ payload: { id: rawThreadInfo.id, threadInfo: rawThreadInfo },
+ });
+ }
+
+ const operations: StoreOperations = {
+ threadStoreOperations: threadOperations,
+ };
+ return { state, ops: operations };
+ }: MigrationFunction<WebNavInfo, AppState>),
};
const persistConfig: PersistConfig = {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 26, 5:48 PM (10 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2585645
Default Alt Text
D12790.id44977.diff (6 KB)
Attached To
Mode
D12790: [web] Introduce `web` migration to strip member permissions
Attached
Detach File
Event Timeline
Log In to Comment