fix(web): handle self-chat mode

This commit is contained in:
Peter Steinberger
2025-12-20 19:31:51 +01:00
parent c38aeb1081
commit 929a10e33d
5 changed files with 178 additions and 20 deletions

View File

@@ -13,7 +13,7 @@ import { loadConfig } from "../config/config.js";
import { isVerbose, logVerbose } from "../globals.js";
import { getChildLogger } from "../logging.js";
import { saveMediaBuffer } from "../media/store.js";
import { jidToE164, normalizeE164 } from "../utils.js";
import { isSelfChatMode, jidToE164, normalizeE164 } from "../utils.js";
import {
createWaSocket,
getStatusCode,
@@ -116,22 +116,6 @@ export async function monitorWebInbox(options: {
// Ignore status/broadcast traffic; we only care about direct chats.
if (remoteJid.endsWith("@status") || remoteJid.endsWith("@broadcast"))
continue;
if (id) {
const participant = msg.key?.participant;
try {
await sock.readMessages([
{ remoteJid, id, participant, fromMe: false },
]);
if (isVerbose()) {
const suffix = participant ? ` (participant ${participant})` : "";
logVerbose(
`Marked message ${id} as read for ${remoteJid}${suffix}`,
);
}
} catch (err) {
logVerbose(`Failed to mark message ${id} read: ${String(err)}`);
}
}
const group = isJidGroup(remoteJid);
const participantJid = msg.key?.participant ?? undefined;
const senderE164 = participantJid ? jidToE164(participantJid) : null;
@@ -160,6 +144,7 @@ export async function monitorWebInbox(options: {
? configuredAllowFrom
: defaultAllowFrom;
const isSamePhone = from === selfE164;
const isSelfChat = isSelfChatMode(selfE164, configuredAllowFrom);
const allowlistEnabled =
!group && Array.isArray(allowFrom) && allowFrom.length > 0;
@@ -174,6 +159,26 @@ export async function monitorWebInbox(options: {
}
}
if (id && !isSelfChat) {
const participant = msg.key?.participant;
try {
await sock.readMessages([
{ remoteJid, id, participant, fromMe: false },
]);
if (isVerbose()) {
const suffix = participant ? ` (participant ${participant})` : "";
logVerbose(
`Marked message ${id} as read for ${remoteJid}${suffix}`,
);
}
} catch (err) {
logVerbose(`Failed to mark message ${id} read: ${String(err)}`);
}
} else if (id && isSelfChat && isVerbose()) {
// Self-chat mode: never auto-send read receipts (blue ticks) on behalf of the owner.
logVerbose(`Self-chat mode: skipping read receipt for ${id}`);
}
let body = extractText(msg.message ?? undefined);
if (!body) {
body = extractMediaPlaceholder(msg.message ?? undefined);