feat: use transaction when uploading prekeys

This commit is contained in:
Adhiraj Singh
2022-03-29 13:41:41 +05:30
parent bb9f233de4
commit 89e35ec18a

View File

@@ -60,6 +60,8 @@ export const makeSocket = ({
} }
const { creds } = authState const { creds } = authState
// add transaction capability
const keys = addTransactionCapability(authState.keys, logger)
let lastDateRecv: Date let lastDateRecv: Date
let epoch = 0 let epoch = 0
@@ -230,10 +232,14 @@ export const makeSocket = ({
update.serverHasPreKeys = true update.serverHasPreKeys = true
} }
await authState.keys.set({ 'pre-key': newPreKeys }) await keys.transaction(
async() => {
await keys.set({ 'pre-key': newPreKeys })
const preKeys = await getPreKeys(authState.keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1]) const preKeys = await getPreKeys(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1])
await execute(preKeys) await execute(preKeys)
}
)
ev.emit('creds.update', update) ev.emit('creds.update', update)
} }
@@ -574,11 +580,7 @@ export const makeSocket = ({
type: 'md' as 'md', type: 'md' as 'md',
ws, ws,
ev, ev,
authState: { authState: { creds, keys },
creds,
// add capability
keys: addTransactionCapability(authState.keys, logger)
},
get user() { get user() {
return authState.creds.me return authState.creds.me
}, },