fix: dedupe inbound messages across providers
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { HISTORY_CONTEXT_MARKER } from "../auto-reply/reply/history.js";
|
||||
import { resetInboundDedupe } from "../auto-reply/reply/inbound-dedupe.js";
|
||||
import { CURRENT_MESSAGE_MARKER } from "../auto-reply/reply/mentions.js";
|
||||
import { monitorSlackProvider } from "./monitor.js";
|
||||
|
||||
@@ -100,6 +101,7 @@ async function waitForEvent(name: string) {
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
resetInboundDedupe();
|
||||
config = {
|
||||
messages: {
|
||||
responsePrefix: "PFX",
|
||||
|
||||
@@ -50,6 +50,7 @@ import {
|
||||
updateLastRoute,
|
||||
} from "../config/sessions.js";
|
||||
import { danger, logVerbose, shouldLogVerbose } from "../globals.js";
|
||||
import { createDedupeCache } from "../infra/dedupe.js";
|
||||
import { enqueueSystemEvent } from "../infra/system-events.js";
|
||||
import { getChildLogger } from "../logging.js";
|
||||
import { type FetchLike, fetchRemoteMedia } from "../media/fetch.js";
|
||||
@@ -516,24 +517,11 @@ export async function monitorSlackProvider(opts: MonitorSlackOpts = {}) {
|
||||
}
|
||||
>();
|
||||
const userCache = new Map<string, { name?: string }>();
|
||||
const seenMessages = new Map<string, number>();
|
||||
const seenMessages = createDedupeCache({ ttlMs: 60_000, maxSize: 500 });
|
||||
|
||||
const markMessageSeen = (channelId: string | undefined, ts?: string) => {
|
||||
if (!channelId || !ts) return false;
|
||||
const key = `${channelId}:${ts}`;
|
||||
if (seenMessages.has(key)) return true;
|
||||
seenMessages.set(key, Date.now());
|
||||
if (seenMessages.size > 500) {
|
||||
const cutoff = Date.now() - 60_000;
|
||||
for (const [entry, seenAt] of seenMessages) {
|
||||
if (seenAt < cutoff || seenMessages.size > 450) {
|
||||
seenMessages.delete(entry);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return seenMessages.check(`${channelId}:${ts}`);
|
||||
};
|
||||
|
||||
const app = new App({
|
||||
|
||||
Reference in New Issue
Block a user