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: {
|
export function createReplyReferencePlanner(options: {
|
||||||
replyToMode: ReplyToMode;
|
replyToMode: ReplyToMode;
|
||||||
/** Existing thread/reference id (used when present, unless replyToMode is "off"). */
|
/** Existing thread/reference id (always used when present). */
|
||||||
existingId?: string;
|
existingId?: string;
|
||||||
/** Id to start a new thread/reference when allowed (e.g., parent message id). */
|
/** Id to start a new thread/reference when allowed (e.g., parent message id). */
|
||||||
startId?: string;
|
startId?: string;
|
||||||
@ -27,12 +27,12 @@ export function createReplyReferencePlanner(options: {
|
|||||||
|
|
||||||
const use = (): string | undefined => {
|
const use = (): string | undefined => {
|
||||||
if (!allowReference) return undefined;
|
if (!allowReference) return undefined;
|
||||||
if (options.replyToMode === "off") return undefined;
|
|
||||||
if (existingId) {
|
if (existingId) {
|
||||||
hasReplied = true;
|
hasReplied = true;
|
||||||
return existingId;
|
return existingId;
|
||||||
}
|
}
|
||||||
if (!startId) return undefined;
|
if (!startId) return undefined;
|
||||||
|
if (options.replyToMode === "off") return undefined;
|
||||||
if (options.replyToMode === "all") {
|
if (options.replyToMode === "all") {
|
||||||
hasReplied = true;
|
hasReplied = true;
|
||||||
return startId;
|
return startId;
|
||||||
|
|||||||
@ -74,7 +74,7 @@ describe("resolveDiscordReplyDeliveryPlan", () => {
|
|||||||
expect(plan.replyReference.use()).toBeUndefined();
|
expect(plan.replyReference.use()).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("always uses existingId when inside a thread", () => {
|
it("respects replyToMode off when inside a thread", () => {
|
||||||
const plan = resolveDiscordReplyDeliveryPlan({
|
const plan = resolveDiscordReplyDeliveryPlan({
|
||||||
replyTarget: "channel:thread",
|
replyTarget: "channel:thread",
|
||||||
replyToMode: "off",
|
replyToMode: "off",
|
||||||
@ -82,6 +82,17 @@ describe("resolveDiscordReplyDeliveryPlan", () => {
|
|||||||
threadChannel: { id: "thread" },
|
threadChannel: { id: "thread" },
|
||||||
createdThreadId: null,
|
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");
|
expect(plan.replyReference.use()).toBe("m1");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -304,9 +304,14 @@ export function resolveDiscordReplyDeliveryPlan(params: {
|
|||||||
replyTarget = deliverTarget;
|
replyTarget = deliverTarget;
|
||||||
}
|
}
|
||||||
const allowReference = deliverTarget === originalReplyTarget;
|
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({
|
const replyReference = createReplyReferencePlanner({
|
||||||
replyToMode: allowReference ? params.replyToMode : "off",
|
replyToMode: effectiveReplyToMode,
|
||||||
existingId: params.threadChannel ? params.messageId : undefined,
|
existingId,
|
||||||
startId: params.messageId,
|
startId: params.messageId,
|
||||||
allowReference,
|
allowReference,
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user