From be888f195ddda144a0cba7879c943793b78fa276 Mon Sep 17 00:00:00 2001 From: devlikepro Date: Mon, 18 Nov 2024 17:09:13 +0700 Subject: [PATCH] [core] NOWEB - fix timestamp --- src/core/engines/noweb/session.noweb.core.ts | 10 +++++----- src/core/engines/noweb/utils.ts | 8 ++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/core/engines/noweb/session.noweb.core.ts b/src/core/engines/noweb/session.noweb.core.ts index c3f8ef37..7b5d4b81 100644 --- a/src/core/engines/noweb/session.noweb.core.ts +++ b/src/core/engines/noweb/session.noweb.core.ts @@ -158,7 +158,7 @@ import { NowebAuthFactoryCore } from './NowebAuthFactoryCore'; import { INowebStore } from './store/INowebStore'; import { NowebPersistentStore } from './store/NowebPersistentStore'; import { NowebStorageFactoryCore } from './store/NowebStorageFactoryCore'; -import { extractMediaContent } from './utils'; +import { ensureNumber, extractMediaContent } from './utils'; // eslint-disable-next-line @typescript-eslint/no-var-requires const QRCode = require('qrcode'); @@ -1507,7 +1507,7 @@ export class WhatsappSessionNoWebCore extends WhatsappSession { const messageId = buildMessageId(reactionMessage.key); const reaction: WAMessageReaction = { id: id, - timestamp: message.messageTimestamp, + timestamp: ensureNumber(message.messageTimestamp), from: toCusFormat(fromToParticipant.from), fromMe: message.key.fromMe, to: toCusFormat(fromToParticipant.to), @@ -1556,7 +1556,7 @@ export class WhatsappSessionNoWebCore extends WhatsappSession { const ack = message.ack || message.status - 1; return Promise.resolve({ id: id, - timestamp: message.messageTimestamp, + timestamp: ensureNumber(message.messageTimestamp), from: toCusFormat(fromToParticipant.from), fromMe: message.key.fromMe, body: body, @@ -1700,7 +1700,7 @@ export class WhatsappSessionNoWebCore extends WhatsappSession { const pollVote: PollVote = { ...voteDestination, selectedOptions: selectedOptions, - timestamp: pollUpdate.senderTimestampMs, + timestamp: ensureNumber(pollUpdate.senderTimestampMs), }; const payload: PollVotePayload = { vote: pollVote, @@ -1732,7 +1732,7 @@ export class WhatsappSessionNoWebCore extends WhatsappSession { // https://github.com/WhiskeySockets/Baileys/pull/348 // Or without toNumber() - it depends on the PR above // timestamp: pollUpdateMessage.senderTimestampMs.toNumber() - timestamp: message.messageTimestamp, + timestamp: ensureNumber(message.messageTimestamp), }; const payload: PollVotePayload = { vote: pollVote, diff --git a/src/core/engines/noweb/utils.ts b/src/core/engines/noweb/utils.ts index c7b9ab92..bb88343f 100644 --- a/src/core/engines/noweb/utils.ts +++ b/src/core/engines/noweb/utils.ts @@ -78,6 +78,14 @@ const isObjectALong = (value: any): value is Long => { ); }; +export function ensureNumber(value: number | Long): number { + if (!value) { + // @ts-ignore + return value; + } + return typeof value === 'number' ? value : toNumber(value); +} + const toNumber = (longValue: Long): number => { const { low, high, unsigned } = longValue; const result = unsigned ? low >>> 0 : low + high * 0x100000000;