diff --git a/abstracto-application/abstracto-modules/modmail/modmail-impl/src/main/java/dev/sheldan/abstracto/modmail/listener/ModMailConfigListener.java b/abstracto-application/abstracto-modules/modmail/modmail-impl/src/main/java/dev/sheldan/abstracto/modmail/listener/ModMailConfigListener.java index 96e4c2aa5..4e5c4502e 100644 --- a/abstracto-application/abstracto-modules/modmail/modmail-impl/src/main/java/dev/sheldan/abstracto/modmail/listener/ModMailConfigListener.java +++ b/abstracto-application/abstracto-modules/modmail/modmail-impl/src/main/java/dev/sheldan/abstracto/modmail/listener/ModMailConfigListener.java @@ -4,17 +4,25 @@ import dev.sheldan.abstracto.core.listener.ServerConfigListener; import dev.sheldan.abstracto.core.models.database.AServer; import dev.sheldan.abstracto.core.service.management.ConfigManagementService; import dev.sheldan.abstracto.modmail.service.ModMailThreadServiceBean; +import dev.sheldan.abstracto.templating.service.TemplateService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import static dev.sheldan.abstracto.modmail.service.ModMailThreadServiceBean.MODMAIL_CLOSING_MESSAGE_TEXT; + @Component public class ModMailConfigListener implements ServerConfigListener { + @Autowired private ConfigManagementService configService; + @Autowired + private TemplateService templateService; + @Override public void updateServerConfig(AServer server) { configService.createIfNotExists(server.getId(), ModMailThreadServiceBean.MODMAIL_CATEGORY, 0L); + configService.createIfNotExists(server.getId(), MODMAIL_CLOSING_MESSAGE_TEXT, templateService.renderSimpleTemplate("modmail_closing_user_message_description")); } } 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 bb20ce19c..fd6bc0c23 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 @@ -39,6 +39,7 @@ import java.util.concurrent.ExecutionException; @Slf4j public class ModMailThreadServiceBean implements ModMailThreadService { + public static final String MODMAIL_CLOSING_MESSAGE_TEXT = "modMailClosingText"; public static final String MODMAIL_CATEGORY = "modmailCategory"; @Autowired private ModMailThreadManagementService modMailThreadManagementService; @@ -129,19 +130,25 @@ public class ModMailThreadServiceBean implements ModMailThreadService { try { ModMailThread thread = createThreadObject(channel, aUserInAServer); sendModMailHeader(channel, aUserInAServer, undoActions); + CompletableFuture future; if(initialMessage != null){ - self.sendUserReply(channel, thread, initialMessage); - } - if(userInitiated) { - sendModMailNotification(aUserInAServer, thread, undoActions); + future = self.sendUserReply(channel, thread, initialMessage); + } else { + future = CompletableFuture.completedFuture(null); } + future.thenAccept(aVoid -> { + if(userInitiated) { + self.sendModMailNotification(aUserInAServer, thread, undoActions); + } + }); } catch (Exception e) { log.error("Failed to perform mod mail thread setup.", e); undoActionService.performActions(undoActions); } } - private void sendModMailNotification(FullUser aUserInAServer, ModMailThread thread, List undoActions) { + @Transactional + public void sendModMailNotification(FullUser aUserInAServer, ModMailThread thread, List undoActions) { List rolesToPing = modMailRoleManagementService.getRolesForServer(thread.getServer()); ModMailNotificationModel modMailNotificationModel = ModMailNotificationModel .builder() @@ -259,7 +266,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService { } } - public void sendUserReply(TextChannel textChannel, ModMailThread modMailThread, Message message) { + public CompletableFuture sendUserReply(TextChannel textChannel, ModMailThread modMailThread, Message message) { Long modMailThreadId = modMailThread.getId(); FullUser fullUser = FullUser .builder() @@ -286,7 +293,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService { .build(); MessageToSend messageToSend = templateService.renderEmbedTemplate("modmail_user_message", modMailUserReplyModel); List> completableFutures = channelService.sendMessageToSendToChannel(messageToSend, textChannel); - CompletableFuture.allOf(completableFutures.toArray(new CompletableFuture[0])).thenAccept(aVoid -> { + return CompletableFuture.allOf(completableFutures.toArray(new CompletableFuture[0])).thenAccept(aVoid -> { self.postProcessSendMessages(modMailThreadId, message, completableFutures); }); @@ -433,7 +440,10 @@ public class ModMailThreadServiceBean implements ModMailThreadService { List> messageFutures = new ArrayList<>(); if(notifyUser){ log.trace("Notifying user {}", user.getIdLong()); - messageFutures.addAll(channelService.sendTemplateInChannel("modmail_closing_user_message", new Object(), privateChannel)); + HashMap closingMessage = new HashMap<>(); + String defaultValue = templateService.renderSimpleTemplate("modmail_closing_user_message_description"); + closingMessage.put("closingMessage", configService.getStringValue(MODMAIL_CLOSING_MESSAGE_TEXT, modMailThread.getServer().getId(), defaultValue)); + messageFutures.addAll(channelService.sendTemplateInChannel("modmail_closing_user_message", closingMessage , privateChannel)); } else { log.trace("*Not* notifying user {}", user.getIdLong()); messageFutures.add(CompletableFuture.completedFuture(null)); diff --git a/abstracto-application/abstracto-modules/modmail/modmail-impl/src/main/resources/templates/modmail/closing/modmail_closing_user_message_embed_en_US.ftl b/abstracto-application/abstracto-modules/modmail/modmail-impl/src/main/resources/templates/modmail/closing/modmail_closing_user_message_embed_en_US.ftl index c32666b1a..acba982f8 100644 --- a/abstracto-application/abstracto-modules/modmail/modmail-impl/src/main/resources/templates/modmail/closing/modmail_closing_user_message_embed_en_US.ftl +++ b/abstracto-application/abstracto-modules/modmail/modmail-impl/src/main/resources/templates/modmail/closing/modmail_closing_user_message_embed_en_US.ftl @@ -4,5 +4,5 @@ "g": 0, "b": 255 }, - "description": "<#include "modmail_closing_user_message_description">" + "description": "${closingMessage}" } \ No newline at end of file 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 f23bf6f91..8182dbbfb 100644 --- a/abstracto-application/documentation/src/main/docs/asciidoc/features/modmail.adoc +++ b/abstracto-application/documentation/src/main/docs/asciidoc/features/modmail.adoc @@ -14,6 +14,10 @@ This feature enables users to contact the moderation of the server in a private Feature key: `modmail` +==== Relevant system configuration +`modmailCategory`:: The category on the server which is used to hold the text channels representing the threads +`modMailClosingText`::The text being used when notifying the user when a thread is closed. + ==== Post targets `modmailPing`:: Will be used to send the notification when a new thread is opened. `modmailLog`:: Will be used to log the interactions when a thread is closed. @@ -68,8 +72,3 @@ Close a thread without logging * Description: Closes the thread without notifying the user and without logging the messages. * Mode Restriction: This command is only available when mod mail is in the mode `log`. -=== Mod mail thread logging - - - -==== Post targets