mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
feat: handle unarchiveChats setting
This commit is contained in:
@@ -145,7 +145,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
// process message and emit events
|
||||
const newEvents = await processMessage(
|
||||
msg,
|
||||
{ historyCache, meId, keyStore: authState.keys, logger, treatCiphertextMessagesAsReal }
|
||||
{ historyCache, meId, accountSettings: authState.creds.accountSettings, keyStore: authState.keys, logger, treatCiphertextMessagesAsReal }
|
||||
)
|
||||
|
||||
// send ack for history message
|
||||
|
||||
@@ -27,6 +27,11 @@ export type SignalCreds = {
|
||||
readonly registrationId: number
|
||||
}
|
||||
|
||||
export type AccountSettings = {
|
||||
/** unarchive chats when a new message is received */
|
||||
unarchiveChats: boolean
|
||||
}
|
||||
|
||||
export type AuthenticationCreds = SignalCreds & {
|
||||
readonly noiseKey: KeyPair
|
||||
readonly advSecretKey: string
|
||||
@@ -40,6 +45,7 @@ export type AuthenticationCreds = SignalCreds & {
|
||||
nextPreKeyId: number
|
||||
|
||||
lastAccountSyncTimestamp?: number
|
||||
accountSettings: AccountSettings
|
||||
}
|
||||
|
||||
export type SignalDataTypeMap = {
|
||||
|
||||
@@ -108,7 +108,10 @@ export const initAuthCreds = (): AuthenticationCreds => {
|
||||
|
||||
nextPreKeyId: 1,
|
||||
firstUnuploadedPreKeyId: 1,
|
||||
serverHasPreKeys: false
|
||||
serverHasPreKeys: false,
|
||||
accountSettings: {
|
||||
unarchiveChats: false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -583,11 +583,13 @@ export const processSyncActions = (
|
||||
name: action.contactAction!.fullName
|
||||
}
|
||||
} else if(action?.pushNameSetting) {
|
||||
map['creds.update'] = {
|
||||
me: { ...me, name: action?.pushNameSetting?.name! }
|
||||
}
|
||||
map['creds.update'] = map['creds.update'] || { }
|
||||
map['creds.update'].me = { ...me, name: action?.pushNameSetting?.name! }
|
||||
} else if(action?.pinAction) {
|
||||
update.pin = action.pinAction?.pinned ? toNumber(action.timestamp) : undefined
|
||||
} else if(action?.unarchiveChatsSetting) {
|
||||
map['creds.update'] = map['creds.update'] || { }
|
||||
map['creds.update'].accountSettings = { unarchiveChats: !!action.unarchiveChatsSetting.unarchiveChats }
|
||||
} else {
|
||||
logger.warn({ action, id }, 'unprocessable update')
|
||||
}
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
import type { Logger } from 'pino'
|
||||
import { proto } from '../../WAProto'
|
||||
import { BaileysEventMap, Chat, GroupMetadata, ParticipantAction, SignalKeyStoreWithTransaction, WAMessageStubType } from '../Types'
|
||||
import { AccountSettings, BaileysEventMap, Chat, GroupMetadata, ParticipantAction, SignalKeyStoreWithTransaction, WAMessageStubType } from '../Types'
|
||||
import { downloadAndProcessHistorySyncNotification, normalizeMessageContent, toNumber } from '../Utils'
|
||||
import { areJidsSameUser, jidNormalizedUser } from '../WABinary'
|
||||
|
||||
type ProcessMessageContext = {
|
||||
historyCache: Set<string>,
|
||||
meId: string,
|
||||
keyStore: SignalKeyStoreWithTransaction,
|
||||
historyCache: Set<string>
|
||||
meId: string
|
||||
keyStore: SignalKeyStoreWithTransaction
|
||||
accountSettings: AccountSettings
|
||||
logger?: Logger
|
||||
treatCiphertextMessagesAsReal?: boolean
|
||||
}
|
||||
|
||||
const processMessage = async(
|
||||
message: proto.IWebMessageInfo,
|
||||
{ historyCache, meId, keyStore, logger, treatCiphertextMessagesAsReal }: ProcessMessageContext
|
||||
{ historyCache, meId, keyStore, accountSettings, logger, treatCiphertextMessagesAsReal }: ProcessMessageContext
|
||||
) => {
|
||||
const map: Partial<BaileysEventMap<any>> = { }
|
||||
|
||||
@@ -30,9 +31,14 @@ const processMessage = async(
|
||||
&& !normalizedContent?.reactionMessage
|
||||
) {
|
||||
chat.conversationTimestamp = toNumber(message.messageTimestamp)
|
||||
if(!message.key.fromMe) {
|
||||
// only increment unread count if not CIPHERTEXT and from another person
|
||||
if(!message.key.fromMe && !!message.messageStubType) {
|
||||
chat.unreadCount = (chat.unreadCount || 0) + 1
|
||||
}
|
||||
|
||||
if(accountSettings?.unarchiveChats) {
|
||||
chat.archive = false
|
||||
}
|
||||
}
|
||||
|
||||
const content = normalizeMessageContent(message.message)
|
||||
|
||||
Reference in New Issue
Block a user