X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FSoneDownloaderImpl.java;h=fed6528bc954114ba37bdb74fc0af2fe8e97424f;hb=40a1ac4c90c1480936c9c782727209cf23acd5e5;hp=ca47132445843e1e236b3bb1a25a6e89684d8396;hpb=f0bf9ce12950f0a6106f59f105dae69592203f35;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/core/SoneDownloaderImpl.java b/src/main/java/net/pterodactylus/sone/core/SoneDownloaderImpl.java index ca47132..fed6528 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneDownloaderImpl.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneDownloaderImpl.java @@ -103,18 +103,19 @@ public class SoneDownloaderImpl extends AbstractService implements SoneDownloade if (!sones.add(sone)) { freenetInterface.unregisterUsk(sone); } - freenetInterface.registerUsk(sone, this); + freenetInterface.registerUsk(sone, new SoneUpdater() { + @Override + public void updateSone(Sone sone, long edition) { + if (edition > sone.getLatestEdition()) { + sone.setLatestEdition(edition); + new Thread(fetchSoneAction(sone), + "Sone Downloader").start(); + } + } + }); } - /** - * Fetches the updated Sone. This method is a callback method for - * {@link FreenetInterface#registerUsk(Sone, SoneDownloader)}. - * - * @param sone - * The Sone to fetch - */ - @Override - public void fetchSone(Sone sone) { + private void fetchSone(Sone sone) { fetchSone(sone, sone.getRequestUri().sskForUSK()); } @@ -449,13 +450,20 @@ public class SoneDownloaderImpl extends AbstractService implements SoneDownloade } Album parent = null; if (parentId != null) { - parent = core.getAlbum(parentId, false); + parent = core.getAlbum(parentId); if (parent == null) { logger.log(Level.WARNING, String.format("Downloaded Sone %s has album with invalid parent!", sone)); return null; } } - Album album = core.getOrCreateAlbum(id).setSone(sone).modify().setTitle(title).setDescription(description).update(); + Album album = core.albumBuilder() + .withId(id) + .by(sone) + .build() + .modify() + .setTitle(title) + .setDescription(description) + .update(); if (parent != null) { parent.addAlbum(album); } else {