[AB-221] fixing embeds and starboard posts not working correctly for deleted users

This commit is contained in:
Sheldan
2021-04-04 23:51:25 +02:00
parent ff676b29e6
commit ecc81884e6
2 changed files with 26 additions and 15 deletions

View File

@@ -137,7 +137,11 @@ public class MessageEmbedServiceBean implements MessageEmbedService {
private CompletableFuture<MessageEmbeddedModel> buildTemplateParameter(Message message, CachedMessage embeddedMessage) {
return userService.retrieveUserForId(embeddedMessage.getAuthor().getAuthorId()).thenApply(authorUser ->
self.loadMessageEmbedModel(message, embeddedMessage, authorUser)
);
).exceptionally(throwable -> {
log.warn("Failed to retrieve author for user {}.", embeddedMessage.getAuthor().getAuthorId(), throwable);
self.loadMessageEmbedModel(message, embeddedMessage, null);
return null;
});
}
@Transactional

View File

@@ -147,23 +147,30 @@ public class StarboardServiceBean implements StarboardService {
private CompletableFuture<StarboardPostModel> buildStarboardPostModel(CachedMessage message, Integer starCount) {
return userService.retrieveUserForId(message.getAuthor().getAuthorId()).thenApply(user -> {
Optional<TextChannel> channel = channelService.getTextChannelFromServerOptional(message.getServerId(), message.getChannelId());
Optional<Guild> guild = guildService.getGuildByIdOptional(message.getServerId());
String starLevelEmote = getAppropriateEmote(message.getServerId(), starCount);
return StarboardPostModel
.builder()
.message(message)
.author(user)
.sourceChannelId(message.getChannelId())
.channel(channel.orElse(null))
.starCount(starCount)
.guild(guild.orElse(null))
.starLevelEmote(starLevelEmote)
.build();
return userService.retrieveUserForId(message.getAuthor().getAuthorId())
.thenApply(user -> createStarboardModel(message, starCount, user))
.exceptionally(throwable -> {
log.warn("Failed to retrieve user for author {} of starboard post.", message.getAuthor().getAuthorId(), throwable);
return createStarboardModel(message, starCount, null);
});
}
private StarboardPostModel createStarboardModel(CachedMessage message, Integer starCount, net.dv8tion.jda.api.entities.User user) {
Optional<TextChannel> channel = channelService.getTextChannelFromServerOptional(message.getServerId(), message.getChannelId());
Optional<Guild> guild = guildService.getGuildByIdOptional(message.getServerId());
String starLevelEmote = getAppropriateEmote(message.getServerId(), starCount);
return StarboardPostModel
.builder()
.message(message)
.author(user)
.sourceChannelId(message.getChannelId())
.channel(channel.orElse(null))
.starCount(starCount)
.guild(guild.orElse(null))
.starLevelEmote(starLevelEmote)
.build();
}
@Override
public CompletableFuture<Void> updateStarboardPost(StarboardPost post, CachedMessage message, List<AUserInAServer> userExceptAuthor) {
int starCount = userExceptAuthor.size();