[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);
Map<Long, List<ServerChannelMessage>> channelMessages = channelMessagesNonGrouped // in case the gild is not available anymore, this would cause the job to fail
.stream() if(guild != null) {
.collect(Collectors.groupingBy(ServerChannelMessage::getChannelId)); Map<Long, List<ServerChannelMessage>> channelMessages = channelMessagesNonGrouped
channelMessages.forEach((channelId, serverChannelMessages) -> { .stream()
MessageChannel channel = guild.getTextChannelById(channelId); .collect(Collectors.groupingBy(ServerChannelMessage::getChannelId));
serverChannelMessages.forEach(serverChannelMessage -> channelMessages.forEach((channelId, serverChannelMessages) -> {
messageFutures.add(channelService.retrieveMessageInChannel(channel, serverChannelMessage.getMessageId()))); MessageChannel channel = guild.getTextChannelById(channelId);
}); // in case the channel was deleted, this would cause the job to fail
if(channel != null) {
serverChannelMessages.forEach(serverChannelMessage ->
messageFutures.add(channelService.retrieveMessageInChannel(channel, serverChannelMessage.getMessageId())));
}
});
}
}); });
return messageFutures; return messageFutures;
} }