Skip to content

Commit 05a3b2a

Browse files
authored
fix(discord): honor explicit names for new forum posts (#129294)
1 parent 4dc7bb7 commit 05a3b2a

2 files changed

Lines changed: 51 additions & 2 deletions

File tree

‎extensions/discord/src/actions/runtime.messaging.send.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ export async function handleDiscordMessageSendAction(ctx: DiscordMessagingAction
258258
return jsonResult(
259259
await appendDiscordThreadRenameResult(ctx, {
260260
payload: { ok: true, result, components: true },
261-
target: to,
261+
target: result.receipt?.threadId ?? to,
262262
threadName,
263263
}),
264264
);
@@ -309,7 +309,7 @@ export async function handleDiscordMessageSendAction(ctx: DiscordMessagingAction
309309
return jsonResult(
310310
await appendDiscordThreadRenameResult(ctx, {
311311
payload: { ok: true, result },
312-
target: to,
312+
target: result.receipt?.threadId ?? to,
313313
threadName,
314314
}),
315315
);

‎extensions/discord/src/actions/runtime.test.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2364,6 +2364,55 @@ describe("handleDiscordMessagingAction", () => {
23642364
});
23652365
});
23662366

2367+
it.each([
2368+
{ label: "forum message", parentType: ChannelType.GuildForum, components: false },
2369+
{ label: "media message", parentType: ChannelType.GuildMedia, components: false },
2370+
{ label: "forum component media", parentType: ChannelType.GuildForum, components: true },
2371+
{ label: "media component media", parentType: ChannelType.GuildMedia, components: true },
2372+
])("renames the newly created $label thread", async ({ parentType, components }) => {
2373+
const sender = components ? sendDiscordComponentMessage : sendMessageDiscord;
2374+
sender.mockResolvedValueOnce({
2375+
messageId: "M1",
2376+
channelId: "T1",
2377+
receipt: { threadId: "T1" },
2378+
});
2379+
fetchChannelInfoDiscord.mockImplementation(async (channelId) => ({
2380+
id: channelId,
2381+
type: channelId === "P1" ? parentType : ChannelType.PublicThread,
2382+
}));
2383+
editChannelDiscord.mockResolvedValueOnce({
2384+
id: "T1",
2385+
name: "chosen-thread",
2386+
});
2387+
2388+
const result = await handleMessagingAction(
2389+
"sendMessage",
2390+
{
2391+
to: "channel:P1",
2392+
content: "A generated thread title",
2393+
threadName: "chosen-thread",
2394+
...(components
2395+
? {
2396+
components: { blocks: [{ type: "text", text: "A generated thread title" }] },
2397+
mediaUrl: "/tmp/image.png",
2398+
}
2399+
: {}),
2400+
},
2401+
enableAllActions,
2402+
);
2403+
2404+
expect(fetchChannelInfoDiscord).toHaveBeenCalledWith("T1", { cfg: DISCORD_TEST_CFG });
2405+
expect(editChannelDiscord).toHaveBeenCalledWith(
2406+
{ channelId: "T1", name: "chosen-thread" },
2407+
{ cfg: DISCORD_TEST_CFG },
2408+
);
2409+
expect(result.details).toMatchObject({
2410+
ok: true,
2411+
result: { channelId: "T1", receipt: { threadId: "T1" } },
2412+
threadRename: { ok: true, channelId: "T1", name: "chosen-thread" },
2413+
});
2414+
});
2415+
23672416
it("forwards sendMessage suppressEmbeds overrides", async () => {
23682417
sendMessageDiscord.mockClear();
23692418

0 commit comments

Comments
 (0)