feat: add state sync keys in transaction

This commit is contained in:
Adhiraj Singh
2022-03-21 23:29:43 +05:30
parent 4962070c29
commit e731de5deb

View File

@@ -168,15 +168,18 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
const keys = protocolMsg.appStateSyncKeyShare!.keys
if(keys?.length) {
let newAppStateSyncKeyId = ''
for(const { keyData, keyId } of keys) {
const strKeyId = Buffer.from(keyId.keyId!).toString('base64')
await authState.keys.transaction(
async() => {
for(const { keyData, keyId } of keys) {
const strKeyId = Buffer.from(keyId.keyId!).toString('base64')
logger.info({ strKeyId }, 'injecting new app state sync key')
await authState.keys.set({ 'app-state-sync-key': { [strKeyId]: keyData } })
newAppStateSyncKeyId = strKeyId
}
logger.info({ strKeyId }, 'injecting new app state sync key')
await authState.keys.set({ 'app-state-sync-key': { [strKeyId]: keyData } })
newAppStateSyncKeyId = strKeyId
}
}
)
ev.emit('creds.update', { myAppStateKeyId: newAppStateSyncKeyId })
} else {
logger.info({ protocolMsg }, 'recv app state sync with 0 keys')