mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
refactor: use constant state & authInfo on legacy
This commit is contained in:
@@ -258,9 +258,9 @@ const makeAuthSocket = (config: LegacySocketConfig) => {
|
||||
|
||||
return {
|
||||
...socket,
|
||||
state,
|
||||
authInfo,
|
||||
ev,
|
||||
getState: () => state,
|
||||
getAuthInfo: () => authInfo,
|
||||
waitForConnection,
|
||||
canLogin,
|
||||
logout
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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 }
|
||||
))
|
||||
|
||||
@@ -22,7 +22,7 @@ const makeMessagesSocket = (config: LegacySocketConfig) => {
|
||||
generateMessageTag,
|
||||
currentEpoch,
|
||||
setQuery,
|
||||
getState
|
||||
state
|
||||
} = sock
|
||||
|
||||
let mediaConn: Promise<MediaConnInfo>
|
||||
@@ -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<MessageInfoUpdate>(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 &&
|
||||
|
||||
Reference in New Issue
Block a user