diff --git a/abstracto-application/abstracto-modules/modmail/modmail-impl/src/main/java/dev/sheldan/abstracto/modmail/commands/CloseNoLog.java b/abstracto-application/abstracto-modules/modmail/modmail-impl/src/main/java/dev/sheldan/abstracto/modmail/commands/CloseNoLog.java new file mode 100644 index 000000000..433433d64 --- /dev/null +++ b/abstracto-application/abstracto-modules/modmail/modmail-impl/src/main/java/dev/sheldan/abstracto/modmail/commands/CloseNoLog.java @@ -0,0 +1,66 @@ +package dev.sheldan.abstracto.modmail.commands; + +import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand; +import dev.sheldan.abstracto.core.command.condition.CommandCondition; +import dev.sheldan.abstracto.core.command.config.CommandConfiguration; +import dev.sheldan.abstracto.core.command.config.HelpInfo; +import dev.sheldan.abstracto.core.command.execution.CommandContext; +import dev.sheldan.abstracto.core.command.execution.CommandResult; +import dev.sheldan.abstracto.core.config.FeatureEnum; +import dev.sheldan.abstracto.modmail.commands.condition.RequiresModMailCondition; +import dev.sheldan.abstracto.modmail.config.ModMailFeatures; +import dev.sheldan.abstracto.modmail.models.database.ModMailThread; +import dev.sheldan.abstracto.modmail.service.ModMailThreadService; +import dev.sheldan.abstracto.modmail.service.management.ModMailThreadManagementService; +import dev.sheldan.abstracto.templating.service.TemplateService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +public class CloseNoLog extends AbstractConditionableCommand { + + @Autowired + private RequiresModMailCondition requiresModMailCondition; + + @Autowired + private ModMailThreadManagementService modMailThreadManagementService; + + @Autowired + private ModMailThreadService modMailThreadService; + + @Autowired + private TemplateService templateService; + + @Override + public CommandResult execute(CommandContext commandContext) { + ModMailThread thread = modMailThreadManagementService.getByChannel(commandContext.getUserInitiatedContext().getChannel()); + modMailThreadService.closeModMailThread(thread, commandContext.getChannel(), null, false, false); + return CommandResult.fromSuccess(); + } + + @Override + public CommandConfiguration getConfiguration() { + HelpInfo helpInfo = HelpInfo.builder().templated(true).build(); + return CommandConfiguration.builder() + .name("closeNoLog") + .module(ModMailModuleInterface.MODMAIL) + .help(helpInfo) + .templated(true) + .causesReaction(true) + .build(); + } + + @Override + public FeatureEnum getFeature() { + return ModMailFeatures.MOD_MAIL_LOGGING; + } + + @Override + public List getConditions() { + List conditions = super.getConditions(); + conditions.add(requiresModMailCondition); + return conditions; + } +} diff --git a/abstracto-application/abstracto-modules/modmail/modmail-impl/src/main/java/dev/sheldan/abstracto/modmail/service/ModMailThreadServiceBean.java b/abstracto-application/abstracto-modules/modmail/modmail-impl/src/main/java/dev/sheldan/abstracto/modmail/service/ModMailThreadServiceBean.java index bfac42fa8..3311c8c81 100644 --- a/abstracto-application/abstracto-modules/modmail/modmail-impl/src/main/java/dev/sheldan/abstracto/modmail/service/ModMailThreadServiceBean.java +++ b/abstracto-application/abstracto-modules/modmail/modmail-impl/src/main/java/dev/sheldan/abstracto/modmail/service/ModMailThreadServiceBean.java @@ -354,12 +354,17 @@ public class ModMailThreadServiceBean implements ModMailThreadService { @Override public synchronized void closeModMailThread(ModMailThread modMailThread, MessageChannel feedBack, String note, Boolean notifyUser) { + boolean loggingEnabled = featureFlagService.isFeatureEnabled(modMailLoggingFeature, modMailThread.getServer()); + closeModMailThread(modMailThread, feedBack, note, notifyUser, loggingEnabled); + } + + @Override + public void closeModMailThread(ModMailThread modMailThread, MessageChannel feedBack, String note, Boolean notifyUser, Boolean logThread) { Long modMailThreadId = modMailThread.getId(); log.info("Starting closing procedure for thread {}", modMailThread.getId()); List modMailMessages = modMailThread.getMessages(); - boolean loggingEnabled = featureFlagService.isFeatureEnabled(modMailLoggingFeature, modMailThread.getServer()); List undoActions = new ArrayList<>(); - if(loggingEnabled) { + if(logThread) { List> messages = modMailMessageService.loadModMailMessages(modMailMessages); log.trace("Loading {} mod mail thread messages.", messages.size()); for (int i = 0; i < messages.size(); i++) { diff --git a/abstracto-application/abstracto-modules/modmail/modmail-int/src/main/java/dev/sheldan/abstracto/modmail/service/ModMailThreadService.java b/abstracto-application/abstracto-modules/modmail/modmail-int/src/main/java/dev/sheldan/abstracto/modmail/service/ModMailThreadService.java index a4025184f..654fa9bd6 100644 --- a/abstracto-application/abstracto-modules/modmail/modmail-int/src/main/java/dev/sheldan/abstracto/modmail/service/ModMailThreadService.java +++ b/abstracto-application/abstracto-modules/modmail/modmail-int/src/main/java/dev/sheldan/abstracto/modmail/service/ModMailThreadService.java @@ -18,4 +18,5 @@ public interface ModMailThreadService { void relayMessageToModMailThread(ModMailThread modMailThread, Message message); void relayMessageToDm(ModMailThread modMailThread, String text, Message message, Boolean anonymous, MessageChannel feedBack); void closeModMailThread(ModMailThread modMailThread, MessageChannel feedBack, String note, Boolean notifyUser); + void closeModMailThread(ModMailThread modMailThread, MessageChannel feedBack, String note, Boolean notifyUser, Boolean logThread); } diff --git a/abstracto-application/documentation/src/main/docs/asciidoc/features/modmail.adoc b/abstracto-application/documentation/src/main/docs/asciidoc/features/modmail.adoc index 86eba788f..7c369ee9a 100644 --- a/abstracto-application/documentation/src/main/docs/asciidoc/features/modmail.adoc +++ b/abstracto-application/documentation/src/main/docs/asciidoc/features/modmail.adoc @@ -51,12 +51,12 @@ Disabling notifications of messages sent by the user:: * Description: Removes your subscription from the current thread, and you will no longer be notified when a message from the member arrives. Closing the mod mail thread:: * Usage: `close [note]` -* Description: Closes the thread, deletes the text channel containing the thread and logs the interactions between the member and the moderators in the `modmailLog` post target. +* Description: Closes the thread, deletes the text channel containing the thread and logs the interactions between the member and the moderators in the `modmailLog` post target. (only if `modmail_logging` is enabled) When closing a thread, a closing header with general information will be send and the note will be displayed there. When a thread is closed this way the user is notified of this. Closing the mod mail thread without notifying the user:: * Usage: `closeSilently [note]` -* Description: Closes the thread, deletes the text channel containing the thread and logs the interactions between the member and the moderators in the `modmailLog` post target. +* Description: Closes the thread, deletes the text channel containing the thread and logs the interactions between the member and the moderators in the `modmailLog` post target. (only if `modmail_logging` is enabled) When closing a thread, a closing header with general information will be send and the note will be displayed there. diff --git a/abstracto-application/template-config/src/main/resources/templates/en_US/modmail/commands/close/help/close_closing_description_en_US.ftl b/abstracto-application/template-config/src/main/resources/templates/en_US/modmail/commands/close/close_closing_description_en_US.ftl similarity index 100% rename from abstracto-application/template-config/src/main/resources/templates/en_US/modmail/commands/close/help/close_closing_description_en_US.ftl rename to abstracto-application/template-config/src/main/resources/templates/en_US/modmail/commands/close/close_closing_description_en_US.ftl diff --git a/abstracto-application/template-config/src/main/resources/templates/en_US/modmail/commands/close/help/close_long_help_en_US.ftl b/abstracto-application/template-config/src/main/resources/templates/en_US/modmail/commands/close/help/close_long_help_en_US.ftl index fe5dd5549..e150eb12c 100644 --- a/abstracto-application/template-config/src/main/resources/templates/en_US/modmail/commands/close/help/close_long_help_en_US.ftl +++ b/abstracto-application/template-config/src/main/resources/templates/en_US/modmail/commands/close/help/close_long_help_en_US.ftl @@ -1 +1 @@ -Closes the mod mail thread, which means: logging the messages to mod mail log, deleting the channel the thread was in and notifying the use that the thread was closed. \ No newline at end of file +Closes the mod mail thread, which means: logging the messages to mod mail log (if `modmail_logging` is enabled), deleting the channel the thread was in and notifying the use that the thread was closed. \ No newline at end of file diff --git a/abstracto-application/template-config/src/main/resources/templates/en_US/modmail/commands/closeNoLog/help/closeNoLog_description_en_US.ftl b/abstracto-application/template-config/src/main/resources/templates/en_US/modmail/commands/closeNoLog/help/closeNoLog_description_en_US.ftl new file mode 100644 index 000000000..d0c12c98f --- /dev/null +++ b/abstracto-application/template-config/src/main/resources/templates/en_US/modmail/commands/closeNoLog/help/closeNoLog_description_en_US.ftl @@ -0,0 +1 @@ +Closes the mod mail thread, does *not* notify the user and does *not* log the thread. \ No newline at end of file diff --git a/abstracto-application/template-config/src/main/resources/templates/en_US/modmail/commands/closeNoLog/help/closeNoLog_long_help_en_US.ftl b/abstracto-application/template-config/src/main/resources/templates/en_US/modmail/commands/closeNoLog/help/closeNoLog_long_help_en_US.ftl new file mode 100644 index 000000000..a6ba698c3 --- /dev/null +++ b/abstracto-application/template-config/src/main/resources/templates/en_US/modmail/commands/closeNoLog/help/closeNoLog_long_help_en_US.ftl @@ -0,0 +1 @@ +Closes the mod mail thread, which means deleting the channel the thread was in. This command does not notify the user nor does it log the content of the thread. \ No newline at end of file diff --git a/abstracto-application/template-config/src/main/resources/templates/en_US/modmail/commands/closeNoLog/help/closeNoLog_usage_en_US.ftl b/abstracto-application/template-config/src/main/resources/templates/en_US/modmail/commands/closeNoLog/help/closeNoLog_usage_en_US.ftl new file mode 100644 index 000000000..b3ed0aaf6 --- /dev/null +++ b/abstracto-application/template-config/src/main/resources/templates/en_US/modmail/commands/closeNoLog/help/closeNoLog_usage_en_US.ftl @@ -0,0 +1 @@ +closeNoLog \ No newline at end of file diff --git a/abstracto-application/template-config/src/main/resources/templates/en_US/modmail/commands/closeSilently/help/closeSilently_long_help_en_US.ftl b/abstracto-application/template-config/src/main/resources/templates/en_US/modmail/commands/closeSilently/help/closeSilently_long_help_en_US.ftl index dfcd74de1..8f5bdf3f4 100644 --- a/abstracto-application/template-config/src/main/resources/templates/en_US/modmail/commands/closeSilently/help/closeSilently_long_help_en_US.ftl +++ b/abstracto-application/template-config/src/main/resources/templates/en_US/modmail/commands/closeSilently/help/closeSilently_long_help_en_US.ftl @@ -1 +1 @@ -Closes the mod mail thread, which means: logging the messages to mod mail log and deleting the channel the thread was in. \ No newline at end of file +Closes the mod mail thread, which means: logging the messages to mod mail log (if `modmail_logging` is enabled) and deleting the channel the thread was in. \ No newline at end of file