fix(discord): respect replyToMode in threads
The issue was that Discord threads always included a message_reference (reply indicator) regardless of replyToMode setting. The fix is Discord-specific: don't pass existingId to the reply planner when replyToMode is 'off'. This prevents reply references in threads while preserving the existing Slack behavior where existingId (thread_ts) is needed to keep messages in the correct thread. - Updated resolveDiscordReplyDeliveryPlan to check replyToMode before setting existingId - Updated tests to reflect new behavior
This commit is contained in:
parent
cd1480d637
commit
20e0a535fb
@ -11,7 +11,7 @@ export type ReplyReferencePlanner = {
|
||||
|
||||
export function createReplyReferencePlanner(options: {
|
||||
replyToMode: ReplyToMode;
|
||||
/** Existing thread/reference id (used when present, unless replyToMode is "off"). */
|
||||
/** Existing thread/reference id (always used when present). */
|
||||
existingId?: string;
|
||||
/** Id to start a new thread/reference when allowed (e.g., parent message id). */
|
||||
startId?: string;
|
||||
@ -27,12 +27,12 @@ export function createReplyReferencePlanner(options: {
|
||||
|
||||
const use = (): string | undefined => {
|
||||
if (!allowReference) return undefined;
|
||||
if (options.replyToMode === "off") return undefined;
|
||||
if (existingId) {
|
||||
hasReplied = true;
|
||||
return existingId;
|
||||
}
|
||||
if (!startId) return undefined;
|
||||
if (options.replyToMode === "off") return undefined;
|
||||
if (options.replyToMode === "all") {
|
||||
hasReplied = true;
|
||||
return startId;
|
||||
|
||||
@ -74,7 +74,7 @@ describe("resolveDiscordReplyDeliveryPlan", () => {
|
||||
expect(plan.replyReference.use()).toBeUndefined();
|
||||
});
|
||||
|
||||
it("always uses existingId when inside a thread", () => {
|
||||
it("respects replyToMode off when inside a thread", () => {
|
||||
const plan = resolveDiscordReplyDeliveryPlan({
|
||||
replyTarget: "channel:thread",
|
||||
replyToMode: "off",
|
||||
@ -82,6 +82,17 @@ describe("resolveDiscordReplyDeliveryPlan", () => {
|
||||
threadChannel: { id: "thread" },
|
||||
createdThreadId: null,
|
||||
});
|
||||
expect(plan.replyReference.use()).toBeUndefined();
|
||||
});
|
||||
|
||||
it("uses message reference when inside a thread with replyToMode first", () => {
|
||||
const plan = resolveDiscordReplyDeliveryPlan({
|
||||
replyTarget: "channel:thread",
|
||||
replyToMode: "first",
|
||||
messageId: "m1",
|
||||
threadChannel: { id: "thread" },
|
||||
createdThreadId: null,
|
||||
});
|
||||
expect(plan.replyReference.use()).toBe("m1");
|
||||
});
|
||||
});
|
||||
|
||||
@ -304,9 +304,14 @@ export function resolveDiscordReplyDeliveryPlan(params: {
|
||||
replyTarget = deliverTarget;
|
||||
}
|
||||
const allowReference = deliverTarget === originalReplyTarget;
|
||||
const effectiveReplyToMode = allowReference ? params.replyToMode : "off";
|
||||
// Don't pass existingId when replyToMode is "off" - this prevents
|
||||
// unwanted reply references in threads when the user has disabled them
|
||||
const existingId =
|
||||
params.threadChannel && effectiveReplyToMode !== "off" ? params.messageId : undefined;
|
||||
const replyReference = createReplyReferencePlanner({
|
||||
replyToMode: allowReference ? params.replyToMode : "off",
|
||||
existingId: params.threadChannel ? params.messageId : undefined,
|
||||
replyToMode: effectiveReplyToMode,
|
||||
existingId,
|
||||
startId: params.messageId,
|
||||
allowReference,
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user