From 65d1241dd9ad0551a75dd4e09c3befe8ce8d2a32 Mon Sep 17 00:00:00 2001 From: Vankka Date: Mon, 23 Oct 2023 23:43:35 +0300 Subject: [PATCH] Map deletes as well --- .../AbstractDiscordGuildMessageChannel.java | 7 ++++++- .../entity/channel/DiscordThreadChannelImpl.java | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/com/discordsrv/common/discord/api/entity/channel/AbstractDiscordGuildMessageChannel.java b/common/src/main/java/com/discordsrv/common/discord/api/entity/channel/AbstractDiscordGuildMessageChannel.java index eecf701e..87ff8b0f 100644 --- a/common/src/main/java/com/discordsrv/common/discord/api/entity/channel/AbstractDiscordGuildMessageChannel.java +++ b/common/src/main/java/com/discordsrv/common/discord/api/entity/channel/AbstractDiscordGuildMessageChannel.java @@ -31,6 +31,7 @@ import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel; import net.dv8tion.jda.api.requests.RestAction; import net.dv8tion.jda.api.requests.restaction.MessageCreateAction; import net.dv8tion.jda.api.requests.restaction.WebhookMessageCreateAction; +import net.dv8tion.jda.api.requests.restaction.WebhookMessageDeleteAction; import net.dv8tion.jda.api.requests.restaction.WebhookMessageEditAction; import net.dv8tion.jda.api.utils.messages.MessageCreateData; import net.dv8tion.jda.api.utils.messages.MessageCreateRequest; @@ -143,11 +144,15 @@ public abstract class AbstractDiscordGuildMessageChannel ReceivedDiscordMessageImpl.fromJDA(discordSRV, msg)); } + protected WebhookMessageDeleteAction mapAction(WebhookMessageDeleteAction action) { + return action; + } + @Override public CompletableFuture deleteMessageById(long id, boolean webhookMessage) { CompletableFuture future; if (webhookMessage) { - future = queryWebhookClient().thenCompose(client -> client.deleteMessageById(id).submit()); + future = queryWebhookClient().thenCompose(client -> mapAction(client.deleteMessageById(id)).submit()); } else { future = channel.deleteMessageById(id).submit(); } diff --git a/common/src/main/java/com/discordsrv/common/discord/api/entity/channel/DiscordThreadChannelImpl.java b/common/src/main/java/com/discordsrv/common/discord/api/entity/channel/DiscordThreadChannelImpl.java index 703b9207..dcb2cadc 100644 --- a/common/src/main/java/com/discordsrv/common/discord/api/entity/channel/DiscordThreadChannelImpl.java +++ b/common/src/main/java/com/discordsrv/common/discord/api/entity/channel/DiscordThreadChannelImpl.java @@ -23,12 +23,15 @@ import com.discordsrv.api.discord.entity.channel.DiscordThreadChannel; import com.discordsrv.api.discord.entity.channel.DiscordThreadContainer; import com.discordsrv.api.discord.entity.guild.DiscordGuild; import com.discordsrv.common.DiscordSRV; +import net.dv8tion.jda.api.JDA; +import net.dv8tion.jda.api.JDABuilder; import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.WebhookClient; import net.dv8tion.jda.api.entities.channel.ChannelType; import net.dv8tion.jda.api.entities.channel.attribute.IThreadContainer; import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; import net.dv8tion.jda.api.requests.restaction.WebhookMessageCreateAction; +import net.dv8tion.jda.api.requests.restaction.WebhookMessageDeleteAction; import net.dv8tion.jda.api.requests.restaction.WebhookMessageEditAction; import org.jetbrains.annotations.NotNull; @@ -63,6 +66,11 @@ public class DiscordThreadChannelImpl extends AbstractDiscordGuildMessageChannel return super.mapAction(action).setThreadId(getId()); } + @Override + protected WebhookMessageDeleteAction mapAction(WebhookMessageDeleteAction action) { + return super.mapAction(action).setThreadId(getId()); + } + @Override public @NotNull DiscordGuild getGuild() { return guild; @@ -83,6 +91,12 @@ public class DiscordThreadChannelImpl extends AbstractDiscordGuildMessageChannel return channel; } + public static void main(String[] args) { + JDA jda = JDABuilder.createDefault("token").build(); + + WebhookClient.createClient(jda, "url").sendMessage("hello").setThreadId(1234567890L).queue(); + } + @Override public DiscordChannelType getType() { ChannelType type = channel.getType();