-
-
Notifications
You must be signed in to change notification settings - Fork 91
Feat/meta data v2 #990
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
Merged
Merged
Feat/meta data v2 #990
Changes from 7 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
744d816
alter help_thread table to add more meta data
ankitsmt211 bc3fab1
update write operation with extra fields
ankitsmt211 0f5e116
listener that updates meta data based on thread status
ankitsmt211 ff7ec2f
fix error in log messages
ankitsmt211 8508977
method to update tagName on change in db
ankitsmt211 198df3a
more suitable name for class and java doc
ankitsmt211 76b09e9
change name to avoid confusion & update java doc
ankitsmt211 c2842cf
minor bug that would change status back to active again and log messa…
ankitsmt211 c5768c2
more columns added for metadata
ankitsmt211 a1ecd95
update listener to record added metadata columns
ankitsmt211 0bd0c13
spotless fix
ankitsmt211 28c28b4
replacing get(0) with getFirst() for list
ankitsmt211 7708513
add routine to settle thread status if was left open
ankitsmt211 3323c48
resolve conflicts
ankitsmt211 ab0fe61
spotless fix
ankitsmt211 58b1292
refactor MarkHelpThreadCloseInDBRoutine and changes
ankitsmt211 dcf9a7a
document updated param in MarkHelpThreadCloseInDBRoutine constructor
ankitsmt211 41667e3
use time of creation/modfication from thread and tags as csv
ankitsmt211 ca6d4d4
rely on discord for getting thread status instead of DB
ankitsmt211 6d2848e
Merge branch 'develop' into feat/meta-data-v2
ankitsmt211 87461c3
changes
ankitsmt211 7d2256c
change list
ankitsmt211 3089083
spotless fix
ankitsmt211 a665aa7
tags from config sanitized
ankitsmt211 b061ae0
requested changes
ankitsmt211 e302e95
spotless
ankitsmt211 c745481
requested changes
ankitsmt211 495e4d2
remove unnecessary map
ankitsmt211 b10387c
increase routine schedule to 24 hrs
ankitsmt211 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
...ation/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadLifecycleListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package org.togetherjava.tjbot.features.help; | ||
|
||
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; | ||
import net.dv8tion.jda.api.events.channel.update.ChannelUpdateAppliedTagsEvent; | ||
import net.dv8tion.jda.api.events.channel.update.ChannelUpdateArchivedEvent; | ||
import net.dv8tion.jda.api.hooks.ListenerAdapter; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import org.togetherjava.tjbot.db.Database; | ||
import org.togetherjava.tjbot.features.EventReceiver; | ||
|
||
import java.time.Instant; | ||
|
||
import static org.togetherjava.tjbot.db.generated.tables.HelpThreads.HELP_THREADS; | ||
|
||
/** | ||
* Listens for help thread events after creation of thread. Updates metadata based on those events | ||
* in database. | ||
*/ | ||
public final class HelpThreadLifecycleListener extends ListenerAdapter implements EventReceiver { | ||
|
||
private final HelpSystemHelper helper; | ||
private final Logger logger = LoggerFactory.getLogger(HelpThreadLifecycleListener.class); | ||
private final Database database; | ||
Taz03 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* Creates a new instance. | ||
* | ||
* @param helper to work with the help threads | ||
* @param database the database to store help thread metadata in | ||
*/ | ||
public HelpThreadLifecycleListener(HelpSystemHelper helper, Database database) { | ||
this.helper = helper; | ||
this.database = database; | ||
} | ||
|
||
@Override | ||
public void onChannelUpdateArchived(@NotNull ChannelUpdateArchivedEvent event) { | ||
if (!event.getChannelType().isThread()) { | ||
return; | ||
} | ||
Taz03 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ThreadChannel threadChannel = event.getChannel().asThreadChannel(); | ||
|
||
if (!helper.isHelpForumName(threadChannel.getParentChannel().getName())) { | ||
return; | ||
} | ||
handleThreadStatus(threadChannel.getIdLong()); | ||
} | ||
|
||
@Override | ||
public void onChannelUpdateAppliedTags(@NotNull ChannelUpdateAppliedTagsEvent event) { | ||
Taz03 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ThreadChannel threadChannel = event.getChannel().asThreadChannel(); | ||
ankitsmt211 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (!helper.isHelpForumName(threadChannel.getParentChannel().getName())) { | ||
return; | ||
} | ||
|
||
String updatedTag = event.getAddedTags().getFirst().getName(); | ||
Taz03 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
long threadId = threadChannel.getIdLong(); | ||
|
||
handleTagsUpdate(threadId, updatedTag); | ||
} | ||
|
||
private void handleThreadStatus(long threadId) { | ||
Instant closedAt = Instant.now(); | ||
Taz03 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
int status = database.read(context -> context.selectFrom(HELP_THREADS) | ||
.where(HELP_THREADS.CHANNEL_ID.eq(threadId)) | ||
.fetchOne(HELP_THREADS.TICKET_STATUS)); | ||
|
||
if (status == HelpSystemHelper.TicketStatus.ACTIVE.val) { | ||
changeStatusToArchive(closedAt, threadId); | ||
} | ||
|
||
changeStatusToActive(threadId); | ||
} | ||
|
||
private void changeStatusToArchive(Instant closedAt, long threadId) { | ||
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(threadId)) | ||
.execute()); | ||
|
||
logger.info("Thread with id: {}, updated to archived in database", threadId); | ||
} | ||
|
||
private void changeStatusToActive(long threadId) { | ||
database.write(context -> context.update(HELP_THREADS) | ||
.set(HELP_THREADS.TICKET_STATUS, HelpSystemHelper.TicketStatus.ACTIVE.val) | ||
.where(HELP_THREADS.CHANNEL_ID.eq(threadId)) | ||
.execute()); | ||
|
||
logger.info("Thread with id: {}, updated to active status in database", threadId); | ||
} | ||
|
||
private void handleTagsUpdate(long threadId, String updatedTag) { | ||
database.write(context -> context.update(HELP_THREADS) | ||
.set(HELP_THREADS.TAG, updatedTag) | ||
.where(HELP_THREADS.CHANNEL_ID.eq(threadId)) | ||
.execute()); | ||
|
||
logger.info("Updated tag for thread with id: {} in database", threadId); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
application/src/main/resources/db/V14__Alter_Help_Thread_Metadata.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ALTER TABLE help_threads ADD ticket_status INTEGER DEFAULT 0; | ||
ALTER TABLE help_threads ADD tag TEXT DEFAULT 'none'; | ||
Taz03 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ALTER TABLE help_threads ADD closed_at TIMESTAMP NULL; | ||
ankitsmt211 marked this conversation as resolved.
Show resolved
Hide resolved
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.