mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-16 04:21:49 +00:00
[AB-xxx] using the suggestion message as the thread starter for suggestion threads
This commit is contained in:
@@ -105,6 +105,9 @@ public class SuggestionServiceBean implements SuggestionService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private SuggestionVoteManagementService suggestionVoteManagementService;
|
private SuggestionVoteManagementService suggestionVoteManagementService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ChannelService channelService;
|
||||||
|
|
||||||
@Value("${abstracto.feature.suggestion.removalMaxAge}")
|
@Value("${abstracto.feature.suggestion.removalMaxAge}")
|
||||||
private Long removalMaxAgeSeconds;
|
private Long removalMaxAgeSeconds;
|
||||||
|
|
||||||
@@ -155,18 +158,18 @@ public class SuggestionServiceBean implements SuggestionService {
|
|||||||
List<ButtonConfigModel> buttonConfigModels = Arrays.asList(model.getAgreeButtonModel(), model.getDisAgreeButtonModel(), model.getRemoveVoteButtonModel());
|
List<ButtonConfigModel> buttonConfigModels = Arrays.asList(model.getAgreeButtonModel(), model.getDisAgreeButtonModel(), model.getRemoveVoteButtonModel());
|
||||||
return FutureUtils.toSingleFutureGeneric(completableFutures)
|
return FutureUtils.toSingleFutureGeneric(completableFutures)
|
||||||
.thenCompose(aVoid -> self.addVotingPossibility(suggestionChannelId, suggestionMessageId, text, suggester, serverId, newSuggestionId, completableFutures, buttonConfigModels, useButtons))
|
.thenCompose(aVoid -> self.addVotingPossibility(suggestionChannelId, suggestionMessageId, text, suggester, serverId, newSuggestionId, completableFutures, buttonConfigModels, useButtons))
|
||||||
.thenCompose(aVoid -> self.createSuggestionThread(serverId, newSuggestionId, suggester, text, autoEvaluationEnabled, autoEvaluationTargetDate));
|
.thenCompose(aVoid -> self.createSuggestionThread(serverId, newSuggestionId, suggester, text, autoEvaluationEnabled, autoEvaluationTargetDate, completableFutures));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public CompletableFuture<Void> createSuggestionThread(Long serverId, Long suggestionId, Member suggester, String suggestionText,
|
public CompletableFuture<Void> createSuggestionThread(Long serverId, Long suggestionId, Member suggester, String suggestionText,
|
||||||
Boolean autoEvaluationEnabled, Instant autoEvaluationTargetDate) {
|
Boolean autoEvaluationEnabled, Instant autoEvaluationTargetDate, List<CompletableFuture<Message>> completableFutures) {
|
||||||
if(featureModeService.featureModeActive(SuggestionFeatureDefinition.SUGGEST, serverId, SuggestionFeatureMode.SUGGESTION_THREAD)) {
|
if(featureModeService.featureModeActive(SuggestionFeatureDefinition.SUGGEST, serverId, SuggestionFeatureMode.SUGGESTION_THREAD)) {
|
||||||
Optional<GuildMessageChannel> suggestionTargetChannelOptional = postTargetService.getPostTargetChannel(SuggestionPostTarget.SUGGESTION, serverId);
|
Optional<GuildMessageChannel> suggestionTargetChannelOptional = postTargetService.getPostTargetChannel(SuggestionPostTarget.SUGGESTION, serverId);
|
||||||
log.info("Trying to create thread for suggestion {} in server {}.", suggestionId, serverId);
|
log.info("Trying to create thread for suggestion {} in server {}.", suggestionId, serverId);
|
||||||
if (suggestionTargetChannelOptional.isPresent()) {
|
if (suggestionTargetChannelOptional.isPresent()) {
|
||||||
GuildMessageChannel messageChannel = suggestionTargetChannelOptional.get();
|
GuildMessageChannel messageChannel = suggestionTargetChannelOptional.get();
|
||||||
if(messageChannel instanceof IThreadContainer) {
|
if(messageChannel instanceof IThreadContainer threadContainer) {
|
||||||
SuggestionThreadModel model = SuggestionThreadModel
|
SuggestionThreadModel model = SuggestionThreadModel
|
||||||
.builder()
|
.builder()
|
||||||
.suggestionId(suggestionId)
|
.suggestionId(suggestionId)
|
||||||
@@ -176,10 +179,15 @@ public class SuggestionServiceBean implements SuggestionService {
|
|||||||
.text(suggestionText)
|
.text(suggestionText)
|
||||||
.autoEvaluationTargetDate(autoEvaluationTargetDate)
|
.autoEvaluationTargetDate(autoEvaluationTargetDate)
|
||||||
.build();
|
.build();
|
||||||
IThreadContainer threadContainer = (IThreadContainer) messageChannel;
|
|
||||||
String threadName = templateService.renderTemplate("suggestion_thread_name", model, serverId);
|
String threadName = templateService.renderTemplate("suggestion_thread_name", model, serverId);
|
||||||
return threadContainer.createThreadChannel(threadName).submit()
|
if(!completableFutures.isEmpty()) {
|
||||||
.thenAccept(threadChannel -> log.info("Created thread for suggestion {} in server {}.", suggestionId, serverId));
|
Long suggestionMessageId = completableFutures.get(0).join().getIdLong();
|
||||||
|
return channelService.createThreadChannel(threadContainer, threadName, suggestionMessageId)
|
||||||
|
.thenAccept(threadChannel -> log.info("Created thread for suggestion {} in server {} using the suggestion message {} as starter.", suggestionId, serverId, suggestionMessageId));
|
||||||
|
} else {
|
||||||
|
return channelService.createThreadChannel(threadContainer, threadName)
|
||||||
|
.thenAccept(threadChannel -> log.info("Created thread for suggestion {} in server {}.", suggestionId, serverId));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
log.info("Suggestion thread was not created - post target for suggestions does not allow to create threads");
|
log.info("Suggestion thread was not created - post target for suggestions does not allow to create threads");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.Permission;
|
import net.dv8tion.jda.api.Permission;
|
||||||
import net.dv8tion.jda.api.entities.*;
|
import net.dv8tion.jda.api.entities.*;
|
||||||
|
import net.dv8tion.jda.api.entities.channel.attribute.IThreadContainer;
|
||||||
import net.dv8tion.jda.api.entities.channel.concrete.Category;
|
import net.dv8tion.jda.api.entities.channel.concrete.Category;
|
||||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||||
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
|
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
|
||||||
@@ -116,6 +117,16 @@ public class ChannelServiceBean implements ChannelService {
|
|||||||
sendTextToChannel(text, channel);
|
sendTextToChannel(text, channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<ThreadChannel> createThreadChannel(IThreadContainer threadContainer, String name) {
|
||||||
|
return threadContainer.createThreadChannel(name).submit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<ThreadChannel> createThreadChannel(IThreadContainer threadContainer, String name, Long messageId) {
|
||||||
|
return threadContainer.createThreadChannel(name, messageId).submit();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Message> sendTextToAChannel(String text, AChannel channel) {
|
public CompletableFuture<Message> sendTextToAChannel(String text, AChannel channel) {
|
||||||
GuildMessageChannel guildMessageChannel = getGuildMessageChannelFromAChannel(channel);
|
GuildMessageChannel guildMessageChannel = getGuildMessageChannelFromAChannel(channel);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import dev.sheldan.abstracto.core.models.database.AServer;
|
|||||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||||
import net.dv8tion.jda.api.Permission;
|
import net.dv8tion.jda.api.Permission;
|
||||||
import net.dv8tion.jda.api.entities.*;
|
import net.dv8tion.jda.api.entities.*;
|
||||||
|
import net.dv8tion.jda.api.entities.channel.attribute.IThreadContainer;
|
||||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||||
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
|
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
|
||||||
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
|
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
|
||||||
@@ -20,6 +21,8 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
public interface ChannelService {
|
public interface ChannelService {
|
||||||
void sendTextToAChannelNotAsync(String text, AChannel channel);
|
void sendTextToAChannelNotAsync(String text, AChannel channel);
|
||||||
void sendTextToChannelNotAsync(String text, MessageChannel channel);
|
void sendTextToChannelNotAsync(String text, MessageChannel channel);
|
||||||
|
CompletableFuture<ThreadChannel> createThreadChannel(IThreadContainer threadContainer, String name);
|
||||||
|
CompletableFuture<ThreadChannel> createThreadChannel(IThreadContainer threadContainer, String name, Long messageId);
|
||||||
CompletableFuture<Message> sendTextToAChannel(String text, AChannel channel);
|
CompletableFuture<Message> sendTextToAChannel(String text, AChannel channel);
|
||||||
CompletableFuture<Message> sendMessageToAChannel(Message message, AChannel channel);
|
CompletableFuture<Message> sendMessageToAChannel(Message message, AChannel channel);
|
||||||
CompletableFuture<Message> sendMessageToChannel(Message message, GuildMessageChannel channel);
|
CompletableFuture<Message> sendMessageToChannel(Message message, GuildMessageChannel channel);
|
||||||
|
|||||||
Reference in New Issue
Block a user