From 683a589dbc8169f590594b856607460dd78e99dc Mon Sep 17 00:00:00 2001 From: caneleex Date: Sat, 29 Jan 2022 19:21:02 +0100 Subject: [PATCH] Override ThreadChannel#getTimeCreated (#1996) --- .../dv8tion/jda/api/entities/ThreadChannel.java | 9 +++++++++ .../jda/internal/entities/EntityBuilder.java | 1 + .../jda/internal/entities/ThreadChannelImpl.java | 15 +++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/src/main/java/net/dv8tion/jda/api/entities/ThreadChannel.java b/src/main/java/net/dv8tion/jda/api/entities/ThreadChannel.java index 84bfc3bf3a..78070ca395 100644 --- a/src/main/java/net/dv8tion/jda/api/entities/ThreadChannel.java +++ b/src/main/java/net/dv8tion/jda/api/entities/ThreadChannel.java @@ -473,6 +473,15 @@ default ThreadMember getOwnerThreadMember() @Nonnull AutoArchiveDuration getAutoArchiveDuration(); + /** + * The timestamp when this thread was created. + *
This will only be valid for threads created after 2022-01-09. + * Otherwise, this will return the timestamp of creation based on the {@link #getIdLong() thread's id.} + * + * @return The timestamp when this thread was created + */ + @Nonnull + OffsetDateTime getTimeCreated(); /** * The slowmode time of this thread. This determines the time each non-moderator must wait before sending another message. diff --git a/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java b/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java index 98b3d850ae..75abf4c321 100644 --- a/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java +++ b/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java @@ -1187,6 +1187,7 @@ public ThreadChannel createThreadChannel(GuildImpl guild, DataObject json, long .setArchived(threadMetadata.getBoolean("archived")) .setInvitable(threadMetadata.getBoolean("invitable")) .setArchiveTimestamp(Helpers.toTimestamp(threadMetadata.getString("archive_timestamp"))) + .setCreationTimestamp(threadMetadata.isNull("create_timestamp") ? 0 : Helpers.toTimestamp(threadMetadata.getString("create_timestamp"))) .setAutoArchiveDuration(ThreadChannel.AutoArchiveDuration.fromKey(threadMetadata.getInt("auto_archive_duration"))); //If the bot in the thread already, then create a thread member for the bot. diff --git a/src/main/java/net/dv8tion/jda/internal/entities/ThreadChannelImpl.java b/src/main/java/net/dv8tion/jda/internal/entities/ThreadChannelImpl.java index da8c1c6ada..5c189340ce 100644 --- a/src/main/java/net/dv8tion/jda/internal/entities/ThreadChannelImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/entities/ThreadChannelImpl.java @@ -20,6 +20,7 @@ import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.managers.channel.concrete.ThreadChannelManager; import net.dv8tion.jda.api.requests.RestAction; +import net.dv8tion.jda.api.utils.TimeUtil; import net.dv8tion.jda.api.utils.cache.CacheView; import net.dv8tion.jda.api.utils.data.DataArray; import net.dv8tion.jda.api.utils.data.DataObject; @@ -52,6 +53,7 @@ public class ThreadChannelImpl extends AbstractGuildChannelImpl