[AB-243] when loading messages we ignore embed links part of a channel/guild which are not available anymore

This commit is contained in:
Sheldan
2021-05-01 12:31:27 +02:00
parent 5a6fac640e
commit fa864f85dd

View File

@@ -126,14 +126,20 @@ public class MessageServiceBean implements MessageService {
.collect(Collectors.groupingBy(ServerChannelMessage::getServerId)); .collect(Collectors.groupingBy(ServerChannelMessage::getServerId));
serverMessages.forEach((serverId, channelMessagesNonGrouped) -> { serverMessages.forEach((serverId, channelMessagesNonGrouped) -> {
Guild guild = guildService.getGuildById(serverId); Guild guild = guildService.getGuildById(serverId);
// in case the gild is not available anymore, this would cause the job to fail
if(guild != null) {
Map<Long, List<ServerChannelMessage>> channelMessages = channelMessagesNonGrouped Map<Long, List<ServerChannelMessage>> channelMessages = channelMessagesNonGrouped
.stream() .stream()
.collect(Collectors.groupingBy(ServerChannelMessage::getChannelId)); .collect(Collectors.groupingBy(ServerChannelMessage::getChannelId));
channelMessages.forEach((channelId, serverChannelMessages) -> { channelMessages.forEach((channelId, serverChannelMessages) -> {
MessageChannel channel = guild.getTextChannelById(channelId); MessageChannel channel = guild.getTextChannelById(channelId);
// in case the channel was deleted, this would cause the job to fail
if(channel != null) {
serverChannelMessages.forEach(serverChannelMessage -> serverChannelMessages.forEach(serverChannelMessage ->
messageFutures.add(channelService.retrieveMessageInChannel(channel, serverChannelMessage.getMessageId()))); messageFutures.add(channelService.retrieveMessageInChannel(channel, serverChannelMessage.getMessageId())));
}
}); });
}
}); });
return messageFutures; return messageFutures;
} }