diff --git a/src/Socket/messages-recv.ts b/src/Socket/messages-recv.ts index 90ba536..115a44e 100644 --- a/src/Socket/messages-recv.ts +++ b/src/Socket/messages-recv.ts @@ -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 diff --git a/src/Types/Auth.ts b/src/Types/Auth.ts index 5c28533..7e1c9c7 100644 --- a/src/Types/Auth.ts +++ b/src/Types/Auth.ts @@ -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 = { diff --git a/src/Utils/auth-utils.ts b/src/Utils/auth-utils.ts index 2cd6722..664c1f4 100644 --- a/src/Utils/auth-utils.ts +++ b/src/Utils/auth-utils.ts @@ -108,7 +108,10 @@ export const initAuthCreds = (): AuthenticationCreds => { nextPreKeyId: 1, firstUnuploadedPreKeyId: 1, - serverHasPreKeys: false + serverHasPreKeys: false, + accountSettings: { + unarchiveChats: false + } } } diff --git a/src/Utils/chat-utils.ts b/src/Utils/chat-utils.ts index 9e8c2fd..f6c650a 100644 --- a/src/Utils/chat-utils.ts +++ b/src/Utils/chat-utils.ts @@ -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') } diff --git a/src/Utils/process-message.ts b/src/Utils/process-message.ts index cfc1ec7..ff90644 100644 --- a/src/Utils/process-message.ts +++ b/src/Utils/process-message.ts @@ -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, - meId: string, - keyStore: SignalKeyStoreWithTransaction, + historyCache: Set + 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> = { } @@ -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)