Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override ThreadChannel#getTimeCreated #1996

Merged
merged 3 commits into from
Jan 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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