mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
add emitOwnEvents
This commit is contained in:
@@ -28,6 +28,7 @@ export const DEFAULT_CONNECTION_CONFIG: SocketConfig = {
|
|||||||
keepAliveIntervalMs: 25_000,
|
keepAliveIntervalMs: 25_000,
|
||||||
logger: P().child({ class: 'baileys' }),
|
logger: P().child({ class: 'baileys' }),
|
||||||
printQRInTerminal: false,
|
printQRInTerminal: false,
|
||||||
|
emitOwnEvents: true
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MEDIA_PATH_MAP: { [T in MediaType]: string } = {
|
export const MEDIA_PATH_MAP: { [T in MediaType]: string } = {
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const processSyncActions = (actions: ChatMutation[]) => {
|
const processSyncActions = (actions: ChatMutation[]) => {
|
||||||
|
|
||||||
const updates: { [jid: string]: Partial<Chat> } = {}
|
const updates: { [jid: string]: Partial<Chat> } = {}
|
||||||
const contactUpdates: { [jid: string]: Partial<Contact> } = {}
|
const contactUpdates: { [jid: string]: Partial<Contact> } = {}
|
||||||
const msgDeletes: proto.IMessageKey[] = []
|
const msgDeletes: proto.IMessageKey[] = []
|
||||||
@@ -360,7 +360,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
|||||||
)
|
)
|
||||||
const initial = await authState.keys.getAppStateSyncVersion(name)
|
const initial = await authState.keys.getAppStateSyncVersion(name)
|
||||||
// temp: verify it was encoded correctly
|
// temp: verify it was encoded correctly
|
||||||
await decodePatches({ syncds: [{ ...patch, version: { version: state.version }, }], name }, initial, authState)
|
const result = await decodePatches({ syncds: [{ ...patch, version: { version: state.version }, }], name }, initial, authState)
|
||||||
|
|
||||||
const node: BinaryNode = {
|
const node: BinaryNode = {
|
||||||
tag: 'iq',
|
tag: 'iq',
|
||||||
@@ -397,6 +397,9 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
|||||||
|
|
||||||
await authState.keys.setAppStateSyncVersion(name, state)
|
await authState.keys.setAppStateSyncVersion(name, state)
|
||||||
ev.emit('auth-state.update', authState)
|
ev.emit('auth-state.update', authState)
|
||||||
|
if(config.emitOwnEvents) {
|
||||||
|
processSyncActions(result.newMutations)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const chatModify = (mod: ChatModification, jid: string, lastMessages: Pick<proto.IWebMessageInfo, 'key' | 'messageTimestamp'>[]) => {
|
const chatModify = (mod: ChatModification, jid: string, lastMessages: Pick<proto.IWebMessageInfo, 'key' | 'messageTimestamp'>[]) => {
|
||||||
|
|||||||
@@ -394,9 +394,11 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id! })
|
await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id! })
|
||||||
process.nextTick(() => {
|
if(config.emitOwnEvents) {
|
||||||
ev.emit('messages.upsert', { messages: [fullMsg], type: 'append' })
|
process.nextTick(() => {
|
||||||
})
|
ev.emit('messages.upsert', { messages: [fullMsg], type: 'append' })
|
||||||
|
})
|
||||||
|
}
|
||||||
return fullMsg
|
return fullMsg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ export type SocketConfig = {
|
|||||||
fetchAgent?: Agent
|
fetchAgent?: Agent
|
||||||
/** should the QR be printed in the terminal */
|
/** should the QR be printed in the terminal */
|
||||||
printQRInTerminal: boolean
|
printQRInTerminal: boolean
|
||||||
|
/** should events be emitted for actions done by this socket connection */
|
||||||
|
emitOwnEvents: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum DisconnectReason {
|
export enum DisconnectReason {
|
||||||
|
|||||||
Reference in New Issue
Block a user