diff --git a/src/Defaults/index.ts b/src/Defaults/index.ts index e557e54..fda44dd 100644 --- a/src/Defaults/index.ts +++ b/src/Defaults/index.ts @@ -43,6 +43,7 @@ const BASE_CONNECTION_CONFIG: CommonSocketConfig = { export const DEFAULT_CONNECTION_CONFIG: SocketConfig = { ...BASE_CONNECTION_CONFIG, + downloadHistory: true, linkPreviewImageThumbnailWidth: 192, getMessage: async() => undefined } diff --git a/src/Socket/messages-recv.ts b/src/Socket/messages-recv.ts index 239aef1..170ad0a 100644 --- a/src/Socket/messages-recv.ts +++ b/src/Socket/messages-recv.ts @@ -13,7 +13,8 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { const { logger, treatCiphertextMessagesAsReal, - retryRequestDelayMs + retryRequestDelayMs, + downloadHistory } = config const sock = makeChatsSocket(config) const { @@ -149,7 +150,15 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { // process message and emit events const newEvents = await processMessage( msg, - { historyCache, meId, accountSettings: authState.creds.accountSettings, keyStore: authState.keys, logger, treatCiphertextMessagesAsReal } + { + downloadHistory, + historyCache, + meId, + accountSettings: authState.creds.accountSettings, + keyStore: authState.keys, + logger, + treatCiphertextMessagesAsReal + } ) // send ack for history message diff --git a/src/Types/index.ts b/src/Types/index.ts index 8786e7c..8788d0e 100644 --- a/src/Types/index.ts +++ b/src/Types/index.ts @@ -18,6 +18,8 @@ import { CommonSocketConfig } from './Socket' export type MessageRetryMap = { [msgId: string]: number } export type SocketConfig = CommonSocketConfig & { + /** By default true, should history messages be downloaded and processed */ + downloadHistory: boolean /** provide a cache to store a user's device list */ userDevicesCache?: NodeCache /** diff --git a/src/Utils/process-message.ts b/src/Utils/process-message.ts index 228ee44..958897a 100644 --- a/src/Utils/process-message.ts +++ b/src/Utils/process-message.ts @@ -6,6 +6,7 @@ import { areJidsSameUser, jidNormalizedUser } from '../WABinary' type ProcessMessageContext = { historyCache: Set + downloadHistory: boolean meId: string keyStore: SignalKeyStoreWithTransaction accountSettings: AccountSettings @@ -22,7 +23,7 @@ const MSG_MISSED_CALL_TYPES = new Set([ const processMessage = async( message: proto.IWebMessageInfo, - { historyCache, meId, keyStore, accountSettings, logger, treatCiphertextMessagesAsReal }: ProcessMessageContext + { downloadHistory, historyCache, meId, keyStore, accountSettings, logger, treatCiphertextMessagesAsReal }: ProcessMessageContext ) => { const map: Partial> = { } @@ -59,18 +60,20 @@ const processMessage = async( logger?.info({ histNotification, id: message.key.id }, 'got history notification') - const { chats, contacts, messages, isLatest } = await downloadAndProcessHistorySyncNotification(histNotification, historyCache) + if(downloadHistory) { + const { chats, contacts, messages, isLatest } = await downloadAndProcessHistorySyncNotification(histNotification, historyCache) - if(chats.length) { - map['chats.set'] = { chats, isLatest } - } + if(chats.length) { + map['chats.set'] = { chats, isLatest } + } - if(messages.length) { - map['messages.set'] = { messages, isLatest } - } + if(messages.length) { + map['messages.set'] = { messages, isLatest } + } - if(contacts.length) { - map['contacts.set'] = { contacts } + if(contacts.length) { + map['contacts.set'] = { contacts } + } } break