From fe8afa31cc18fcd060c5ce5b3a555322332573ef Mon Sep 17 00:00:00 2001 From: freya02 <41875020+freya022@users.noreply.github.com> Date: Fri, 19 Apr 2024 23:33:39 +0200 Subject: [PATCH 1/3] Fix thread pagination when skipping ahead --- .../ThreadChannelPaginationActionImpl.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/net/dv8tion/jda/internal/requests/restaction/pagination/ThreadChannelPaginationActionImpl.java b/src/main/java/net/dv8tion/jda/internal/requests/restaction/pagination/ThreadChannelPaginationActionImpl.java index 8a66407a37..37db064821 100644 --- a/src/main/java/net/dv8tion/jda/internal/requests/restaction/pagination/ThreadChannelPaginationActionImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/requests/restaction/pagination/ThreadChannelPaginationActionImpl.java @@ -10,6 +10,7 @@ import net.dv8tion.jda.api.requests.Response; import net.dv8tion.jda.api.requests.Route; import net.dv8tion.jda.api.requests.restaction.pagination.ThreadChannelPaginationAction; +import net.dv8tion.jda.api.utils.TimeUtil; import net.dv8tion.jda.api.utils.data.DataArray; import net.dv8tion.jda.api.utils.data.DataObject; import net.dv8tion.jda.internal.entities.EntityBuilder; @@ -59,19 +60,16 @@ protected String getPaginationLastEvaluatedKey(long lastId, ThreadChannel last) if (useID) return Long.toUnsignedString(lastId); - if (order == PaginationOrder.FORWARD && lastId == 0) - { - // first second of 2015 aka discords epoch, hard coding something older makes no sense to me - return "2015-01-01T00:00:00.000"; - } - - // this should be redundant, due to calling this with PaginationAction#getLast() as last param, - // but let's have this here. - if (last == null) + if (last != null) + // If threads were retrieved + // OffsetDateTime#toString() is defined to be ISO8601, needs no helper method. + return last.getTimeArchiveInfoLastModified().toString(); + else if (lastId != 0) + // If the user skipped ahead + return TimeUtil.getTimeCreated(lastId).toString(); + else + // If we just started paginating return OffsetDateTime.now(ZoneOffset.UTC).toString(); - - // OffsetDateTime#toString() is defined to be ISO8601, needs no helper method. - return last.getTimeArchiveInfoLastModified().toString(); } @Override From ef58600080797c1938b31205102d2315c2bf8d26 Mon Sep 17 00:00:00 2001 From: freya02 <41875020+freya022@users.noreply.github.com> Date: Fri, 19 Apr 2024 23:38:18 +0200 Subject: [PATCH 2/3] Add note on ThreadChannelPaginationAction#skipTo about archive timestamps --- .../pagination/ThreadChannelPaginationAction.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/net/dv8tion/jda/api/requests/restaction/pagination/ThreadChannelPaginationAction.java b/src/main/java/net/dv8tion/jda/api/requests/restaction/pagination/ThreadChannelPaginationAction.java index fdfe9fbec0..d05a8ee087 100644 --- a/src/main/java/net/dv8tion/jda/api/requests/restaction/pagination/ThreadChannelPaginationAction.java +++ b/src/main/java/net/dv8tion/jda/api/requests/restaction/pagination/ThreadChannelPaginationAction.java @@ -78,4 +78,14 @@ default Guild getGuild() { return getChannel().getGuild(); } + + /** + * {@inheritDoc} + * + * Note: When paginating over public and not-joined private threads, + * this skips based on {@link ThreadChannel#getTimeArchiveInfoLastModified() the archive timestamp}. + */ + @Nonnull + @Override + ThreadChannelPaginationAction skipTo(long id); } From 5b065fdb8743d2b1b05eee9efccf93cf22c442df Mon Sep 17 00:00:00 2001 From: freya02 <41875020+freya022@users.noreply.github.com> Date: Fri, 19 Apr 2024 23:39:32 +0200 Subject: [PATCH 3/3] Do not cache retrieved archived threads --- .../pagination/ThreadChannelPaginationActionImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/dv8tion/jda/internal/requests/restaction/pagination/ThreadChannelPaginationActionImpl.java b/src/main/java/net/dv8tion/jda/internal/requests/restaction/pagination/ThreadChannelPaginationActionImpl.java index 37db064821..4778b841ed 100644 --- a/src/main/java/net/dv8tion/jda/internal/requests/restaction/pagination/ThreadChannelPaginationActionImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/requests/restaction/pagination/ThreadChannelPaginationActionImpl.java @@ -14,6 +14,7 @@ import net.dv8tion.jda.api.utils.data.DataArray; import net.dv8tion.jda.api.utils.data.DataObject; import net.dv8tion.jda.internal.entities.EntityBuilder; +import net.dv8tion.jda.internal.entities.GuildImpl; import net.dv8tion.jda.internal.utils.Helpers; import javax.annotation.Nonnull; @@ -100,7 +101,7 @@ protected void handleSuccess(Response response, Request> req try { - ThreadChannel thread = builder.createThreadChannel(threadObj, getGuild().getIdLong()); + ThreadChannel thread = builder.createThreadChannel((GuildImpl) getGuild(), threadObj, getGuild().getIdLong(), false); list.add(thread); if (this.useCache)