From 189b740ea60d0c13002b53c3acd4955429906ee9 Mon Sep 17 00:00:00 2001 From: Adhiraj Singh Date: Mon, 4 Jul 2022 11:38:17 +0530 Subject: [PATCH] chore: remove "treatCiphertextMessagesAsReal" flag !BREAKING_CHANGE This was generally a poor design decision on my part to add something like this -- primarily because it could increment the chat unread counter a 100 times for a single message --- README.md | 2 -- src/Defaults/index.ts | 1 - src/LegacySocket/messages.ts | 7 ++----- src/Socket/chats.ts | 3 +-- src/Types/Socket.ts | 2 -- src/Utils/event-buffer.ts | 2 +- src/Utils/process-message.ts | 8 +++----- tsconfig.json | 1 + 8 files changed, 8 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index da9e502..73b6f88 100644 --- a/README.md +++ b/README.md @@ -124,8 +124,6 @@ type SocketConfig = { fetchAgent?: Agent /** should the QR be printed in the terminal */ printQRInTerminal: boolean - /** fires a conversationTimestamp & read count update on CIPHERTEXT messages */ - treatCiphertextMessagesAsReal: boolean /** * fetch a message from your store * implement this so that messages failed to send (solves the "this message can take a while" issue) can be retried diff --git a/src/Defaults/index.ts b/src/Defaults/index.ts index 289e261..306b664 100644 --- a/src/Defaults/index.ts +++ b/src/Defaults/index.ts @@ -37,7 +37,6 @@ const BASE_CONNECTION_CONFIG: CommonSocketConfig = { emitOwnEvents: true, defaultQueryTimeoutMs: 60_000, customUploadHosts: [], - treatCiphertextMessagesAsReal: false, retryRequestDelayMs: 250 } diff --git a/src/LegacySocket/messages.ts b/src/LegacySocket/messages.ts index d62ca95..dee6076 100644 --- a/src/LegacySocket/messages.ts +++ b/src/LegacySocket/messages.ts @@ -12,7 +12,7 @@ const STATUS_MAP = { } as { [_: string]: WAMessageStatus } const makeMessagesSocket = (config: LegacySocketConfig) => { - const { logger, treatCiphertextMessagesAsReal } = config + const { logger } = config const sock = makeChatsSocket(config) const { ev, @@ -117,10 +117,7 @@ const makeMessagesSocket = (config: LegacySocketConfig) => { const protocolMessage = normalizedContent?.protocolMessage if( - ( - !!normalizedContent || - (message.messageStubType === WAMessageStubType.CIPHERTEXT && treatCiphertextMessagesAsReal) - ) + !!normalizedContent && !normalizedContent?.protocolMessage && !normalizedContent?.reactionMessage ) { diff --git a/src/Socket/chats.ts b/src/Socket/chats.ts index d6bea71..f97eeb8 100644 --- a/src/Socket/chats.ts +++ b/src/Socket/chats.ts @@ -12,7 +12,7 @@ const MAX_SYNC_ATTEMPTS = 5 const APP_STATE_SYNC_TIMEOUT_MS = 10_000 export const makeChatsSocket = (config: SocketConfig) => { - const { logger, markOnlineOnConnect, treatCiphertextMessagesAsReal, downloadHistory } = config + const { logger, markOnlineOnConnect, downloadHistory } = config const sock = makeSocket(config) const { ev, @@ -721,7 +721,6 @@ export const makeChatsSocket = (config: SocketConfig) => { creds: authState.creds, keyStore: authState.keys, logger, - treatCiphertextMessagesAsReal } ) diff --git a/src/Types/Socket.ts b/src/Types/Socket.ts index 9c43caf..59aa841 100644 --- a/src/Types/Socket.ts +++ b/src/Types/Socket.ts @@ -37,8 +37,6 @@ export type CommonSocketConfig = { mediaCache?: NodeCache /** custom upload hosts to upload media to */ customUploadHosts: MediaConnInfo['hosts'] - /** fires a conversationTimestamp & read count update on CIPHERTEXT messages */ - treatCiphertextMessagesAsReal: boolean /** time to wait between sending new retry requests */ retryRequestDelayMs: number } diff --git a/src/Utils/event-buffer.ts b/src/Utils/event-buffer.ts index 7852a94..96c7565 100644 --- a/src/Utils/event-buffer.ts +++ b/src/Utils/event-buffer.ts @@ -313,7 +313,7 @@ function append( const chatId = message.key.remoteJid const chat = data.chatUpdates[chatId] || data.chatUpserts[chatId] if( - isRealMessage(message, false) + isRealMessage(message) && shouldIncrementChatUnread(message) && typeof chat.unreadCount !== 'undefined' && chat.unreadCount > 0 diff --git a/src/Utils/process-message.ts b/src/Utils/process-message.ts index 9df4066..b5f2e02 100644 --- a/src/Utils/process-message.ts +++ b/src/Utils/process-message.ts @@ -12,7 +12,6 @@ type ProcessMessageContext = { keyStore: SignalKeyStoreWithTransaction ev: BaileysEventEmitter logger?: Logger - treatCiphertextMessagesAsReal?: boolean } const MSG_MISSED_CALL_TYPES = new Set([ @@ -39,12 +38,11 @@ export const cleanMessage = (message: proto.IWebMessageInfo, meId: string) => { } } -export const isRealMessage = (message: proto.IWebMessageInfo, treatCiphertextMessagesAsReal: boolean) => { +export const isRealMessage = (message: proto.IWebMessageInfo) => { const normalizedContent = normalizeMessageContent(message.message) return ( !!normalizedContent || MSG_MISSED_CALL_TYPES.has(message.messageStubType) - || (message.messageStubType === WAMessageStubType.CIPHERTEXT && treatCiphertextMessagesAsReal) ) && !normalizedContent?.protocolMessage && !normalizedContent?.reactionMessage @@ -56,14 +54,14 @@ export const shouldIncrementChatUnread = (message: proto.IWebMessageInfo) => ( const processMessage = async( message: proto.IWebMessageInfo, - { downloadHistory, ev, historyCache, recvChats, creds, keyStore, logger, treatCiphertextMessagesAsReal }: ProcessMessageContext + { downloadHistory, ev, historyCache, recvChats, creds, keyStore, logger }: ProcessMessageContext ) => { const meId = creds.me!.id const { accountSettings } = creds const chat: Partial = { id: jidNormalizedUser(message.key.remoteJid) } - if(isRealMessage(message, treatCiphertextMessagesAsReal)) { + if(isRealMessage(message)) { chat.conversationTimestamp = toNumber(message.messageTimestamp) // only increment unread count if not CIPHERTEXT and from another person if(shouldIncrementChatUnread(message)) { diff --git a/tsconfig.json b/tsconfig.json index 3b6bfec..756c69e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,6 +7,7 @@ "checkJs": false, "outDir": "lib", "strict": false, + "skipLibCheck": true, "noImplicitThis": true, "esModuleInterop": true, "resolveJsonModule": true,