mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Fix linting generateMessageIDV2 (#871)
* Update messages-send.ts * Update generics.ts
This commit is contained in:
@@ -4,7 +4,7 @@ import NodeCache from 'node-cache'
|
|||||||
import { proto } from '../../WAProto'
|
import { proto } from '../../WAProto'
|
||||||
import { DEFAULT_CACHE_TTLS, WA_DEFAULT_EPHEMERAL } from '../Defaults'
|
import { DEFAULT_CACHE_TTLS, WA_DEFAULT_EPHEMERAL } from '../Defaults'
|
||||||
import { AnyMessageContent, MediaConnInfo, MessageReceiptType, MessageRelayOptions, MiscMessageGenerationOptions, SocketConfig, WAMessageKey } from '../Types'
|
import { AnyMessageContent, MediaConnInfo, MessageReceiptType, MessageRelayOptions, MiscMessageGenerationOptions, SocketConfig, WAMessageKey } from '../Types'
|
||||||
import { aggregateMessageKeysNotFromMe, assertMediaContent, bindWaitForEvent, decryptMediaRetryData, encodeSignedDeviceIdentity, encodeWAMessage, encryptMediaRetryRequest, extractDeviceJids, generateMessageID, generateMessageIDV2, generateWAMessage, getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, parseAndInjectE2ESessions, unixTimestampSeconds } from '../Utils'
|
import { aggregateMessageKeysNotFromMe, assertMediaContent, bindWaitForEvent, decryptMediaRetryData, encodeSignedDeviceIdentity, encodeWAMessage, encryptMediaRetryRequest, extractDeviceJids, generateMessageIDV2, generateWAMessage, getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, parseAndInjectE2ESessions, unixTimestampSeconds } from '../Utils'
|
||||||
import { getUrlInfo } from '../Utils/link-preview'
|
import { getUrlInfo } from '../Utils/link-preview'
|
||||||
import { areJidsSameUser, BinaryNode, BinaryNodeAttributes, getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, isJidUser, jidDecode, jidEncode, jidNormalizedUser, JidWithDevice, S_WHATSAPP_NET } from '../WABinary'
|
import { areJidsSameUser, BinaryNode, BinaryNodeAttributes, getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, isJidUser, jidDecode, jidEncode, jidNormalizedUser, JidWithDevice, S_WHATSAPP_NET } from '../WABinary'
|
||||||
import { makeGroupsSocket } from './groups'
|
import { makeGroupsSocket } from './groups'
|
||||||
|
|||||||
@@ -173,22 +173,22 @@ export async function promiseTimeout<T>(ms: number | undefined, promise: (resolv
|
|||||||
// inspired from whatsmeow code
|
// inspired from whatsmeow code
|
||||||
// https://github.com/tulir/whatsmeow/blob/64bc969fbe78d31ae0dd443b8d4c80a5d026d07a/send.go#L42
|
// https://github.com/tulir/whatsmeow/blob/64bc969fbe78d31ae0dd443b8d4c80a5d026d07a/send.go#L42
|
||||||
export const generateMessageIDV2 = (userId?: string): string => {
|
export const generateMessageIDV2 = (userId?: string): string => {
|
||||||
const data = Buffer.alloc(8 + 20 + 16)
|
const data = Buffer.alloc(8 + 20 + 16)
|
||||||
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)))
|
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)))
|
||||||
|
|
||||||
if (userId) {
|
if (userId) {
|
||||||
const id = jidDecode(userId)
|
const id = jidDecode(userId)
|
||||||
if (id?.user) {
|
if (id?.user) {
|
||||||
data.write(id.user, 8)
|
data.write(id.user, 8)
|
||||||
data.write('@c.us', 8 + id.user.length)
|
data.write('@c.us', 8 + id.user.length)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const random = randomBytes(16)
|
const random = randomBytes(16)
|
||||||
random.copy(data, 28)
|
random.copy(data, 28)
|
||||||
|
|
||||||
const hash = createHash('sha256').update(data).digest()
|
const hash = createHash('sha256').update(data).digest()
|
||||||
return '3EB0' + hash.toString('hex').toUpperCase().substring(0, 18)
|
return '3EB0' + hash.toString('hex').toUpperCase().substring(0, 18)
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate a random ID to attach to a message
|
// generate a random ID to attach to a message
|
||||||
|
|||||||
Reference in New Issue
Block a user