mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
feat: add toggle to download history
This commit is contained in:
@@ -43,6 +43,7 @@ const BASE_CONNECTION_CONFIG: CommonSocketConfig<any> = {
|
|||||||
|
|
||||||
export const DEFAULT_CONNECTION_CONFIG: SocketConfig = {
|
export const DEFAULT_CONNECTION_CONFIG: SocketConfig = {
|
||||||
...BASE_CONNECTION_CONFIG,
|
...BASE_CONNECTION_CONFIG,
|
||||||
|
downloadHistory: true,
|
||||||
linkPreviewImageThumbnailWidth: 192,
|
linkPreviewImageThumbnailWidth: 192,
|
||||||
getMessage: async() => undefined
|
getMessage: async() => undefined
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
const {
|
const {
|
||||||
logger,
|
logger,
|
||||||
treatCiphertextMessagesAsReal,
|
treatCiphertextMessagesAsReal,
|
||||||
retryRequestDelayMs
|
retryRequestDelayMs,
|
||||||
|
downloadHistory
|
||||||
} = config
|
} = config
|
||||||
const sock = makeChatsSocket(config)
|
const sock = makeChatsSocket(config)
|
||||||
const {
|
const {
|
||||||
@@ -149,7 +150,15 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
// process message and emit events
|
// process message and emit events
|
||||||
const newEvents = await processMessage(
|
const newEvents = await processMessage(
|
||||||
msg,
|
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
|
// send ack for history message
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ import { CommonSocketConfig } from './Socket'
|
|||||||
export type MessageRetryMap = { [msgId: string]: number }
|
export type MessageRetryMap = { [msgId: string]: number }
|
||||||
|
|
||||||
export type SocketConfig = CommonSocketConfig<AuthenticationState> & {
|
export type SocketConfig = CommonSocketConfig<AuthenticationState> & {
|
||||||
|
/** By default true, should history messages be downloaded and processed */
|
||||||
|
downloadHistory: boolean
|
||||||
/** provide a cache to store a user's device list */
|
/** provide a cache to store a user's device list */
|
||||||
userDevicesCache?: NodeCache
|
userDevicesCache?: NodeCache
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { areJidsSameUser, jidNormalizedUser } from '../WABinary'
|
|||||||
|
|
||||||
type ProcessMessageContext = {
|
type ProcessMessageContext = {
|
||||||
historyCache: Set<string>
|
historyCache: Set<string>
|
||||||
|
downloadHistory: boolean
|
||||||
meId: string
|
meId: string
|
||||||
keyStore: SignalKeyStoreWithTransaction
|
keyStore: SignalKeyStoreWithTransaction
|
||||||
accountSettings: AccountSettings
|
accountSettings: AccountSettings
|
||||||
@@ -22,7 +23,7 @@ const MSG_MISSED_CALL_TYPES = new Set([
|
|||||||
|
|
||||||
const processMessage = async(
|
const processMessage = async(
|
||||||
message: proto.IWebMessageInfo,
|
message: proto.IWebMessageInfo,
|
||||||
{ historyCache, meId, keyStore, accountSettings, logger, treatCiphertextMessagesAsReal }: ProcessMessageContext
|
{ downloadHistory, historyCache, meId, keyStore, accountSettings, logger, treatCiphertextMessagesAsReal }: ProcessMessageContext
|
||||||
) => {
|
) => {
|
||||||
const map: Partial<BaileysEventMap<any>> = { }
|
const map: Partial<BaileysEventMap<any>> = { }
|
||||||
|
|
||||||
@@ -59,18 +60,20 @@ const processMessage = async(
|
|||||||
|
|
||||||
logger?.info({ histNotification, id: message.key.id }, 'got history notification')
|
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) {
|
if(chats.length) {
|
||||||
map['chats.set'] = { chats, isLatest }
|
map['chats.set'] = { chats, isLatest }
|
||||||
}
|
}
|
||||||
|
|
||||||
if(messages.length) {
|
if(messages.length) {
|
||||||
map['messages.set'] = { messages, isLatest }
|
map['messages.set'] = { messages, isLatest }
|
||||||
}
|
}
|
||||||
|
|
||||||
if(contacts.length) {
|
if(contacts.length) {
|
||||||
map['contacts.set'] = { contacts }
|
map['contacts.set'] = { contacts }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in New Issue
Block a user