mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-13 19:41:38 +00:00
[AB-96] adding ability to edit/delete modmail messages via editing/deleting the original message causing the message,
adding featuremode to modmail to define whether or not there is a separate message posted to the mod mail thread, to see it easier, renaming modmail related tables to singular, adding some necessary methods (caching) to all entities
This commit is contained in:
@@ -48,7 +48,7 @@ public class ModMailFeature implements FeatureConfig {
|
||||
|
||||
@Override
|
||||
public List<FeatureMode> getAvailableModes() {
|
||||
return Arrays.asList(ModMailMode.LOGGING);
|
||||
return Arrays.asList(ModMailMode.LOGGING, ModMailMode.SEPARATE_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,7 +9,7 @@ import lombok.Getter;
|
||||
*/
|
||||
@Getter
|
||||
public enum ModMailMode implements FeatureMode {
|
||||
LOGGING("log");
|
||||
LOGGING("log"), SEPARATE_MESSAGE("threadMessage");
|
||||
|
||||
private final String key;
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package dev.sheldan.abstracto.modmail.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
|
||||
public class ModMailThreadChannelNotFound extends AbstractoRunTimeException {
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import lombok.*;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.time.Instant;
|
||||
|
||||
/**
|
||||
@@ -16,19 +17,30 @@ import java.time.Instant;
|
||||
@Entity
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table(name = "modmail_messages")
|
||||
@Cacheable
|
||||
@Table(name = "modmail_message")
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode
|
||||
@Cacheable
|
||||
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
|
||||
public class ModMailMessage {
|
||||
public class ModMailMessage implements Serializable {
|
||||
|
||||
/**
|
||||
* The globally unique message ID which was send in the mod mail thread, either by a user of by the staff handling the thread
|
||||
* The ID of the message which caused this message to be created, either the message containing the command or the message received from the user
|
||||
*/
|
||||
@Id
|
||||
private Long messageId;
|
||||
|
||||
/**
|
||||
* The message which got created:
|
||||
* for a message from the user, the messageId of the message in the thread
|
||||
* for a message from staff, the messageId of the message in the DM channel
|
||||
*/
|
||||
@Column(name = "created_message_in_dm")
|
||||
private Long createdMessageInDM;
|
||||
@Column
|
||||
private Long createdMessageInChannel;
|
||||
|
||||
/**
|
||||
* The {@link AUserInAServer} which authored this message
|
||||
*/
|
||||
@@ -39,18 +51,21 @@ public class ModMailMessage {
|
||||
/**
|
||||
* The {@link ModMailThread} in whose context this message was sent and this message is related to
|
||||
*/
|
||||
@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
|
||||
@ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
|
||||
@JoinColumn(name = "threadReference", nullable = false)
|
||||
private ModMailThread threadReference;
|
||||
|
||||
/**
|
||||
* Whether or not this message was from the user or a staff member, for convenience
|
||||
* true: message was send via command, false: message was send from the user
|
||||
* This is used to decide where to get the message from in case of logging, because the user might delete the message and we do not want to re-parse the command message
|
||||
*/
|
||||
@Column
|
||||
private Boolean dmChannel;
|
||||
|
||||
/**
|
||||
* Staff only: Whether or not this message meant to be sent anonymous
|
||||
*/
|
||||
@Column
|
||||
private Boolean anonymous;
|
||||
|
||||
@Column(name = "created")
|
||||
|
||||
@@ -6,6 +6,7 @@ import lombok.*;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.time.Instant;
|
||||
|
||||
/**
|
||||
@@ -16,12 +17,13 @@ import java.time.Instant;
|
||||
@Entity
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table(name = "modmail_roles")
|
||||
@Cacheable
|
||||
@Table(name = "modmail_role")
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode
|
||||
@Cacheable
|
||||
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
|
||||
public class ModMailRole {
|
||||
public class ModMailRole implements Serializable {
|
||||
|
||||
/**
|
||||
* Unique ID of the mod mail role
|
||||
|
||||
@@ -5,6 +5,7 @@ import lombok.*;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -18,11 +19,12 @@ import java.util.List;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table(name = "modmail_thread")
|
||||
@Cacheable
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode
|
||||
@Cacheable
|
||||
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
|
||||
public class ModMailThread {
|
||||
public class ModMailThread implements Serializable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
|
||||
@@ -16,9 +16,10 @@ import java.time.Instant;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table(name = "modmail_subscriber")
|
||||
@Cacheable
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode
|
||||
@Cacheable
|
||||
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
|
||||
public class ModMailThreadSubscriber {
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package dev.sheldan.abstracto.modmail.service;
|
||||
|
||||
|
||||
import dev.sheldan.abstracto.core.models.UndoActionInstance;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AUser;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.modmail.models.database.ModMailThread;
|
||||
@@ -50,9 +51,9 @@ public interface ModMailThreadService {
|
||||
* In case there was no channel found, this will cause a message to be shown to the user and the existing mod mail thread will be closed.
|
||||
* This is the case, if the mod mail thread was still open in the database, but no text channel was found anymore.
|
||||
* @param modMailThread The {@link ModMailThread} on which the user answered
|
||||
* @param message The {@link Message} object which was sent by the user to answer with
|
||||
* @param messageFromUser The {@link Message} object which was sent by the user as an answer
|
||||
*/
|
||||
CompletableFuture<Message> relayMessageToModMailThread(ModMailThread modMailThread, Message message, List<UndoActionInstance> undoActions);
|
||||
CompletableFuture<Message> relayMessageToModMailThread(ModMailThread modMailThread, Message messageFromUser, List<UndoActionInstance> undoActions);
|
||||
|
||||
/**
|
||||
* Forwards a message send by a moderator to the direct message channel opened with the user. If the message is
|
||||
@@ -91,4 +92,7 @@ public interface ModMailThreadService {
|
||||
* @param logThread Whether or not the thread should be logged to the appropriate post target
|
||||
*/
|
||||
CompletableFuture<Void> closeModMailThread(ModMailThread modMailThread, String note, boolean notifyUser, boolean logThread, List<UndoActionInstance> undoActions);
|
||||
|
||||
boolean isModMailThread(AChannel channel);
|
||||
boolean isModMailThread(Long channelId);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import dev.sheldan.abstracto.modmail.models.database.ModMailThread;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Management service to handle the creation and retrieval of {@link ModMailMessage} instances from the database
|
||||
@@ -14,13 +15,15 @@ public interface ModMailMessageManagementService {
|
||||
/**
|
||||
* Creates an instance of {@link ModMailMessage}, attaches it to the given {@link ModMailThread} and returns the created instance
|
||||
* @param modMailThread The {@link ModMailThread} the message should be attached to
|
||||
* @param message The {@link Message} which should be attached to the {@link ModMailThread}
|
||||
* @param createdMessageInDM The {@link Message} which should be attached to the {@link ModMailThread} and was posted to the DM channel (might be null)
|
||||
* @param createdMessageInChannel The {@link Message} which should be attached to the {@link ModMailThread} and was posted to the modmail thread (might be null)
|
||||
* @param userPostedMessage The {@link Message} which caused this message to be created, the command or the message by the user
|
||||
* @param author The {@link AUserInAServer} who authored the {@link Message} originally
|
||||
* @param anonymous Whether or not the message was sent anonymous (only possible by staff members)
|
||||
* @param dmChannel Whether or not the message originated from the user, and therefore in an direct message channel
|
||||
* @return
|
||||
*/
|
||||
ModMailMessage addMessageToThread(ModMailThread modMailThread, Message message, AUserInAServer author, Boolean anonymous, Boolean dmChannel);
|
||||
ModMailMessage addMessageToThread(ModMailThread modMailThread, Message createdMessageInDM, Message createdMessageInChannel, Message userPostedMessage, AUserInAServer author, Boolean anonymous, Boolean dmChannel);
|
||||
|
||||
/**
|
||||
* Retrieves all messages which were sent in a {@link ModMailThread}
|
||||
@@ -28,4 +31,8 @@ public interface ModMailMessageManagementService {
|
||||
* @return A list of {@link ModMailMessage} which were sent in the given thread
|
||||
*/
|
||||
List<ModMailMessage> getMessagesOfThread(ModMailThread modMailThread);
|
||||
|
||||
Optional<ModMailMessage> getByMessageIdOptional(Long messageId);
|
||||
|
||||
void deleteMessageFromThread(ModMailMessage modMailMessage);
|
||||
}
|
||||
|
||||
@@ -45,6 +45,8 @@ public interface ModMailThreadManagementService {
|
||||
* @return The found mod mail thread, or null if none was found
|
||||
*/
|
||||
ModMailThread getByChannel(AChannel channel);
|
||||
Optional<ModMailThread> getByChannelOptional(AChannel channel);
|
||||
Optional<ModMailThread> getByChannelIdOptional(Long channelId);
|
||||
|
||||
/**
|
||||
* Searches for mod mail threads with the appropriate staten which concern the given {@link AUserInAServer}
|
||||
|
||||
Reference in New Issue
Block a user