Skip to content

Commit

Permalink
Override ThreadChannel#getTimeCreated (#1996)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebm253 committed Jan 29, 2022
1 parent e5b80dc commit 683a589
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/java/net/dv8tion/jda/api/entities/ThreadChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,15 @@ default ThreadMember getOwnerThreadMember()
@Nonnull
AutoArchiveDuration getAutoArchiveDuration();

/**
* The timestamp when this thread was created.
* <br><b>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.}</b>
*
* @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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,6 +53,7 @@ public class ThreadChannelImpl extends AbstractGuildChannelImpl<ThreadChannelImp
private boolean invitable;
private long parentChannelId;
private long archiveTimestamp;
private long creationTimestamp;
private long ownerId;
private long latestMessageId;
private int messageCount;
Expand Down Expand Up @@ -209,6 +211,13 @@ public AutoArchiveDuration getAutoArchiveDuration()
return autoArchiveDuration;
}

@Nonnull
@Override
public OffsetDateTime getTimeCreated()
{
return creationTimestamp == 0 ? TimeUtil.getTimeCreated(getIdLong()) : Helpers.toOffset(creationTimestamp);
}

@Override
public int getSlowmode()
{
Expand Down Expand Up @@ -311,6 +320,12 @@ public ThreadChannelImpl setArchiveTimestamp(long archiveTimestamp)
return this;
}

public ThreadChannelImpl setCreationTimestamp(long creationTimestamp)
{
this.creationTimestamp = creationTimestamp;
return this;
}

public ThreadChannelImpl setOwnerId(long ownerId)
{
this.ownerId = ownerId;
Expand Down

0 comments on commit 683a589

Please sign in to comment.