Merge 233604fcfd into 4583f88626
This commit is contained in:
commit
139f8fbb6b
@ -14,7 +14,9 @@ function unwrapMessage(message: proto.IMessage | undefined): proto.IMessage | un
|
|||||||
return normalized as proto.IMessage | undefined;
|
return normalized as proto.IMessage | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractContextInfo(message: proto.IMessage | undefined): proto.IContextInfo | undefined {
|
export function extractContextInfo(
|
||||||
|
message: proto.IMessage | undefined,
|
||||||
|
): proto.IContextInfo | undefined {
|
||||||
if (!message) return undefined;
|
if (!message) return undefined;
|
||||||
const contentType = getContentType(message);
|
const contentType = getContentType(message);
|
||||||
const candidate = contentType ? (message as Record<string, unknown>)[contentType] : undefined;
|
const candidate = contentType ? (message as Record<string, unknown>)[contentType] : undefined;
|
||||||
@ -46,6 +48,22 @@ function extractContextInfo(message: proto.IMessage | undefined): proto.IContext
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ForwardingInfo {
|
||||||
|
isForwarded: boolean;
|
||||||
|
forwardingScore?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function extractForwardingInfo(rawMessage: proto.IMessage | undefined): ForwardingInfo {
|
||||||
|
const message = unwrapMessage(rawMessage);
|
||||||
|
if (!message) return { isForwarded: false };
|
||||||
|
const contextInfo = extractContextInfo(message);
|
||||||
|
if (!contextInfo) return { isForwarded: false };
|
||||||
|
return {
|
||||||
|
isForwarded: contextInfo.isForwarded ?? false,
|
||||||
|
forwardingScore: contextInfo.forwardingScore ?? undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function extractMentionedJids(rawMessage: proto.IMessage | undefined): string[] | undefined {
|
export function extractMentionedJids(rawMessage: proto.IMessage | undefined): string[] | undefined {
|
||||||
const message = unwrapMessage(rawMessage);
|
const message = unwrapMessage(rawMessage);
|
||||||
if (!message) return undefined;
|
if (!message) return undefined;
|
||||||
|
|||||||
@ -13,6 +13,7 @@ import { checkInboundAccessControl } from "./access-control.js";
|
|||||||
import { isRecentInboundMessage } from "./dedupe.js";
|
import { isRecentInboundMessage } from "./dedupe.js";
|
||||||
import {
|
import {
|
||||||
describeReplyContext,
|
describeReplyContext,
|
||||||
|
extractForwardingInfo,
|
||||||
extractLocationData,
|
extractLocationData,
|
||||||
extractMediaPlaceholder,
|
extractMediaPlaceholder,
|
||||||
extractMentionedJids,
|
extractMentionedJids,
|
||||||
@ -222,6 +223,16 @@ export async function monitorWebInbox(options: {
|
|||||||
if (!body) continue;
|
if (!body) continue;
|
||||||
}
|
}
|
||||||
const replyContext = describeReplyContext(msg.message as proto.IMessage | undefined);
|
const replyContext = describeReplyContext(msg.message as proto.IMessage | undefined);
|
||||||
|
const forwardingInfo = extractForwardingInfo(msg.message as proto.IMessage | undefined);
|
||||||
|
|
||||||
|
// Add forwarding tag to body if message is forwarded
|
||||||
|
if (forwardingInfo.isForwarded) {
|
||||||
|
const forwardTag =
|
||||||
|
forwardingInfo.forwardingScore && forwardingInfo.forwardingScore >= 5
|
||||||
|
? "[forwarded many times]"
|
||||||
|
: "[forwarded]";
|
||||||
|
body = `${forwardTag} ${body}`;
|
||||||
|
}
|
||||||
|
|
||||||
let mediaPath: string | undefined;
|
let mediaPath: string | undefined;
|
||||||
let mediaType: string | undefined;
|
let mediaType: string | undefined;
|
||||||
@ -290,6 +301,8 @@ export async function monitorWebInbox(options: {
|
|||||||
groupSubject,
|
groupSubject,
|
||||||
groupParticipants,
|
groupParticipants,
|
||||||
mentionedJids: mentionedJids ?? undefined,
|
mentionedJids: mentionedJids ?? undefined,
|
||||||
|
isForwarded: forwardingInfo.isForwarded,
|
||||||
|
forwardingScore: forwardingInfo.forwardingScore,
|
||||||
selfJid,
|
selfJid,
|
||||||
selfE164,
|
selfE164,
|
||||||
location: location ?? undefined,
|
location: location ?? undefined,
|
||||||
|
|||||||
@ -29,6 +29,8 @@ export type WebInboundMessage = {
|
|||||||
groupSubject?: string;
|
groupSubject?: string;
|
||||||
groupParticipants?: string[];
|
groupParticipants?: string[];
|
||||||
mentionedJids?: string[];
|
mentionedJids?: string[];
|
||||||
|
isForwarded?: boolean;
|
||||||
|
forwardingScore?: number;
|
||||||
selfJid?: string | null;
|
selfJid?: string | null;
|
||||||
selfE164?: string | null;
|
selfE164?: string | null;
|
||||||
location?: NormalizedLocation;
|
location?: NormalizedLocation;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user