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

Bugfix/npe help thread close #1160

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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.togetherjava.tjbot.features.help;

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
import net.dv8tion.jda.api.entities.channel.forums.ForumTag;
import net.dv8tion.jda.api.events.channel.update.ChannelUpdateAppliedTagsEvent;
Expand Down Expand Up @@ -75,14 +76,25 @@ private void handleThreadStatus(ThreadChannel threadChannel) {
boolean isArchived = threadChannel.isArchived();

if (isArchived) {
handleArchiveStatus(closedAt, threadChannel);
handleArchiveStatus(closedAt, threadId, threadChannel.getJDA());
return;
}

updateThreadStatusToActive(threadId);
}

void handleArchiveStatus(Instant closedAt, ThreadChannel threadChannel) {
void handleArchiveStatus(Instant closedAt, long id, JDA jda) {
ThreadChannel threadChannel = jda.getThreadChannelById(id);
if (threadChannel == null) {
logger.info("thread with id: {} no longer exists, marking archived in records", id);
database.write(context -> context.update(HELP_THREADS)
.set(HELP_THREADS.CLOSED_AT, closedAt)
.set(HELP_THREADS.TICKET_STATUS, HelpSystemHelper.TicketStatus.ARCHIVED.val)
.where(HELP_THREADS.CHANNEL_ID.eq(id))
.execute());
return;
}

long threadId = threadChannel.getIdLong();
int messageCount = threadChannel.getMessageCount();
int participantsExceptAuthor = threadChannel.getMemberCount() - 1;
Expand All @@ -96,6 +108,7 @@ void handleArchiveStatus(Instant closedAt, ThreadChannel threadChannel) {
.execute());

logger.info("Thread with id: {}, updated to archived status in database", threadId);

}

private void updateThreadStatusToActive(long threadId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.togetherjava.tjbot.features.help;

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -59,13 +58,12 @@ private void updateTicketStatus(JDA jda) {
.map(HelpThreadsRecord::getChannelId)
.toList());


threadIdsToClose.forEach(id -> {
try {
Zabuzard marked this conversation as resolved.
Show resolved Hide resolved
ThreadChannel threadChannel = jda.getThreadChannelById(id);
helpThreadLifecycleListener.handleArchiveStatus(now, threadChannel);
helpThreadLifecycleListener.handleArchiveStatus(now, id, jda);
} catch (Exception exception) {
logger.warn("unable to mark thread as close with id :{}", id, exception);
logger.warn("Failed to update status of thread with id: {} to archived", id,
exception);
}
});
}
Expand Down
Loading