mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
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
This commit is contained in:
@@ -124,8 +124,6 @@ type SocketConfig = {
|
|||||||
fetchAgent?: Agent
|
fetchAgent?: Agent
|
||||||
/** should the QR be printed in the terminal */
|
/** should the QR be printed in the terminal */
|
||||||
printQRInTerminal: boolean
|
printQRInTerminal: boolean
|
||||||
/** fires a conversationTimestamp & read count update on CIPHERTEXT messages */
|
|
||||||
treatCiphertextMessagesAsReal: boolean
|
|
||||||
/**
|
/**
|
||||||
* fetch a message from your store
|
* 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
|
* implement this so that messages failed to send (solves the "this message can take a while" issue) can be retried
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ const BASE_CONNECTION_CONFIG: CommonSocketConfig<any> = {
|
|||||||
emitOwnEvents: true,
|
emitOwnEvents: true,
|
||||||
defaultQueryTimeoutMs: 60_000,
|
defaultQueryTimeoutMs: 60_000,
|
||||||
customUploadHosts: [],
|
customUploadHosts: [],
|
||||||
treatCiphertextMessagesAsReal: false,
|
|
||||||
retryRequestDelayMs: 250
|
retryRequestDelayMs: 250
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ const STATUS_MAP = {
|
|||||||
} as { [_: string]: WAMessageStatus }
|
} as { [_: string]: WAMessageStatus }
|
||||||
|
|
||||||
const makeMessagesSocket = (config: LegacySocketConfig) => {
|
const makeMessagesSocket = (config: LegacySocketConfig) => {
|
||||||
const { logger, treatCiphertextMessagesAsReal } = config
|
const { logger } = config
|
||||||
const sock = makeChatsSocket(config)
|
const sock = makeChatsSocket(config)
|
||||||
const {
|
const {
|
||||||
ev,
|
ev,
|
||||||
@@ -117,10 +117,7 @@ const makeMessagesSocket = (config: LegacySocketConfig) => {
|
|||||||
const protocolMessage = normalizedContent?.protocolMessage
|
const protocolMessage = normalizedContent?.protocolMessage
|
||||||
|
|
||||||
if(
|
if(
|
||||||
(
|
!!normalizedContent
|
||||||
!!normalizedContent ||
|
|
||||||
(message.messageStubType === WAMessageStubType.CIPHERTEXT && treatCiphertextMessagesAsReal)
|
|
||||||
)
|
|
||||||
&& !normalizedContent?.protocolMessage
|
&& !normalizedContent?.protocolMessage
|
||||||
&& !normalizedContent?.reactionMessage
|
&& !normalizedContent?.reactionMessage
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ const MAX_SYNC_ATTEMPTS = 5
|
|||||||
const APP_STATE_SYNC_TIMEOUT_MS = 10_000
|
const APP_STATE_SYNC_TIMEOUT_MS = 10_000
|
||||||
|
|
||||||
export const makeChatsSocket = (config: SocketConfig) => {
|
export const makeChatsSocket = (config: SocketConfig) => {
|
||||||
const { logger, markOnlineOnConnect, treatCiphertextMessagesAsReal, downloadHistory } = config
|
const { logger, markOnlineOnConnect, downloadHistory } = config
|
||||||
const sock = makeSocket(config)
|
const sock = makeSocket(config)
|
||||||
const {
|
const {
|
||||||
ev,
|
ev,
|
||||||
@@ -721,7 +721,6 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
|||||||
creds: authState.creds,
|
creds: authState.creds,
|
||||||
keyStore: authState.keys,
|
keyStore: authState.keys,
|
||||||
logger,
|
logger,
|
||||||
treatCiphertextMessagesAsReal
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -37,8 +37,6 @@ export type CommonSocketConfig<T> = {
|
|||||||
mediaCache?: NodeCache
|
mediaCache?: NodeCache
|
||||||
/** custom upload hosts to upload media to */
|
/** custom upload hosts to upload media to */
|
||||||
customUploadHosts: MediaConnInfo['hosts']
|
customUploadHosts: MediaConnInfo['hosts']
|
||||||
/** fires a conversationTimestamp & read count update on CIPHERTEXT messages */
|
|
||||||
treatCiphertextMessagesAsReal: boolean
|
|
||||||
/** time to wait between sending new retry requests */
|
/** time to wait between sending new retry requests */
|
||||||
retryRequestDelayMs: number
|
retryRequestDelayMs: number
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -313,7 +313,7 @@ function append<E extends BufferableEvent>(
|
|||||||
const chatId = message.key.remoteJid
|
const chatId = message.key.remoteJid
|
||||||
const chat = data.chatUpdates[chatId] || data.chatUpserts[chatId]
|
const chat = data.chatUpdates[chatId] || data.chatUpserts[chatId]
|
||||||
if(
|
if(
|
||||||
isRealMessage(message, false)
|
isRealMessage(message)
|
||||||
&& shouldIncrementChatUnread(message)
|
&& shouldIncrementChatUnread(message)
|
||||||
&& typeof chat.unreadCount !== 'undefined'
|
&& typeof chat.unreadCount !== 'undefined'
|
||||||
&& chat.unreadCount > 0
|
&& chat.unreadCount > 0
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ type ProcessMessageContext = {
|
|||||||
keyStore: SignalKeyStoreWithTransaction
|
keyStore: SignalKeyStoreWithTransaction
|
||||||
ev: BaileysEventEmitter
|
ev: BaileysEventEmitter
|
||||||
logger?: Logger
|
logger?: Logger
|
||||||
treatCiphertextMessagesAsReal?: boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const MSG_MISSED_CALL_TYPES = new Set([
|
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)
|
const normalizedContent = normalizeMessageContent(message.message)
|
||||||
return (
|
return (
|
||||||
!!normalizedContent
|
!!normalizedContent
|
||||||
|| MSG_MISSED_CALL_TYPES.has(message.messageStubType)
|
|| MSG_MISSED_CALL_TYPES.has(message.messageStubType)
|
||||||
|| (message.messageStubType === WAMessageStubType.CIPHERTEXT && treatCiphertextMessagesAsReal)
|
|
||||||
)
|
)
|
||||||
&& !normalizedContent?.protocolMessage
|
&& !normalizedContent?.protocolMessage
|
||||||
&& !normalizedContent?.reactionMessage
|
&& !normalizedContent?.reactionMessage
|
||||||
@@ -56,14 +54,14 @@ export const shouldIncrementChatUnread = (message: proto.IWebMessageInfo) => (
|
|||||||
|
|
||||||
const processMessage = async(
|
const processMessage = async(
|
||||||
message: proto.IWebMessageInfo,
|
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 meId = creds.me!.id
|
||||||
const { accountSettings } = creds
|
const { accountSettings } = creds
|
||||||
|
|
||||||
const chat: Partial<Chat> = { id: jidNormalizedUser(message.key.remoteJid) }
|
const chat: Partial<Chat> = { id: jidNormalizedUser(message.key.remoteJid) }
|
||||||
|
|
||||||
if(isRealMessage(message, treatCiphertextMessagesAsReal)) {
|
if(isRealMessage(message)) {
|
||||||
chat.conversationTimestamp = toNumber(message.messageTimestamp)
|
chat.conversationTimestamp = toNumber(message.messageTimestamp)
|
||||||
// only increment unread count if not CIPHERTEXT and from another person
|
// only increment unread count if not CIPHERTEXT and from another person
|
||||||
if(shouldIncrementChatUnread(message)) {
|
if(shouldIncrementChatUnread(message)) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
"checkJs": false,
|
"checkJs": false,
|
||||||
"outDir": "lib",
|
"outDir": "lib",
|
||||||
"strict": false,
|
"strict": false,
|
||||||
|
"skipLibCheck": true,
|
||||||
"noImplicitThis": true,
|
"noImplicitThis": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
|
|||||||
Reference in New Issue
Block a user