Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32223208
D11188.1765207923.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D11188.1765207923.diff
View Options
diff --git a/keyserver/src/version.js b/keyserver/src/version.js
--- a/keyserver/src/version.js
+++ b/keyserver/src/version.js
@@ -1,3 +1,3 @@
// @flow
-export const keyserverCodeVersion = 78;
+export const keyserverCodeVersion = 79;
diff --git a/lib/permissions/special-roles.js b/lib/permissions/special-roles.js
--- a/lib/permissions/special-roles.js
+++ b/lib/permissions/special-roles.js
@@ -65,4 +65,8 @@
return _mapValues(patchRawThreadInfoWithSpecialRole)(rawThreadInfos);
}
-export { patchRoleInfoWithSpecialRole, patchRawThreadInfosWithSpecialRole };
+export {
+ patchRoleInfoWithSpecialRole,
+ patchRawThreadInfosWithSpecialRole,
+ patchRawThreadInfoWithSpecialRole,
+};
diff --git a/web/redux/persist.js b/web/redux/persist.js
--- a/web/redux/persist.js
+++ b/web/redux/persist.js
@@ -11,6 +11,8 @@
type ReplaceKeyserverOperation,
} from 'lib/ops/keyserver-store-ops.js';
import type { ClientDBMessageStoreOperation } from 'lib/ops/message-store-ops.js';
+import type { ClientDBThreadStoreOperation } from 'lib/ops/thread-store-ops.js';
+import { patchRawThreadInfoWithSpecialRole } from 'lib/permissions/special-roles.js';
import {
createAsyncMigrate,
type StorageMigrationFunction,
@@ -25,6 +27,7 @@
import { cookieTypes } from 'lib/types/session-types.js';
import { defaultConnectionInfo } from 'lib/types/socket-types.js';
import { defaultGlobalThemeInfo } from 'lib/types/theme-types.js';
+import type { ClientDBThreadInfo } 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';
@@ -35,6 +38,10 @@
} from 'lib/utils/migration-utils.js';
import { entries } from 'lib/utils/objects.js';
import { resetUserSpecificState } from 'lib/utils/reducers-utils.js';
+import {
+ convertClientDBThreadInfoToRawThreadInfo,
+ convertRawThreadInfoToClientDBThreadInfo,
+} from 'lib/utils/thread-ops-utils.js';
import commReduxStorageEngine from './comm-redux-storage-engine.js';
import { defaultWebState } from './default-state.js';
@@ -437,6 +444,52 @@
storeOperations: { messageStoreOperations },
});
+ return state;
+ },
+ [17]: async (state: AppState) => {
+ // 1. Check if `databaseModule` is supported and early-exit if not.
+ const sharedWorker = await getCommSharedWorker();
+ const isDatabaseSupported = await sharedWorker.isSupported();
+
+ if (!isDatabaseSupported) {
+ return state;
+ }
+
+ // 2. Get existing `stores` from SQLite.
+ const stores = await sharedWorker.schedule({
+ type: workerRequestMessageTypes.GET_CLIENT_STORE,
+ });
+ invariant(stores?.store, 'Stores should exist');
+
+ const threads: $ReadOnlyArray<ClientDBThreadInfo> = stores.store.threads;
+ if (threads.length === 0) {
+ return state;
+ }
+
+ // 3. Convert to `RawThreadInfo`, patch in `specialRole`, and convert back.
+ const patchedClientDBThreadInfos: $ReadOnlyArray<ClientDBThreadInfo> =
+ threads
+ .map(convertClientDBThreadInfoToRawThreadInfo)
+ .map(patchRawThreadInfoWithSpecialRole)
+ .map(convertRawThreadInfoToClientDBThreadInfo);
+
+ // 4. Construct operations to remove existing threads and replace them
+ // with threads that have the `specialRole` field patched in.
+ const threadStoreOperations: ClientDBThreadStoreOperation[] = [];
+ threadStoreOperations.push({ type: 'remove_all' });
+ for (const clientDBThreadInfo: ClientDBThreadInfo of patchedClientDBThreadInfos) {
+ threadStoreOperations.push({
+ type: 'replace',
+ payload: clientDBThreadInfo,
+ });
+ }
+
+ // 5. Process the constructed `threadStoreOperations`.
+ await sharedWorker.schedule({
+ type: workerRequestMessageTypes.PROCESS_STORE_OPERATIONS,
+ storeOperations: { threadStoreOperations },
+ });
+
return state;
},
};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 8, 3:32 PM (8 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5848848
Default Alt Text
D11188.1765207923.diff (3 KB)
Attached To
Mode
D11188: [web] Redux migration to patch in `specialRole` field
Attached
Detach File
Event Timeline
Log In to Comment