mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
PDO protocol (peer data operation): Get more history sync + better message retry mechanism (#919)
* feat(feature/pdo-sync): initial commit * feat(feature/pdo-sync): Moved to conventional send functions, exported, patched some errors * fix(feature/pdo-sync): Linting and more bugsquatting * chore(feature/pdo-sync): linting done * feat/fix(feat/pdo-sync): Newsletter decrypt + ack * merge (#946) * fix: profilePictureUrl (#901) * Update module to latest version (#926) * Update package.json Update the module to the latest * Add files via upload * Fix: Readme use upsert events (#908) * Fix: getUSyncDevices (#862) * Update messages-send.ts * Update messages-send.ts * Update messages-send.ts * Fix lint * Fix lint * fix(master): update linting workflow to node 20 (current LTS) --------- Co-authored-by: Akhlaqul Muhammad Fadwa <75623219+zennn08@users.noreply.github.com> Co-authored-by: Rizz2Dev <muhamad.rizki27483@smp.belajar.id> Co-authored-by: Oscar Guindzberg <oscar.guindzberg@gmail.com> Co-authored-by: Bob <115008575+bobslavtriev@users.noreply.github.com> * chore(feature/pdo-sync): final linting * fix(feature/pdo-sync): make replies optional * feat(feat/pdo-sync): add <unavailable> handle * feat(feature/pdo-sync): Fixed the issues with peer messages and implemented some more logic * fix(feature/pdo-sync): Make progress optional * fix(feature/pdo-sync): Nullify and defeat Message absent from node if it is resolved immediately * feat(feature/pdo-sync): Export message absent from node and export PDO request ID with it --------- Co-authored-by: Akhlaqul Muhammad Fadwa <75623219+zennn08@users.noreply.github.com> Co-authored-by: Rizz2Dev <muhamad.rizki27483@smp.belajar.id> Co-authored-by: Oscar Guindzberg <oscar.guindzberg@gmail.com> Co-authored-by: Bob <115008575+bobslavtriev@users.noreply.github.com>
This commit is contained in:
@@ -264,6 +264,34 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
return didFetchNewSession
|
||||
}
|
||||
|
||||
const sendPeerDataOperationMessage = async(
|
||||
pdoMessage: proto.Message.IPeerDataOperationRequestMessage
|
||||
): Promise<string> => {
|
||||
//TODO: for later, abstract the logic to send a Peer Message instead of just PDO - useful for App State Key Resync with phone
|
||||
if(!authState.creds.me?.id) {
|
||||
throw new Boom('Not authenticated')
|
||||
}
|
||||
|
||||
const protocolMessage: proto.IMessage = {
|
||||
protocolMessage: {
|
||||
peerDataOperationRequestMessage: pdoMessage,
|
||||
type: proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
|
||||
}
|
||||
}
|
||||
|
||||
const meJid = jidNormalizedUser(authState.creds.me.id)!
|
||||
|
||||
const msgId = await relayMessage(meJid, protocolMessage, {
|
||||
additionalAttributes: {
|
||||
category: 'peer',
|
||||
// eslint-disable-next-line camelcase
|
||||
push_priority: 'high_force',
|
||||
},
|
||||
})
|
||||
|
||||
return msgId
|
||||
}
|
||||
|
||||
const createParticipantNodes = async(
|
||||
jids: string[],
|
||||
message: proto.IMessage,
|
||||
@@ -436,12 +464,15 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
if(!participant) {
|
||||
devices.push({ user })
|
||||
// do not send message to self if the device is 0 (mobile)
|
||||
if(meDevice !== undefined && meDevice !== 0) {
|
||||
devices.push({ user: meUser })
|
||||
}
|
||||
|
||||
const additionalDevices = await getUSyncDevices([ meId, jid ], !!useUserDevicesCache, true)
|
||||
devices.push(...additionalDevices)
|
||||
if(!(additionalAttributes?.['category'] === 'peer' && user === meUser)) {
|
||||
if(meDevice !== undefined && meDevice !== 0) {
|
||||
devices.push({ user: meUser })
|
||||
}
|
||||
|
||||
const additionalDevices = await getUSyncDevices([ meId, jid ], !!useUserDevicesCache, true)
|
||||
devices.push(...additionalDevices)
|
||||
}
|
||||
}
|
||||
|
||||
const allJids: string[] = []
|
||||
@@ -475,11 +506,18 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
}
|
||||
|
||||
if(participants.length) {
|
||||
binaryNodeContent.push({
|
||||
tag: 'participants',
|
||||
attrs: { },
|
||||
content: participants
|
||||
})
|
||||
if(additionalAttributes?.['category'] === 'peer') {
|
||||
const peerNode = participants[0]?.content?.[0] as BinaryNode
|
||||
if(peerNode) {
|
||||
binaryNodeContent.push(peerNode) // push only enc
|
||||
}
|
||||
} else {
|
||||
binaryNodeContent.push({
|
||||
tag: 'participants',
|
||||
attrs: { },
|
||||
content: participants
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const stanza: BinaryNode = {
|
||||
@@ -606,8 +644,9 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
sendReceipts,
|
||||
readMessages,
|
||||
refreshMediaConn,
|
||||
waUploadToServer,
|
||||
waUploadToServer,
|
||||
fetchPrivacySettings,
|
||||
sendPeerDataOperationMessage,
|
||||
updateMediaMessage: async(message: proto.IWebMessageInfo) => {
|
||||
const content = assertMediaContent(message.message)
|
||||
const mediaKey = content.mediaKey!
|
||||
|
||||
Reference in New Issue
Block a user