Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2537 & #2538 #2539

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions frontend/controller/serviceworkers/sw-primary.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ const setupRootState = () => {
lastRun: Object.create(null) // { notificationKey: number },
}
}

if (!rootState.namespaceLookups) rootState.namespaceLookups = Object.create(null)
if (!rootState.reverseNamespaceLookups) rootState.reverseNamespaceLookups = Object.create(null)
}

sbp('okTurtles.events/on', CHELONIA_RESET, setupRootState)
Expand Down
2 changes: 1 addition & 1 deletion frontend/model/getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import groupGetters from './contracts/shared/getters/group.js'
import identityGetters from './contracts/shared/getters/identity.js'

const checkedUsername = (state: Object, username: string, userID: string) => {
if (username && state.namespaceLookups[username] === userID) {
if (username && state.namespaceLookups?.[username] === userID) {
return username
}
}
Expand Down
20 changes: 20 additions & 0 deletions frontend/model/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,26 @@ sbp('sbp/selectors/register', {
sbp('gi.actions/group/fixAnyoneCanJoinLink', { contractID }).catch(e => console.error(`[state/vuex/postUpgradeVerification] Error during gi.actions/group/fixAnyoneCanJoinLink for ${contractID}:`, e))
})
}, 'gi.contracts/group')

// Fix missing `namespaceLookups`. See issue
// Promise.resolve to coerce into a promise, making `then` safe
Promise.resolve(sbp('chelonia/rootState')).then((state) => {
if (state.namespaceLookups) return

const identityContractIDs = Object.entries(state.contracts)
// $FlowFixMe[incompatible-use]
.filter(([, { type }]) => type === 'gi.contracts/identity')
.map(([id]) => id)
console.info('Fixing missing lookup entries', identityContractIDs)

return Promise.all(identityContractIDs.map((id) => {
const username = state[id].attributes?.username
if (!username) return undefined
return sbp('namespace/lookup', username, { skipCache: true })
})).catch(e => {
console.error('[state/vuex/postUpgradeVerification] Error during lookup', e)
})
})
},
'state/vuex/save': (encrypted: ?boolean, state: ?Object) => {
return sbp('okTurtles.eventQueue/queueEvent', 'state/vuex/save', async function () {
Expand Down