Skip to content

Commit e79edbe

Browse files
committed
WIP: Fast-path login
1 parent ac0853a commit e79edbe

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

frontend/controller/actions/identity.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -411,26 +411,26 @@ export default (sbp('sbp/selectors/register', {
411411
}
412412

413413
try {
414-
if (!state) {
414+
await sbp('gi.db/settings/save', SETTING_CURRENT_USER, identityContractID)
415+
sbp('okTurtles.events/emit', LOGIN, { identityContractID, encryptionParams, state })
416+
417+
try {
418+
if (!state) {
415419
// Make sure we don't unsubscribe from our own identity contract
416420
// Note that this should be done _after_ calling
417421
// `chelonia/storeSecretKeys`: If the following line results in
418422
// syncing the identity contract and fetching events, the secret keys
419423
// for processing them will not be available otherwise.
420-
await sbp('chelonia/contract/retain', identityContractID)
421-
} else {
424+
await sbp('chelonia/contract/retain', identityContractID)
425+
} else {
422426
// If there is a state, we've already retained the identity contract
423427
// but might need to fetch the latest events
424-
await sbp('chelonia/contract/sync', identityContractID)
428+
await sbp('chelonia/contract/sync', identityContractID)
429+
}
430+
} catch (e) {
431+
console.error('[gi.actions/identity] Error during login contract sync', e)
432+
throw new GIErrorUIRuntimeError(L('Error during login contract sync'), { cause: e })
425433
}
426-
} catch (e) {
427-
console.error('[gi.actions/identity] Error during login contract sync', e)
428-
throw new GIErrorUIRuntimeError(L('Error during login contract sync'), { cause: e })
429-
}
430-
431-
try {
432-
await sbp('gi.db/settings/save', SETTING_CURRENT_USER, identityContractID)
433-
sbp('okTurtles.events/emit', LOGIN, { identityContractID, encryptionParams, state })
434434

435435
const contractIDs = groupContractsByType(cheloniaState?.contracts)
436436
await syncContractsInOrder(contractIDs)

frontend/controller/app/identity.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,19 @@ sbp('okTurtles.events/on', LOGIN, async ({ identityContractID, encryptionParams,
119119

120120
// NOTE: users could notice that they leave the group by someone
121121
// else when they log in
122-
const currentState = sbp('state/vuex/state')
123-
if (!currentState.currentGroupId) {
124-
const gId = Object.keys(currentState.contracts)
125-
.find(cID => currentState[identityContractID].groups[cID] && !currentState[identityContractID].groups[cID].hasLeft)
126-
127-
if (gId) {
128-
sbp('gi.app/group/switch', gId)
122+
sbp('chelonia/queueInvocation', identityContractID, () => {
123+
const currentState = sbp('state/vuex/state')
124+
if (!currentState.currentGroupId && currentState[identityContractID]?.groups) {
125+
const gId = Object.keys(currentState.contracts)
126+
.find(cID => currentState[identityContractID].groups[cID] && !currentState[identityContractID].groups[cID].hasLeft)
127+
128+
if (gId) {
129+
sbp('gi.app/group/switch', gId)
130+
}
129131
}
130-
}
132+
}).catch(e => {
133+
console.error('[LOGIN] Error setting current group ID', e)
134+
})
131135

132136
// Whenever there's an active session, the encrypted save state should be
133137
// removed, as it is only used for recovering the state when logging in

0 commit comments

Comments
 (0)