Skip to content

Commit

Permalink
[native][web] Fix keyserver store tranform error
Browse files Browse the repository at this point in the history
Summary:
issue: https://linear.app/comm/issue/ENG-4930/keyserver-missing-from-keyserverstore
Please see this comment for detailed explantion of the solution: https://linear.app/comm/issue/ENG-4930/keyserver-missing-from-keyserverstore#comment-62fa00d1

Test Plan: Checked that after the migrations were added, the error does not appear.

Reviewers: michal, kamil

Reviewed By: michal

Subscribers: ashoat, tomek

Differential Revision: https://phab.comm.dev/D9246
  • Loading branch information
InkaAlicja committed Nov 13, 2023
1 parent 2e6b15a commit af77993
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
27 changes: 24 additions & 3 deletions native/redux/persist.js
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,28 @@ const migrations = {
},
};
},
[57]: async state => {
const {
// eslint-disable-next-line no-unused-vars
connection,
keyserverStore: { keyserverInfos },
...rest
} = state;
const newKeyserverInfos = {};
for (const key in keyserverInfos) {
newKeyserverInfos[key] = {
...keyserverInfos[key],
connection: { ...defaultConnectionInfo },
};
}
return {
...rest,
keyserverStore: {
...state.keyserverStore,
keyserverInfos: newKeyserverInfos,
},
};
},
};

// After migration 31, we'll no longer want to persist `messageStore.messages`
Expand Down Expand Up @@ -954,11 +976,10 @@ const keyserverStoreTransform: Transform = createTransform(
},
(state: PersistedKeyserverStore): KeyserverStore => {
const keyserverInfos = {};
const defaultConnection = defaultConnectionInfo;
for (const key in state.keyserverInfos) {
keyserverInfos[key] = {
...state.keyserverInfos[key],
connection: { ...defaultConnection },
connection: { ...defaultConnectionInfo },
};
}
return {
Expand All @@ -985,7 +1006,7 @@ const persistConfig = {
'connection',
],
debug: __DEV__,
version: 56,
version: 57,
transforms: [
messageStoreMessagesBlocklistTransform,
reportStoreTransform,
Expand Down
24 changes: 21 additions & 3 deletions web/redux/persist.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,25 @@ const migrations = {
},
},
}),
[10]: async state => {
const { keyserverInfos } = state.keyserverStore;
const newKeyserverInfos = {};
for (const key in keyserverInfos) {
newKeyserverInfos[key] = {
...keyserverInfos[key],
connection: { ...defaultConnectionInfo },
updatesCurrentAsOf: 0,
sessionID: null,
};
}
return {
...state,
keyserverStore: {
...state.keyserverStore,
keyserverInfos: newKeyserverInfos,
},
};
},
};

const persistWhitelist = [
Expand Down Expand Up @@ -267,11 +286,10 @@ const keyserverStoreTransform: Transform = createTransform(
},
(state: PersistedKeyserverStore): KeyserverStore => {
const keyserverInfos = {};
const defaultConnection = defaultConnectionInfo;
for (const key in state.keyserverInfos) {
keyserverInfos[key] = {
...state.keyserverInfos[key],
connection: { ...defaultConnection },
connection: { ...defaultConnectionInfo },
updatesCurrentAsOf: 0,
sessionID: null,
};
Expand All @@ -295,7 +313,7 @@ const persistConfig: PersistConfig = {
{ debug: isDev },
migrateStorageToSQLite,
): any),
version: 9,
version: 10,
transforms: [keyserverStoreTransform],
};

Expand Down

0 comments on commit af77993

Please sign in to comment.