feat: implement "treatCiphertextMessagesAsReal" flag

This commit is contained in:
Adhiraj Singh
2022-03-21 14:15:22 +05:30
parent b5470e1b00
commit 93c8db319e
5 changed files with 22 additions and 5 deletions

View File

@@ -124,6 +124,8 @@ 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

View File

@@ -30,6 +30,7 @@ const BASE_CONNECTION_CONFIG: CommonSocketConfig<any> = {
emitOwnEvents: true, emitOwnEvents: true,
defaultQueryTimeoutMs: 60_000, defaultQueryTimeoutMs: 60_000,
customUploadHosts: [], customUploadHosts: [],
treatCiphertextMessagesAsReal: true
} }
export const DEFAULT_CONNECTION_CONFIG: SocketConfig = { export const DEFAULT_CONNECTION_CONFIG: SocketConfig = {

View File

@@ -13,7 +13,7 @@ const STATUS_MAP = {
} as { [_: string]: WAMessageStatus } } as { [_: string]: WAMessageStatus }
const makeMessagesSocket = (config: LegacySocketConfig) => { const makeMessagesSocket = (config: LegacySocketConfig) => {
const { logger } = config const { logger, treatCiphertextMessagesAsReal } = config
const sock = makeChatsSocket(config) const sock = makeChatsSocket(config)
const { const {
ev, ev,
@@ -120,7 +120,13 @@ const makeMessagesSocket = (config: LegacySocketConfig) => {
ev.emit('groups.update', [ { id: jid, ...update } ]) ev.emit('groups.update', [ { id: jid, ...update } ])
} }
if(message.message) { if(
(
!!message.message ||
(message.messageStubType === WAMessageStubType.CIPHERTEXT && treatCiphertextMessagesAsReal)
)
&& !message.message!.protocolMessage
) {
chatUpdate.conversationTimestamp = +toNumber(message.messageTimestamp) chatUpdate.conversationTimestamp = +toNumber(message.messageTimestamp)
// add to count if the message isn't from me & there exists a message // add to count if the message isn't from me & there exists a message
if(!message.key.fromMe) { if(!message.key.fromMe) {

View File

@@ -9,7 +9,7 @@ import { makeChatsSocket } from './chats'
import { extractGroupMetadata } from './groups' import { extractGroupMetadata } from './groups'
export const makeMessagesRecvSocket = (config: SocketConfig) => { export const makeMessagesRecvSocket = (config: SocketConfig) => {
const { logger } = config const { logger, treatCiphertextMessagesAsReal } = config
const sock = makeChatsSocket(config) const sock = makeChatsSocket(config)
const { const {
ev, ev,
@@ -548,7 +548,13 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
() => processMessage(msg, chat) () => processMessage(msg, chat)
) )
if(!!msg.message && !msg.message!.protocolMessage) { if(
(
!!msg.message ||
(msg.messageStubType === WAMessageStubType.CIPHERTEXT && treatCiphertextMessagesAsReal)
)
&& !msg.message!.protocolMessage
) {
chat.conversationTimestamp = toNumber(msg.messageTimestamp) chat.conversationTimestamp = toNumber(msg.messageTimestamp)
if(!msg.key.fromMe) { if(!msg.key.fromMe) {
chat.unreadCount = (chat.unreadCount || 0) + 1 chat.unreadCount = (chat.unreadCount || 0) + 1

View File

@@ -35,6 +35,8 @@ export type CommonSocketConfig<T> = {
emitOwnEvents: boolean emitOwnEvents: boolean
/** provide a cache to store media, so does not have to be re-uploaded */ /** provide a cache to store media, so does not have to be re-uploaded */
mediaCache?: NodeCache mediaCache?: NodeCache
/** custom upload hosts to upload media to */
customUploadHosts: MediaConnInfo['hosts'] customUploadHosts: MediaConnInfo['hosts']
/** fires a conversationTimestamp & read count update on CIPHERTEXT messages */
treatCiphertextMessagesAsReal: boolean
} }