mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-01-25 20:04:01 +00:00
[AB-347] adding support for multiple and generic attachments to modmail
fixing editing messages with multiple embeds fixing message limit also bein imposed on pure embed count
This commit is contained in:
@@ -28,8 +28,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
@@ -106,11 +109,24 @@ public class ModMailMessageEditedListener implements AsyncMessageUpdatedListener
|
||||
.aUserInAServer(modMailMessage.getThreadReference().getUser())
|
||||
.member(targetMember)
|
||||
.build();
|
||||
List<String> imageUrls = loadedMessage
|
||||
.getAttachments()
|
||||
.stream()
|
||||
.filter(Message.Attachment::isImage)
|
||||
.map(Message.Attachment::getProxyUrl)
|
||||
.collect(Collectors.toList());
|
||||
Map<String, String> otherAttachments = loadedMessage
|
||||
.getAttachments()
|
||||
.stream()
|
||||
.filter(attachment -> !attachment.isImage())
|
||||
.collect(Collectors.toMap(Message.Attachment::getFileName, Message.Attachment::getUrl));
|
||||
ModMailModeratorReplyModel.ModMailModeratorReplyModelBuilder modMailModeratorReplyModelBuilder = ModMailModeratorReplyModel
|
||||
.builder()
|
||||
.text(newText)
|
||||
.modMailThread(modMailMessage.getThreadReference())
|
||||
.postedMessage(loadedMessage)
|
||||
.attachedImageUrls(imageUrls)
|
||||
.remainingAttachments(otherAttachments)
|
||||
.anonymous(modMailMessage.getAnonymous())
|
||||
.threadUser(fullThreadUser);
|
||||
if(modMailMessage.getAnonymous()) {
|
||||
|
||||
@@ -498,10 +498,23 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
||||
.map(CompletableFuture::join)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
List<String> imageUrls = messageFromUser
|
||||
.getAttachments()
|
||||
.stream()
|
||||
.filter(Message.Attachment::isImage)
|
||||
.map(Message.Attachment::getProxyUrl)
|
||||
.collect(Collectors.toList());
|
||||
Map<String, String> otherAttachments = messageFromUser
|
||||
.getAttachments()
|
||||
.stream()
|
||||
.filter(attachment -> !attachment.isImage())
|
||||
.collect(Collectors.toMap(Message.Attachment::getFileName, Message.Attachment::getUrl));
|
||||
ModMailUserReplyModel modMailUserReplyModel = ModMailUserReplyModel
|
||||
.builder()
|
||||
.postedMessage(messageFromUser)
|
||||
.member(member)
|
||||
.attachedImageUrls(imageUrls)
|
||||
.remainingAttachments(otherAttachments)
|
||||
.subscribers(subscribers)
|
||||
.build();
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate("modmail_user_message", modMailUserReplyModel, textChannel.getGuild().getIdLong());
|
||||
@@ -568,11 +581,24 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
||||
.aUserInAServer(modMailThread.getUser())
|
||||
.member(targetMember)
|
||||
.build();
|
||||
List<String> imageUrls = replyCommandMessage
|
||||
.getAttachments()
|
||||
.stream()
|
||||
.filter(Message.Attachment::isImage)
|
||||
.map(Message.Attachment::getProxyUrl)
|
||||
.collect(Collectors.toList());
|
||||
Map<String, String> otherAttachments = replyCommandMessage
|
||||
.getAttachments()
|
||||
.stream()
|
||||
.filter(attachment -> !attachment.isImage())
|
||||
.collect(Collectors.toMap(Message.Attachment::getFileName, Message.Attachment::getUrl));
|
||||
ModMailModeratorReplyModel.ModMailModeratorReplyModelBuilder modMailModeratorReplyModelBuilder = ModMailModeratorReplyModel
|
||||
.builder()
|
||||
.text(text)
|
||||
.modMailThread(modMailThread)
|
||||
.postedMessage(replyCommandMessage)
|
||||
.remainingAttachments(otherAttachments)
|
||||
.attachedImageUrls(imageUrls)
|
||||
.anonymous(anonymous)
|
||||
.threadUser(fullThreadUser);
|
||||
if(anonymous) {
|
||||
@@ -798,7 +824,8 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
||||
return modMailMessage.getCreatedMessageInChannel().equals(message.getIdLong());
|
||||
}
|
||||
})
|
||||
.findFirst().orElseThrow(() -> new AbstractoRunTimeException("Could not find desired message in list of messages in thread. This should not happen, as we just retrieved them from the same place."));
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new AbstractoRunTimeException("Could not find desired message in list of messages in thread. This should not happen, as we just retrieved them from the same place."));
|
||||
User author = authors.getOrDefault(modmailMessage.getAuthor().getUserReference().getId(), message.getJDA().getSelfUser());
|
||||
ModMailLoggedMessageModel modMailLoggedMessageModel =
|
||||
ModMailLoggedMessageModel
|
||||
|
||||
@@ -8,6 +8,9 @@ import lombok.Setter;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Model used to render the response by staff members to the DM channel with the user
|
||||
*/
|
||||
@@ -36,6 +39,8 @@ public class ModMailModeratorReplyModel {
|
||||
* Whether or not the reply should be shown anonymous
|
||||
*/
|
||||
private Boolean anonymous;
|
||||
private List<String> attachedImageUrls;
|
||||
private Map<String, String> remainingAttachments;
|
||||
/**
|
||||
* The {@link ModMailThread} to reply to
|
||||
*/
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Model used to render the response by the user to the mod mail thread channel.
|
||||
@@ -23,6 +24,8 @@ public class ModMailUserReplyModel {
|
||||
* The {@link Message} which was posted, which contains all the possible information
|
||||
*/
|
||||
private Message postedMessage;
|
||||
private List<String> attachedImageUrls;
|
||||
private Map<String, String> remainingAttachments;
|
||||
/**
|
||||
* List of {@link Member} which are registered as subscribers for a particular mod mail thread and will be pinged
|
||||
* when the user sends a new message
|
||||
|
||||
Reference in New Issue
Block a user