From: David ‘Bombe’ Roden Date: Sat, 6 Nov 2021 20:52:16 +0000 (+0100) Subject: 🔀 Merge remote-tracking branch 'origin/master' X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=0df7b8013abac27e1071761b98a106744fe1f929;hp=-c;p=xudocci.git 🔀 Merge remote-tracking branch 'origin/master' --- 0df7b8013abac27e1071761b98a106744fe1f929 diff --combined src/main/java/net/pterodactylus/xdcc/core/Core.java index 8bc923f,db64416..8ef074c --- a/src/main/java/net/pterodactylus/xdcc/core/Core.java +++ b/src/main/java/net/pterodactylus/xdcc/core/Core.java @@@ -18,10 -18,12 +18,11 @@@ package net.pterodactylus.xdcc.core; import static java.lang.String.format; + import static java.util.stream.Collectors.toSet; import static net.pterodactylus.irc.event.ChannelNotJoined.Reason.banned; import static net.pterodactylus.irc.event.ChannelNotJoined.Reason.inviteOnly; import static net.pterodactylus.irc.event.ChannelNotJoined.Reason.registeredNicknamesOnly; import static net.pterodactylus.irc.util.MessageCleaner.getDefaultInstance; -import static net.pterodactylus.xdcc.data.Channel.TO_NETWORK; import static net.pterodactylus.xdcc.data.Download.FILTER_RUNNING; import java.io.File; @@@ -185,7 -187,7 +186,7 @@@ public class Core extends AbstractExecu * @return All defined networks */ public Collection networks() { - return FluentIterable.from(channels).transform(TO_NETWORK).toSet(); + return FluentIterable.from(channels).transform(Channel::network).toSet(); } /** @@@ -410,7 -412,7 +411,7 @@@ .map(Channel::network) .distinct() .filter((network) -> !networkConnections.containsKey(network)) - .collect(Collectors.toSet()); + .collect(toSet()); if (missingNetworks.isEmpty()) { if (!missingChannels.isEmpty()) { @@@ -662,7 -664,7 +663,7 @@@ .values().stream() .filter(bot -> bot.channel() .equalsIgnoreCase(channel.get().name())) - .collect(Collectors.toSet()); + .collect(toSet()); botsToRemove.stream() .forEach(bot -> networkBots.row(network.get()) .remove(bot.name())); @@@ -886,38 -888,38 +887,38 @@@ @Subscribe public void dccSendReceived(final DccSendReceived dccSendReceived) { final Optional network = getNetwork(dccSendReceived.connection()); + eventBus.post(new GenericMessage(format("Got DCC Send from %s for %s.", dccSendReceived.source(), dccSendReceived.filename()))); if (!network.isPresent()) { return; } + eventBus.post(new GenericMessage("a")); - Collection packDownloads = downloads.get(dccSendReceived.filename()); - if (packDownloads.isEmpty()) { - /* unknown download, ignore. */ - return; - } + Set openDownloads = downloads.values().stream() + .filter(download -> download.bot().name().equalsIgnoreCase(dccSendReceived.source().nick().orNull())) + .filter(download -> download.dccReceiver() == null) + .collect(toSet()); + eventBus.post(new GenericMessage("b")); - /* check if it’s already downloading. */ - Collection runningDownloads = FluentIterable.from(packDownloads).filter(FILTER_RUNNING).toSet(); - if (!runningDownloads.isEmpty()) { - eventBus.post(new GenericMessage(String.format("Ignoring offer for %s, it’s already being downloaded.", dccSendReceived.filename()))); + if (openDownloads.isEmpty()) { + /* I don't think we requested this. */ + eventBus.post(new GenericMessage(format("Ignoring offer for %s, no open download from %s.", dccSendReceived.filename(), dccSendReceived.source()))); return; } + eventBus.post(new GenericMessage("c")); - /* locate the correct download. */ - Collection requestedDownload = FluentIterable.from(packDownloads).filter(new Predicate() { - - @Override - public boolean apply(Download download) { - return download.bot().network().equals(network.get()) && download.bot().name().equalsIgnoreCase(dccSendReceived.source().nick().get()); - } - }).toSet(); - - /* we did not request this download. */ - if (requestedDownload.isEmpty()) { + /* check if it’s already downloading. */ + if (downloads.values().stream().anyMatch(download -> download.filename().equals(dccSendReceived.filename()) && download.dccReceiver() != null)) { + eventBus.post(new GenericMessage(format("Ignoring offer for %s, it’s already being downloaded.", dccSendReceived.filename()))); return; } + eventBus.post(new GenericMessage("d")); - Download download = requestedDownload.iterator().next(); + Download download = openDownloads.stream() + .filter(it -> it.filename().equals(dccSendReceived.filename())) + .findFirst() + .orElse(openDownloads.iterator().next()); + eventBus.post(new GenericMessage("e")); + eventBus.post(new GenericMessage(format("Downloading %s from %s as %s.", dccSendReceived.filename(), dccSendReceived.source(), download.filename()))); /* check if the file already exists. */ File outputFile = new File(temporaryDirectory, dccSendReceived.filename());