diff --git a/src/Socket/chats.ts b/src/Socket/chats.ts index e17a435..1bca767 100644 --- a/src/Socket/chats.ts +++ b/src/Socket/chats.ts @@ -22,6 +22,7 @@ export const makeChatsSocket = (config: SocketConfig) => { sendNode, query, onUnexpectedError, + logout } = sock let privacySettings: { [_: string]: string } | undefined @@ -35,7 +36,14 @@ export const makeChatsSocket = (config: SocketConfig) => { const appStateSyncTimeout = debouncedTimeout( APP_STATE_SYNC_TIMEOUT_MS, async() => { + if(!authState.creds.myAppStateKeyId) { + logger.warn('myAppStateKeyId not synced, bad link') + await logout('Incomplete app state key sync') + return + } + if(ws.readyState === ws.OPEN) { + logger.info( { recvChats: Object.keys(recvChats).length }, 'doing initial app state sync' diff --git a/src/Socket/socket.ts b/src/Socket/socket.ts index dcc8ef2..1e46c4f 100644 --- a/src/Socket/socket.ts +++ b/src/Socket/socket.ts @@ -396,7 +396,7 @@ export const makeSocket = ({ ) /** logout & invalidate connection */ - const logout = async() => { + const logout = async(msg?: string) => { const jid = authState.creds.me?.id if(jid) { await sendNode({ @@ -419,7 +419,7 @@ export const makeSocket = ({ }) } - end(new Boom('Intentional Logout', { statusCode: DisconnectReason.loggedOut })) + end(new Boom(msg || 'Intentional Logout', { statusCode: DisconnectReason.loggedOut })) } ws.on('message', onMessageRecieved)