diff --git a/src/LegacySocket/auth.ts b/src/LegacySocket/auth.ts index e8d87d1..262a37c 100644 --- a/src/LegacySocket/auth.ts +++ b/src/LegacySocket/auth.ts @@ -258,9 +258,9 @@ const makeAuthSocket = (config: LegacySocketConfig) => { return { ...socket, + state, + authInfo, ev, - getState: () => state, - getAuthInfo: () => authInfo, waitForConnection, canLogin, logout diff --git a/src/LegacySocket/chats.ts b/src/LegacySocket/chats.ts index 96c7b34..9bd39da 100644 --- a/src/LegacySocket/chats.ts +++ b/src/LegacySocket/chats.ts @@ -13,7 +13,7 @@ const makeChatsSocket = (config: LegacySocketConfig) => { setQuery, query, sendNode, - getState + state } = sock const chatsDebounceTimeout = debouncedTimeout(10_000, () => sendChatsQuery(1)) @@ -212,10 +212,10 @@ const makeChatsSocket = (config: LegacySocketConfig) => { }) // User Profile Name Updates socketEvents.on('CB:Conn,pushname', json => { - const { legacy: { user }, connection } = getState() + const { legacy: { user }, connection } = state if(connection === 'open' && json[1].pushname !== user.name) { user.name = json[1].pushname - ev.emit('connection.update', { legacy: { ...getState().legacy, user } }) + ev.emit('connection.update', { legacy: { ...state.legacy, user } }) } }) // read updates @@ -397,7 +397,7 @@ const makeChatsSocket = (config: LegacySocketConfig) => { } ] ) - ev.emit('contacts.update', [{ id: getState().legacy!.user!.id, status }]) + ev.emit('contacts.update', [{ id: state.legacy!.user!.id, status }]) return response }, /** Updates business profile. */ @@ -420,9 +420,9 @@ const makeChatsSocket = (config: LegacySocketConfig) => { )) as any as {status: number, pushname: string} if(config.emitOwnEvents) { - const user = { ...getState().legacy!.user!, name } + const user = { ...state.legacy!.user!, name } ev.emit('connection.update', { legacy: { - ...getState().legacy, user + ...state.legacy, user } }) ev.emit('contacts.update', [{ id: user.id, name }]) } @@ -446,7 +446,7 @@ const makeChatsSocket = (config: LegacySocketConfig) => { ] } - const user = getState().legacy?.user + const user = state.legacy?.user const { eurl } = await this.setQuery ([query], [WAMetric.picture, 136], tag) as { eurl: string, status: number } if(config.emitOwnEvents) { @@ -454,7 +454,7 @@ const makeChatsSocket = (config: LegacySocketConfig) => { user.imgUrl = eurl ev.emit('connection.update', { legacy: { - ...getState().legacy, + ...state.legacy, user } }) diff --git a/src/LegacySocket/groups.ts b/src/LegacySocket/groups.ts index 053de2d..88aa673 100644 --- a/src/LegacySocket/groups.ts +++ b/src/LegacySocket/groups.ts @@ -13,7 +13,7 @@ const makeGroupsSocket = (config: LegacySocketConfig) => { generateMessageTag, currentEpoch, setQuery, - getState + state } = sock /** Generic function for group queries */ @@ -23,7 +23,7 @@ const makeGroupsSocket = (config: LegacySocketConfig) => { { tag: 'group', attrs: { - author: getState().legacy?.user?.id, + author: state.legacy?.user?.id, id: tag, type: type, jid: jid, @@ -217,7 +217,7 @@ const makeGroupsSocket = (config: LegacySocketConfig) => { subject: result.name, id: jid, creation: undefined, - owner: getState().legacy?.user?.id, + owner: state.legacy?.user?.id, participants: result.recipients!.map(({ id }) => ( { id: jidNormalizedUser(id), isAdmin: false, isSuperAdmin: false } )) diff --git a/src/LegacySocket/messages.ts b/src/LegacySocket/messages.ts index 399e93d..852bdd2 100644 --- a/src/LegacySocket/messages.ts +++ b/src/LegacySocket/messages.ts @@ -22,7 +22,7 @@ const makeMessagesSocket = (config: LegacySocketConfig) => { generateMessageTag, currentEpoch, setQuery, - getState + state } = sock let mediaConn: Promise @@ -161,7 +161,7 @@ const makeMessagesSocket = (config: LegacySocketConfig) => { // check if the message is an action if (message.messageStubType) { - const { user } = getState().legacy! + const { user } = state.legacy! //let actor = jidNormalizedUser (message.participant) let participants: string[] const emitParticipantsUpdate = (action: ParticipantAction) => ( @@ -257,7 +257,7 @@ const makeMessagesSocket = (config: LegacySocketConfig) => { } ] } - const isMsgToMe = areJidsSameUser(message.key.remoteJid, getState().legacy.user?.id || '') + const isMsgToMe = areJidsSameUser(message.key.remoteJid, state.legacy.user?.id || '') const flag = isMsgToMe ? WAFlag.acknowledge : WAFlag.ignore // acknowledge when sending message to oneself const mID = message.key.id const finalState = isMsgToMe ? WAMessageStatus.READ : WAMessageStatus.SERVER_ACK @@ -353,7 +353,7 @@ const makeMessagesSocket = (config: LegacySocketConfig) => { } const keyPartial = { remoteJid: jidNormalizedUser(attributes.to), - fromMe: areJidsSameUser(attributes.from, getState().legacy?.user?.id || ''), + fromMe: areJidsSameUser(attributes.from, state.legacy?.user?.id || ''), } const updates = ids.map(id => ({ key: { ...keyPartial, id }, @@ -491,7 +491,7 @@ const makeMessagesSocket = (config: LegacySocketConfig) => { content: AnyMessageContent, options: MiscMessageGenerationOptions & { waitForAck?: boolean } = { waitForAck: true } ) => { - const userJid = getState().legacy.user?.id + const userJid = state.legacy.user?.id if( typeof content === 'object' && 'disappearingMessagesInChat' in content &&