2 * Sone - Core.java - Copyright © 2010–2020 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.core;
20 import static com.google.common.base.Optional.fromNullable;
21 import static com.google.common.base.Preconditions.checkArgument;
22 import static com.google.common.base.Preconditions.checkNotNull;
23 import static com.google.common.primitives.Longs.tryParse;
24 import static java.lang.String.format;
25 import static java.util.logging.Level.WARNING;
26 import static java.util.logging.Logger.getLogger;
27 import static net.pterodactylus.sone.data.AlbumsKt.getAllImages;
29 import java.util.ArrayList;
30 import java.util.Collection;
31 import java.util.HashMap;
32 import java.util.HashSet;
33 import java.util.List;
35 import java.util.Map.Entry;
37 import java.util.concurrent.ExecutorService;
38 import java.util.concurrent.Executors;
39 import java.util.concurrent.ScheduledExecutorService;
40 import java.util.concurrent.TimeUnit;
41 import java.util.concurrent.atomic.*;
42 import java.util.logging.Level;
43 import java.util.logging.Logger;
45 import javax.annotation.Nonnull;
46 import javax.annotation.Nullable;
48 import com.codahale.metrics.*;
49 import net.pterodactylus.sone.core.ConfigurationSoneParser.InvalidAlbumFound;
50 import net.pterodactylus.sone.core.ConfigurationSoneParser.InvalidImageFound;
51 import net.pterodactylus.sone.core.ConfigurationSoneParser.InvalidParentAlbumFound;
52 import net.pterodactylus.sone.core.ConfigurationSoneParser.InvalidPostFound;
53 import net.pterodactylus.sone.core.ConfigurationSoneParser.InvalidPostReplyFound;
54 import net.pterodactylus.sone.core.event.*;
55 import net.pterodactylus.sone.data.Album;
56 import net.pterodactylus.sone.data.Client;
57 import net.pterodactylus.sone.data.Image;
58 import net.pterodactylus.sone.data.Post;
59 import net.pterodactylus.sone.data.PostReply;
60 import net.pterodactylus.sone.data.Profile;
61 import net.pterodactylus.sone.data.Profile.Field;
62 import net.pterodactylus.sone.data.Reply;
63 import net.pterodactylus.sone.data.Sone;
64 import net.pterodactylus.sone.data.Sone.SoneStatus;
65 import net.pterodactylus.sone.data.SoneOptions.LoadExternalContent;
66 import net.pterodactylus.sone.data.TemporaryImage;
67 import net.pterodactylus.sone.database.AlbumBuilder;
68 import net.pterodactylus.sone.database.Database;
69 import net.pterodactylus.sone.database.DatabaseException;
70 import net.pterodactylus.sone.database.ImageBuilder;
71 import net.pterodactylus.sone.database.PostBuilder;
72 import net.pterodactylus.sone.database.PostProvider;
73 import net.pterodactylus.sone.database.PostReplyBuilder;
74 import net.pterodactylus.sone.database.PostReplyProvider;
75 import net.pterodactylus.sone.database.SoneBuilder;
76 import net.pterodactylus.sone.database.SoneProvider;
77 import net.pterodactylus.sone.freenet.wot.Identity;
78 import net.pterodactylus.sone.freenet.wot.IdentityManager;
79 import net.pterodactylus.sone.freenet.wot.OwnIdentity;
80 import net.pterodactylus.sone.freenet.wot.event.IdentityAddedEvent;
81 import net.pterodactylus.sone.freenet.wot.event.IdentityRemovedEvent;
82 import net.pterodactylus.sone.freenet.wot.event.IdentityUpdatedEvent;
83 import net.pterodactylus.sone.freenet.wot.event.OwnIdentityAddedEvent;
84 import net.pterodactylus.sone.freenet.wot.event.OwnIdentityRemovedEvent;
85 import net.pterodactylus.sone.main.SonePlugin;
86 import net.pterodactylus.util.config.Configuration;
87 import net.pterodactylus.util.config.ConfigurationException;
88 import net.pterodactylus.util.service.AbstractService;
89 import net.pterodactylus.util.thread.NamedThreadFactory;
91 import com.google.common.annotations.VisibleForTesting;
92 import com.google.common.base.Stopwatch;
93 import com.google.common.collect.FluentIterable;
94 import com.google.common.collect.HashMultimap;
95 import com.google.common.collect.Multimap;
96 import com.google.common.collect.Multimaps;
97 import com.google.common.eventbus.EventBus;
98 import com.google.common.eventbus.Subscribe;
99 import com.google.inject.Inject;
100 import com.google.inject.Singleton;
101 import kotlin.jvm.functions.Function1;
107 public class Core extends AbstractService implements SoneProvider, PostProvider, PostReplyProvider {
110 private static final Logger logger = getLogger(Core.class.getName());
112 /** The start time. */
113 private final long startupTime = System.currentTimeMillis();
115 private final AtomicBoolean debug = new AtomicBoolean(false);
117 /** The preferences. */
118 private final Preferences preferences;
120 /** The event bus. */
121 private final EventBus eventBus;
123 /** The configuration. */
124 private final Configuration configuration;
126 /** Whether we’re currently saving the configuration. */
127 private boolean storingConfiguration = false;
129 /** The identity manager. */
130 private final IdentityManager identityManager;
132 /** Interface to freenet. */
133 private final FreenetInterface freenetInterface;
135 /** The Sone downloader. */
136 private final SoneDownloader soneDownloader;
138 /** The image inserter. */
139 private final ImageInserter imageInserter;
141 /** Sone downloader thread-pool. */
142 private final ExecutorService soneDownloaders = Executors.newFixedThreadPool(10, new NamedThreadFactory("Sone Downloader %2$d"));
144 /** The update checker. */
145 private final UpdateChecker updateChecker;
147 /** The trust updater. */
148 private final WebOfTrustUpdater webOfTrustUpdater;
150 /** Locked local Sones. */
151 /* synchronize on itself. */
152 private final Set<Sone> lockedSones = new HashSet<>();
154 /** Sone inserters. */
155 /* synchronize access on this on sones. */
156 private final Map<Sone, SoneInserter> soneInserters = new HashMap<>();
158 /** Sone rescuers. */
159 /* synchronize access on this on sones. */
160 private final Map<Sone, SoneRescuer> soneRescuers = new HashMap<>();
162 /** All known Sones. */
163 private final Set<String> knownSones = new HashSet<>();
165 /** The post database. */
166 private final Database database;
168 /** Trusted identities, sorted by own identities. */
169 private final Multimap<OwnIdentity, Identity> trustedIdentities = Multimaps.synchronizedSetMultimap(HashMultimap.<OwnIdentity, Identity>create());
171 /** All temporary images. */
172 private final Map<String, TemporaryImage> temporaryImages = new HashMap<>();
174 /** Ticker for threads that mark own elements as known. */
175 private final ScheduledExecutorService localElementTicker = Executors.newScheduledThreadPool(1);
177 /** The time the configuration was last touched. */
178 private volatile long lastConfigurationUpdate;
180 private final MetricRegistry metricRegistry;
181 private final Histogram configurationSaveTimeHistogram;
184 public Core(Configuration configuration, FreenetInterface freenetInterface, IdentityManager identityManager, SoneDownloader soneDownloader, ImageInserter imageInserter, UpdateChecker updateChecker, WebOfTrustUpdater webOfTrustUpdater, EventBus eventBus, Database database, MetricRegistry metricRegistry) {
186 this.configuration = configuration;
187 this.freenetInterface = freenetInterface;
188 this.identityManager = identityManager;
189 this.soneDownloader = soneDownloader;
190 this.imageInserter = imageInserter;
191 this.updateChecker = updateChecker;
192 this.webOfTrustUpdater = webOfTrustUpdater;
193 this.eventBus = eventBus;
194 this.database = database;
195 this.metricRegistry = metricRegistry;
196 preferences = new Preferences(eventBus);
197 this.configurationSaveTimeHistogram = metricRegistry.histogram("configuration.save.duration", () -> new Histogram(new ExponentiallyDecayingReservoir(3000, 0)));
205 * Returns the time Sone was started.
207 * @return The startup time (in milliseconds since Jan 1, 1970 UTC)
209 public long getStartupTime() {
214 public boolean getDebug() {
218 public void setDebug() {
220 eventBus.post(new DebugActivatedEvent());
224 * Returns the options used by the core.
226 * @return The options of the core
228 public Preferences getPreferences() {
233 * Returns the identity manager used by the core.
235 * @return The identity manager
237 public IdentityManager getIdentityManager() {
238 return identityManager;
242 * Returns the update checker.
244 * @return The update checker
246 public UpdateChecker getUpdateChecker() {
247 return updateChecker;
251 * Returns the Sone rescuer for the given local Sone.
254 * The local Sone to get the rescuer for
255 * @return The Sone rescuer for the given Sone
257 public SoneRescuer getSoneRescuer(Sone sone) {
258 checkNotNull(sone, "sone must not be null");
259 checkArgument(sone.isLocal(), "sone must be local");
260 synchronized (soneRescuers) {
261 SoneRescuer soneRescuer = soneRescuers.get(sone);
262 if (soneRescuer == null) {
263 soneRescuer = new SoneRescuer(this, soneDownloader, sone);
264 soneRescuers.put(sone, soneRescuer);
272 * Returns whether the given Sone is currently locked.
276 * @return {@code true} if the Sone is locked, {@code false} if it is not
278 public boolean isLocked(Sone sone) {
279 synchronized (lockedSones) {
280 return lockedSones.contains(sone);
284 public SoneBuilder soneBuilder() {
285 return database.newSoneBuilder();
293 public Collection<Sone> getSones() {
294 return database.getSones();
299 public Function1<String, Sone> getSoneLoader() {
300 return database.getSoneLoader();
304 * Returns the Sone with the given ID, regardless whether it’s local or
308 * The ID of the Sone to get
309 * @return The Sone with the given ID, or {@code null} if there is no such
314 public Sone getSone(@Nonnull String id) {
315 return database.getSone(id);
322 public Collection<Sone> getLocalSones() {
323 return database.getLocalSones();
327 * Returns the local Sone with the given ID, optionally creating a new Sone.
331 * @return The Sone with the given ID, or {@code null}
333 public Sone getLocalSone(String id) {
334 Sone sone = database.getSone(id);
335 if ((sone != null) && sone.isLocal()) {
345 public Collection<Sone> getRemoteSones() {
346 return database.getRemoteSones();
350 * Returns the remote Sone with the given ID.
354 * The ID of the remote Sone to get
355 * @return The Sone with the given ID
357 public Sone getRemoteSone(String id) {
358 return database.getSone(id);
362 * Returns whether the given Sone has been modified.
365 * The Sone to check for modifications
366 * @return {@code true} if a modification has been detected in the Sone,
367 * {@code false} otherwise
369 public boolean isModifiedSone(Sone sone) {
370 return soneInserters.containsKey(sone) && soneInserters.get(sone).isModified();
374 * Returns a post builder.
376 * @return A new post builder
378 public PostBuilder postBuilder() {
379 return database.newPostBuilder();
384 public Post getPost(@Nonnull String postId) {
385 return database.getPost(postId);
392 public Collection<Post> getPosts(String soneId) {
393 return database.getPosts(soneId);
400 public Collection<Post> getDirectedPosts(final String recipientId) {
401 checkNotNull(recipientId, "recipient must not be null");
402 return database.getDirectedPosts(recipientId);
406 * Returns a post reply builder.
408 * @return A new post reply builder
410 public PostReplyBuilder postReplyBuilder() {
411 return database.newPostReplyBuilder();
419 public PostReply getPostReply(String replyId) {
420 return database.getPostReply(replyId);
427 public List<PostReply> getReplies(final String postId) {
428 return database.getReplies(postId);
432 * Returns all Sones that have liked the given post.
435 * The post to get the liking Sones for
436 * @return The Sones that like the given post
438 public Set<Sone> getLikes(Post post) {
439 Set<Sone> sones = new HashSet<>();
440 for (Sone sone : getSones()) {
441 if (sone.getLikedPostIds().contains(post.getId())) {
449 * Returns all Sones that have liked the given reply.
452 * The reply to get the liking Sones for
453 * @return The Sones that like the given reply
455 public Set<Sone> getLikes(PostReply reply) {
456 Set<Sone> sones = new HashSet<>();
457 for (Sone sone : getSones()) {
458 if (sone.getLikedReplyIds().contains(reply.getId())) {
466 * Returns whether the given post is bookmarked.
470 * @return {@code true} if the given post is bookmarked, {@code false}
473 public boolean isBookmarked(Post post) {
474 return database.isPostBookmarked(post);
478 * Returns all currently known bookmarked posts.
480 * @return All bookmarked posts
482 public Set<Post> getBookmarkedPosts() {
483 return database.getBookmarkedPosts();
486 public AlbumBuilder albumBuilder() {
487 return database.newAlbumBuilder();
491 * Returns the album with the given ID, optionally creating a new album if
492 * an album with the given ID can not be found.
495 * The ID of the album
496 * @return The album with the given ID, or {@code null} if no album with the
500 public Album getAlbum(@Nonnull String albumId) {
501 return database.getAlbum(albumId);
504 public ImageBuilder imageBuilder() {
505 return database.newImageBuilder();
509 * Returns the image with the given ID, creating it if necessary.
512 * The ID of the image
513 * @return The image with the given ID
516 public Image getImage(String imageId) {
517 return getImage(imageId, true);
521 * Returns the image with the given ID, optionally creating it if it does
525 * The ID of the image
527 * {@code true} to create an image if none exists with the given
529 * @return The image with the given ID, or {@code null} if none exists and
533 public Image getImage(String imageId, boolean create) {
534 Image image = database.getImage(imageId);
541 Image newImage = database.newImageBuilder().withId(imageId).build();
542 database.storeImage(newImage);
547 * Returns the temporary image with the given ID.
550 * The ID of the temporary image
551 * @return The temporary image, or {@code null} if there is no temporary
552 * image with the given ID
554 public TemporaryImage getTemporaryImage(String imageId) {
555 synchronized (temporaryImages) {
556 return temporaryImages.get(imageId);
565 * Locks the given Sone. A locked Sone will not be inserted by
566 * {@link SoneInserter} until it is {@link #unlockSone(Sone) unlocked}
572 public void lockSone(Sone sone) {
573 synchronized (lockedSones) {
574 if (lockedSones.add(sone)) {
575 eventBus.post(new SoneLockedEvent(sone));
581 * Unlocks the given Sone.
583 * @see #lockSone(Sone)
587 public void unlockSone(Sone sone) {
588 synchronized (lockedSones) {
589 if (lockedSones.remove(sone)) {
590 eventBus.post(new SoneUnlockedEvent(sone));
596 * Adds a local Sone from the given own identity.
599 * The own identity to create a Sone from
600 * @return The added (or already existing) Sone
602 public Sone addLocalSone(OwnIdentity ownIdentity) {
603 if (ownIdentity == null) {
604 logger.log(Level.WARNING, "Given OwnIdentity is null!");
607 logger.info(String.format("Adding Sone from OwnIdentity: %s", ownIdentity));
608 Sone sone = database.newSoneBuilder().local().from(ownIdentity).build();
609 String property = fromNullable(ownIdentity.getProperty("Sone.LatestEdition")).or("0");
610 sone.setLatestEdition(fromNullable(tryParse(property)).or(0L));
611 sone.setClient(new Client("Sone", SonePlugin.getPluginVersion()));
613 SoneInserter soneInserter = new SoneInserter(this, eventBus, freenetInterface, metricRegistry, ownIdentity.getId());
614 soneInserter.insertionDelayChanged(new InsertionDelayChangedEvent(preferences.getInsertionDelay()));
615 eventBus.register(soneInserter);
616 synchronized (soneInserters) {
617 soneInserters.put(sone, soneInserter);
620 database.storeSone(sone);
621 sone.setStatus(SoneStatus.idle);
622 if (sone.getPosts().isEmpty() && sone.getReplies().isEmpty() && getAllImages(sone.getRootAlbum()).isEmpty()) {
625 eventBus.post(new SoneLockedOnStartup(sone));
627 soneInserter.start();
632 * Creates a new Sone for the given own identity.
635 * The own identity to create a Sone for
636 * @return The created Sone
638 public Sone createSone(OwnIdentity ownIdentity) {
639 if (!webOfTrustUpdater.addContextWait(ownIdentity, "Sone")) {
640 logger.log(Level.SEVERE, String.format("Could not add “Sone” context to own identity: %s", ownIdentity));
643 Sone sone = addLocalSone(ownIdentity);
645 followSone(sone, "nwa8lHa271k2QvJ8aa0Ov7IHAV-DFOCFgmDt3X6BpCI");
646 touchConfiguration();
651 * Adds the Sone of the given identity.
654 * The identity whose Sone to add
655 * @return The added or already existing Sone
657 public Sone addRemoteSone(Identity identity) {
658 if (identity == null) {
659 logger.log(Level.WARNING, "Given Identity is null!");
662 String property = fromNullable(identity.getProperty("Sone.LatestEdition")).or("0");
663 long latestEdition = fromNullable(tryParse(property)).or(0L);
664 Sone existingSone = getSone(identity.getId());
665 if ((existingSone != null )&& existingSone.isLocal()) {
668 boolean newSone = existingSone == null;
669 Sone sone = !newSone ? existingSone : database.newSoneBuilder().from(identity).build();
670 sone.setLatestEdition(latestEdition);
672 synchronized (knownSones) {
673 newSone = !knownSones.contains(sone.getId());
675 sone.setKnown(!newSone);
677 eventBus.post(new NewSoneFoundEvent(sone));
678 for (Sone localSone : getLocalSones()) {
679 if (localSone.getOptions().isAutoFollow()) {
680 followSone(localSone, sone.getId());
685 database.storeSone(sone);
686 soneDownloader.addSone(sone);
687 soneDownloaders.execute(soneDownloader.fetchSoneAsUskAction(sone));
692 * Lets the given local Sone follow the Sone with the given ID.
695 * The local Sone that should follow another Sone
697 * The ID of the Sone to follow
699 public void followSone(Sone sone, String soneId) {
700 checkNotNull(sone, "sone must not be null");
701 checkNotNull(soneId, "soneId must not be null");
702 database.addFriend(sone, soneId);
703 @SuppressWarnings("ConstantConditions") // we just followed, this can’t be null.
704 long now = database.getFollowingTime(soneId);
705 Sone followedSone = getSone(soneId);
706 if (followedSone == null) {
709 for (Post post : followedSone.getPosts()) {
710 if (post.getTime() < now) {
714 for (PostReply reply : followedSone.getReplies()) {
715 if (reply.getTime() < now) {
716 markReplyKnown(reply);
719 touchConfiguration();
723 * Lets the given local Sone unfollow the Sone with the given ID.
726 * The local Sone that should unfollow another Sone
728 * The ID of the Sone being unfollowed
730 public void unfollowSone(Sone sone, String soneId) {
731 checkNotNull(sone, "sone must not be null");
732 checkNotNull(soneId, "soneId must not be null");
733 database.removeFriend(sone, soneId);
734 touchConfiguration();
738 * Updates the stored Sone with the given Sone.
743 public void updateSone(Sone sone) {
744 updateSone(sone, false);
748 * Updates the stored Sone with the given Sone. If {@code soneRescueMode} is
749 * {@code true}, an older Sone than the current Sone can be given to restore
754 * @param soneRescueMode
755 * {@code true} if the stored Sone should be updated regardless
756 * of the age of the given Sone
758 public void updateSone(final Sone sone, boolean soneRescueMode) {
759 Sone storedSone = getSone(sone.getId());
760 if (storedSone != null) {
761 if (!soneRescueMode && !(sone.getTime() > storedSone.getTime())) {
762 logger.log(Level.FINE, String.format("Downloaded Sone %s is not newer than stored Sone %s.", sone, storedSone));
765 List<Object> events =
766 collectEventsForChangesInSone(storedSone, sone);
767 database.storeSone(sone);
768 for (Object event : events) {
769 eventBus.post(event);
771 sone.setOptions(storedSone.getOptions());
772 sone.setKnown(storedSone.isKnown());
773 sone.setStatus((sone.getTime() == 0) ? SoneStatus.unknown : SoneStatus.idle);
774 if (sone.isLocal()) {
775 touchConfiguration();
780 private List<Object> collectEventsForChangesInSone(Sone oldSone, Sone newSone) {
781 List<Object> events = new ArrayList<>();
782 SoneComparison soneComparison = new SoneComparison(oldSone, newSone);
783 for (Post newPost : soneComparison.getNewPosts()) {
784 if (newPost.getSone().equals(newSone)) {
785 newPost.setKnown(true);
786 } else if (newPost.getTime() < database.getFollowingTime(newSone.getId())) {
787 newPost.setKnown(true);
788 } else if (!newPost.isKnown()) {
789 events.add(new NewPostFoundEvent(newPost));
792 for (Post post : soneComparison.getRemovedPosts()) {
793 events.add(new PostRemovedEvent(post));
795 for (PostReply postReply : soneComparison.getNewPostReplies()) {
796 if (postReply.getSone().equals(newSone)) {
797 postReply.setKnown(true);
798 } else if (postReply.getTime() < database.getFollowingTime(newSone.getId())) {
799 postReply.setKnown(true);
800 } else if (!postReply.isKnown()) {
801 events.add(new NewPostReplyFoundEvent(postReply));
804 for (PostReply postReply : soneComparison.getRemovedPostReplies()) {
805 events.add(new PostReplyRemovedEvent(postReply));
811 * Deletes the given Sone. This will remove the Sone from the
812 * {@link #getLocalSones() local Sones}, stop its {@link SoneInserter} and
813 * remove the context from its identity.
818 public void deleteSone(Sone sone) {
819 if (!(sone.getIdentity() instanceof OwnIdentity)) {
820 logger.log(Level.WARNING, String.format("Tried to delete Sone of non-own identity: %s", sone));
823 if (!getLocalSones().contains(sone)) {
824 logger.log(Level.WARNING, String.format("Tried to delete non-local Sone: %s", sone));
827 SoneInserter soneInserter = soneInserters.remove(sone);
829 database.removeSone(sone);
830 webOfTrustUpdater.removeContext((OwnIdentity) sone.getIdentity(), "Sone");
831 webOfTrustUpdater.removeProperty((OwnIdentity) sone.getIdentity(), "Sone.LatestEdition");
833 configuration.getLongValue("Sone/" + sone.getId() + "/Time").setValue(null);
834 } catch (ConfigurationException ce1) {
835 logger.log(Level.WARNING, "Could not remove Sone from configuration!", ce1);
840 * Marks the given Sone as known. If the Sone was not {@link Post#isKnown()
841 * known} before, a {@link MarkSoneKnownEvent} is fired.
844 * The Sone to mark as known
846 public void markSoneKnown(Sone sone) {
847 if (!sone.isKnown()) {
849 synchronized (knownSones) {
850 knownSones.add(sone.getId());
852 eventBus.post(new MarkSoneKnownEvent(sone));
853 touchConfiguration();
858 * Loads and updates the given Sone from the configuration. If any error is
859 * encountered, loading is aborted and the given Sone is not changed.
862 * The Sone to load and update
864 public void loadSone(Sone sone) {
865 if (!sone.isLocal()) {
866 logger.log(Level.FINE, String.format("Tried to load non-local Sone: %s", sone));
869 logger.info(String.format("Loading local Sone: %s", sone));
872 String sonePrefix = "Sone/" + sone.getId();
873 Long soneTime = configuration.getLongValue(sonePrefix + "/Time").getValue(null);
874 if (soneTime == null) {
875 logger.log(Level.INFO, "Could not load Sone because no Sone has been saved.");
878 String lastInsertFingerprint = configuration.getStringValue(sonePrefix + "/LastInsertFingerprint").getValue("");
881 ConfigurationSoneParser configurationSoneParser = new ConfigurationSoneParser(configuration, sone);
882 Profile profile = configurationSoneParser.parseProfile();
885 Collection<Post> posts;
887 posts = configurationSoneParser.parsePosts(database);
888 } catch (InvalidPostFound ipf) {
889 logger.log(Level.WARNING, "Invalid post found, aborting load!");
894 Collection<PostReply> replies;
896 replies = configurationSoneParser.parsePostReplies(database);
897 } catch (InvalidPostReplyFound iprf) {
898 logger.log(Level.WARNING, "Invalid reply found, aborting load!");
902 /* load post likes. */
903 Set<String> likedPostIds =
904 configurationSoneParser.parseLikedPostIds();
906 /* load reply likes. */
907 Set<String> likedReplyIds =
908 configurationSoneParser.parseLikedPostReplyIds();
911 List<Album> topLevelAlbums;
914 configurationSoneParser.parseTopLevelAlbums(database);
915 } catch (InvalidAlbumFound iaf) {
916 logger.log(Level.WARNING, "Invalid album found, aborting load!");
918 } catch (InvalidParentAlbumFound ipaf) {
919 logger.log(Level.WARNING, format("Invalid parent album ID: %s",
920 ipaf.getAlbumParentId()));
926 configurationSoneParser.parseImages(database);
927 } catch (InvalidImageFound iif) {
928 logger.log(WARNING, "Invalid image found, aborting load!");
930 } catch (InvalidParentAlbumFound ipaf) {
931 logger.log(Level.WARNING,
932 format("Invalid album image (%s) encountered, aborting load!",
933 ipaf.getAlbumParentId()));
938 String avatarId = configuration.getStringValue(sonePrefix + "/Profile/Avatar").getValue(null);
939 if (avatarId != null) {
940 final Map<String, Image> images =
941 configurationSoneParser.getImages();
942 profile.setAvatar(images.get(avatarId));
946 sone.getOptions().setAutoFollow(configuration.getBooleanValue(sonePrefix + "/Options/AutoFollow").getValue(false));
947 sone.getOptions().setSoneInsertNotificationEnabled(configuration.getBooleanValue(sonePrefix + "/Options/EnableSoneInsertNotifications").getValue(false));
948 sone.getOptions().setShowNewSoneNotifications(configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewSones").getValue(true));
949 sone.getOptions().setShowNewPostNotifications(configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewPosts").getValue(true));
950 sone.getOptions().setShowNewReplyNotifications(configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewReplies").getValue(true));
951 sone.getOptions().setShowCustomAvatars(LoadExternalContent.valueOf(configuration.getStringValue(sonePrefix + "/Options/ShowCustomAvatars").getValue(LoadExternalContent.NEVER.name())));
952 sone.getOptions().setLoadLinkedImages(LoadExternalContent.valueOf(configuration.getStringValue(sonePrefix + "/Options/LoadLinkedImages").getValue(LoadExternalContent.NEVER.name())));
954 /* if we’re still here, Sone was loaded successfully. */
955 synchronized (sone) {
956 sone.setTime(soneTime);
957 sone.setProfile(profile);
958 sone.setPosts(posts);
959 sone.setReplies(replies);
960 sone.setLikePostIds(likedPostIds);
961 sone.setLikeReplyIds(likedReplyIds);
962 for (Album album : sone.getRootAlbum().getAlbums()) {
963 sone.getRootAlbum().removeAlbum(album);
965 for (Album album : topLevelAlbums) {
966 sone.getRootAlbum().addAlbum(album);
968 synchronized (soneInserters) {
969 soneInserters.get(sone).setLastInsertFingerprint(lastInsertFingerprint);
972 for (Post post : posts) {
975 for (PostReply reply : replies) {
976 reply.setKnown(true);
979 logger.info(String.format("Sone loaded successfully: %s", sone));
983 * Creates a new post.
986 * The Sone that creates the post
988 * The recipient Sone, or {@code null} if this post does not have
991 * The text of the post
992 * @return The created post
994 public Post createPost(Sone sone, @Nullable Sone recipient, String text) {
995 checkNotNull(text, "text must not be null");
996 checkArgument(text.trim().length() > 0, "text must not be empty");
997 if (!sone.isLocal()) {
998 logger.log(Level.FINE, String.format("Tried to create post for non-local Sone: %s", sone));
1001 PostBuilder postBuilder = database.newPostBuilder();
1002 postBuilder.from(sone.getId()).randomId().currentTime().withText(text.trim());
1003 if (recipient != null) {
1004 postBuilder.to(recipient.getId());
1006 final Post post = postBuilder.build();
1007 database.storePost(post);
1008 eventBus.post(new NewPostFoundEvent(post));
1010 touchConfiguration();
1011 localElementTicker.schedule(new MarkPostKnown(post), 10, TimeUnit.SECONDS);
1016 * Deletes the given post.
1019 * The post to delete
1021 public void deletePost(Post post) {
1022 if (!post.getSone().isLocal()) {
1023 logger.log(Level.WARNING, String.format("Tried to delete post of non-local Sone: %s", post.getSone()));
1026 database.removePost(post);
1027 eventBus.post(new PostRemovedEvent(post));
1028 markPostKnown(post);
1029 touchConfiguration();
1033 * Marks the given post as known, if it is currently not a known post
1034 * (according to {@link Post#isKnown()}).
1037 * The post to mark as known
1039 public void markPostKnown(Post post) {
1040 post.setKnown(true);
1041 eventBus.post(new MarkPostKnownEvent(post));
1042 touchConfiguration();
1043 for (PostReply reply : getReplies(post.getId())) {
1044 markReplyKnown(reply);
1048 public void bookmarkPost(Post post) {
1049 database.bookmarkPost(post);
1053 * Removes the given post from the bookmarks.
1056 * The post to unbookmark
1058 public void unbookmarkPost(Post post) {
1059 database.unbookmarkPost(post);
1063 * Creates a new reply.
1066 * The Sone that creates the reply
1068 * The post that this reply refers to
1070 * The text of the reply
1071 * @return The created reply
1073 public PostReply createReply(Sone sone, Post post, String text) {
1074 checkNotNull(text, "text must not be null");
1075 checkArgument(text.trim().length() > 0, "text must not be empty");
1076 if (!sone.isLocal()) {
1077 logger.log(Level.FINE, String.format("Tried to create reply for non-local Sone: %s", sone));
1080 PostReplyBuilder postReplyBuilder = postReplyBuilder();
1081 postReplyBuilder.randomId().from(sone.getId()).to(post.getId()).currentTime().withText(text.trim());
1082 final PostReply reply = postReplyBuilder.build();
1083 database.storePostReply(reply);
1084 eventBus.post(new NewPostReplyFoundEvent(reply));
1085 sone.addReply(reply);
1086 touchConfiguration();
1087 localElementTicker.schedule(new MarkReplyKnown(reply), 10, TimeUnit.SECONDS);
1092 * Deletes the given reply.
1095 * The reply to delete
1097 public void deleteReply(PostReply reply) {
1098 Sone sone = reply.getSone();
1099 if (!sone.isLocal()) {
1100 logger.log(Level.FINE, String.format("Tried to delete non-local reply: %s", reply));
1103 database.removePostReply(reply);
1104 markReplyKnown(reply);
1105 sone.removeReply(reply);
1106 touchConfiguration();
1110 * Marks the given reply as known, if it is currently not a known reply
1111 * (according to {@link Reply#isKnown()}).
1114 * The reply to mark as known
1116 public void markReplyKnown(PostReply reply) {
1117 boolean previouslyKnown = reply.isKnown();
1118 reply.setKnown(true);
1119 eventBus.post(new MarkPostReplyKnownEvent(reply));
1120 if (!previouslyKnown) {
1121 touchConfiguration();
1126 * Creates a new album for the given Sone.
1129 * The Sone to create the album for
1131 * The parent of the album (may be {@code null} to create a
1133 * @return The new album
1135 public Album createAlbum(Sone sone, Album parent) {
1136 Album album = database.newAlbumBuilder().randomId().by(sone).build();
1137 database.storeAlbum(album);
1138 parent.addAlbum(album);
1143 * Deletes the given album. The owner of the album has to be a local Sone,
1144 * and the album has to be {@link Album#isEmpty() empty} to be deleted.
1147 * The album to remove
1149 public void deleteAlbum(Album album) {
1150 checkNotNull(album, "album must not be null");
1151 checkArgument(album.getSone().isLocal(), "album’s Sone must be a local Sone");
1152 if (!album.isEmpty()) {
1155 album.getParent().removeAlbum(album);
1156 database.removeAlbum(album);
1157 touchConfiguration();
1161 * Creates a new image.
1164 * The Sone creating the image
1166 * The album the image will be inserted into
1167 * @param temporaryImage
1168 * The temporary image to create the image from
1169 * @return The newly created image
1171 public Image createImage(Sone sone, Album album, TemporaryImage temporaryImage) {
1172 checkNotNull(sone, "sone must not be null");
1173 checkNotNull(album, "album must not be null");
1174 checkNotNull(temporaryImage, "temporaryImage must not be null");
1175 checkArgument(sone.isLocal(), "sone must be a local Sone");
1176 checkArgument(sone.equals(album.getSone()), "album must belong to the given Sone");
1177 Image image = database.newImageBuilder().withId(temporaryImage.getId()).build().modify().setSone(sone).setCreationTime(System.currentTimeMillis()).update();
1178 album.addImage(image);
1179 database.storeImage(image);
1180 imageInserter.insertImage(temporaryImage, image);
1185 * Deletes the given image. This method will also delete a matching
1188 * @see #deleteTemporaryImage(String)
1190 * The image to delete
1192 public void deleteImage(Image image) {
1193 checkNotNull(image, "image must not be null");
1194 checkArgument(image.getSone().isLocal(), "image must belong to a local Sone");
1195 deleteTemporaryImage(image.getId());
1196 image.getAlbum().removeImage(image);
1197 database.removeImage(image);
1198 touchConfiguration();
1202 * Creates a new temporary image.
1205 * The MIME type of the temporary image
1207 * The encoded data of the image
1208 * @return The temporary image
1210 public TemporaryImage createTemporaryImage(String mimeType, byte[] imageData) {
1211 TemporaryImage temporaryImage = new TemporaryImage();
1212 temporaryImage.setMimeType(mimeType).setImageData(imageData);
1213 synchronized (temporaryImages) {
1214 temporaryImages.put(temporaryImage.getId(), temporaryImage);
1216 return temporaryImage;
1220 * Deletes the temporary image with the given ID.
1223 * The ID of the temporary image to delete
1225 public void deleteTemporaryImage(String imageId) {
1226 checkNotNull(imageId, "imageId must not be null");
1227 synchronized (temporaryImages) {
1228 temporaryImages.remove(imageId);
1230 Image image = getImage(imageId, false);
1231 if (image != null) {
1232 imageInserter.cancelImageInsert(image);
1237 * Notifies the core that the configuration, either of the core or of a
1238 * single local Sone, has changed, and that the configuration should be
1241 public void touchConfiguration() {
1242 lastConfigurationUpdate = System.currentTimeMillis();
1253 public void serviceStart() {
1254 loadConfiguration();
1255 updateChecker.start();
1256 identityManager.start();
1257 webOfTrustUpdater.init();
1258 webOfTrustUpdater.start();
1259 database.startAsync();
1266 public void serviceRun() {
1267 long lastSaved = System.currentTimeMillis();
1268 while (!shouldStop()) {
1270 long now = System.currentTimeMillis();
1271 if (shouldStop() || ((lastConfigurationUpdate > lastSaved) && ((now - lastConfigurationUpdate) > 5000))) {
1272 for (Sone localSone : getLocalSones()) {
1273 saveSone(localSone);
1275 saveConfiguration();
1285 public void serviceStop() {
1286 localElementTicker.shutdownNow();
1287 synchronized (soneInserters) {
1288 for (Entry<Sone, SoneInserter> soneInserter : soneInserters.entrySet()) {
1289 soneInserter.getValue().stop();
1290 Sone latestSone = getLocalSone(soneInserter.getKey().getId());
1291 saveSone(latestSone);
1294 synchronized (soneRescuers) {
1295 for (SoneRescuer soneRescuer : soneRescuers.values()) {
1299 saveConfiguration();
1300 database.stopAsync();
1301 webOfTrustUpdater.stop();
1302 updateChecker.stop();
1303 soneDownloader.stop();
1304 soneDownloaders.shutdown();
1305 identityManager.stop();
1313 * Saves the given Sone. This will persist all local settings for the given
1314 * Sone, such as the friends list and similar, private options.
1319 private synchronized void saveSone(Sone sone) {
1320 if (!sone.isLocal()) {
1321 logger.log(Level.FINE, String.format("Tried to save non-local Sone: %s", sone));
1324 if (!(sone.getIdentity() instanceof OwnIdentity)) {
1325 logger.log(Level.WARNING, String.format("Local Sone without OwnIdentity found, refusing to save: %s", sone));
1329 logger.log(Level.INFO, String.format("Saving Sone: %s", sone));
1331 /* save Sone into configuration. */
1332 String sonePrefix = "Sone/" + sone.getId();
1333 configuration.getLongValue(sonePrefix + "/Time").setValue(sone.getTime());
1334 configuration.getStringValue(sonePrefix + "/LastInsertFingerprint").setValue(soneInserters.get(sone).getLastInsertFingerprint());
1337 Profile profile = sone.getProfile();
1338 configuration.getStringValue(sonePrefix + "/Profile/FirstName").setValue(profile.getFirstName());
1339 configuration.getStringValue(sonePrefix + "/Profile/MiddleName").setValue(profile.getMiddleName());
1340 configuration.getStringValue(sonePrefix + "/Profile/LastName").setValue(profile.getLastName());
1341 configuration.getIntValue(sonePrefix + "/Profile/BirthDay").setValue(profile.getBirthDay());
1342 configuration.getIntValue(sonePrefix + "/Profile/BirthMonth").setValue(profile.getBirthMonth());
1343 configuration.getIntValue(sonePrefix + "/Profile/BirthYear").setValue(profile.getBirthYear());
1344 configuration.getStringValue(sonePrefix + "/Profile/Avatar").setValue(profile.getAvatar());
1346 /* save profile fields. */
1347 int fieldCounter = 0;
1348 for (Field profileField : profile.getFields()) {
1349 String fieldPrefix = sonePrefix + "/Profile/Fields/" + fieldCounter++;
1350 configuration.getStringValue(fieldPrefix + "/Name").setValue(profileField.getName());
1351 configuration.getStringValue(fieldPrefix + "/Value").setValue(profileField.getValue());
1353 configuration.getStringValue(sonePrefix + "/Profile/Fields/" + fieldCounter + "/Name").setValue(null);
1356 int postCounter = 0;
1357 for (Post post : sone.getPosts()) {
1358 String postPrefix = sonePrefix + "/Posts/" + postCounter++;
1359 configuration.getStringValue(postPrefix + "/ID").setValue(post.getId());
1360 configuration.getStringValue(postPrefix + "/Recipient").setValue(post.getRecipientId().orNull());
1361 configuration.getLongValue(postPrefix + "/Time").setValue(post.getTime());
1362 configuration.getStringValue(postPrefix + "/Text").setValue(post.getText());
1364 configuration.getStringValue(sonePrefix + "/Posts/" + postCounter + "/ID").setValue(null);
1367 int replyCounter = 0;
1368 for (PostReply reply : sone.getReplies()) {
1369 String replyPrefix = sonePrefix + "/Replies/" + replyCounter++;
1370 configuration.getStringValue(replyPrefix + "/ID").setValue(reply.getId());
1371 configuration.getStringValue(replyPrefix + "/Post/ID").setValue(reply.getPostId());
1372 configuration.getLongValue(replyPrefix + "/Time").setValue(reply.getTime());
1373 configuration.getStringValue(replyPrefix + "/Text").setValue(reply.getText());
1375 configuration.getStringValue(sonePrefix + "/Replies/" + replyCounter + "/ID").setValue(null);
1377 /* save post likes. */
1378 int postLikeCounter = 0;
1379 for (String postId : sone.getLikedPostIds()) {
1380 configuration.getStringValue(sonePrefix + "/Likes/Post/" + postLikeCounter++ + "/ID").setValue(postId);
1382 configuration.getStringValue(sonePrefix + "/Likes/Post/" + postLikeCounter + "/ID").setValue(null);
1384 /* save reply likes. */
1385 int replyLikeCounter = 0;
1386 for (String replyId : sone.getLikedReplyIds()) {
1387 configuration.getStringValue(sonePrefix + "/Likes/Reply/" + replyLikeCounter++ + "/ID").setValue(replyId);
1389 configuration.getStringValue(sonePrefix + "/Likes/Reply/" + replyLikeCounter + "/ID").setValue(null);
1391 /* save albums. first, collect in a flat structure, top-level first. */
1392 List<Album> albums = FluentIterable.from(sone.getRootAlbum().getAlbums()).transformAndConcat(Album.FLATTENER).toList();
1394 int albumCounter = 0;
1395 for (Album album : albums) {
1396 String albumPrefix = sonePrefix + "/Albums/" + albumCounter++;
1397 configuration.getStringValue(albumPrefix + "/ID").setValue(album.getId());
1398 configuration.getStringValue(albumPrefix + "/Title").setValue(album.getTitle());
1399 configuration.getStringValue(albumPrefix + "/Description").setValue(album.getDescription());
1400 configuration.getStringValue(albumPrefix + "/Parent").setValue(album.getParent().equals(sone.getRootAlbum()) ? null : album.getParent().getId());
1402 configuration.getStringValue(sonePrefix + "/Albums/" + albumCounter + "/ID").setValue(null);
1405 int imageCounter = 0;
1406 for (Album album : albums) {
1407 for (Image image : album.getImages()) {
1408 if (!image.isInserted()) {
1411 String imagePrefix = sonePrefix + "/Images/" + imageCounter++;
1412 configuration.getStringValue(imagePrefix + "/ID").setValue(image.getId());
1413 configuration.getStringValue(imagePrefix + "/Album").setValue(album.getId());
1414 configuration.getStringValue(imagePrefix + "/Key").setValue(image.getKey());
1415 configuration.getStringValue(imagePrefix + "/Title").setValue(image.getTitle());
1416 configuration.getStringValue(imagePrefix + "/Description").setValue(image.getDescription());
1417 configuration.getLongValue(imagePrefix + "/CreationTime").setValue(image.getCreationTime());
1418 configuration.getIntValue(imagePrefix + "/Width").setValue(image.getWidth());
1419 configuration.getIntValue(imagePrefix + "/Height").setValue(image.getHeight());
1422 configuration.getStringValue(sonePrefix + "/Images/" + imageCounter + "/ID").setValue(null);
1425 configuration.getBooleanValue(sonePrefix + "/Options/AutoFollow").setValue(sone.getOptions().isAutoFollow());
1426 configuration.getBooleanValue(sonePrefix + "/Options/EnableSoneInsertNotifications").setValue(sone.getOptions().isSoneInsertNotificationEnabled());
1427 configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewSones").setValue(sone.getOptions().isShowNewSoneNotifications());
1428 configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewPosts").setValue(sone.getOptions().isShowNewPostNotifications());
1429 configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewReplies").setValue(sone.getOptions().isShowNewReplyNotifications());
1430 configuration.getStringValue(sonePrefix + "/Options/ShowCustomAvatars").setValue(sone.getOptions().getShowCustomAvatars().name());
1431 configuration.getStringValue(sonePrefix + "/Options/LoadLinkedImages").setValue(sone.getOptions().getLoadLinkedImages().name());
1433 webOfTrustUpdater.setProperty((OwnIdentity) sone.getIdentity(), "Sone.LatestEdition", String.valueOf(sone.getLatestEdition()));
1435 logger.log(Level.INFO, String.format("Sone %s saved.", sone));
1436 } catch (ConfigurationException ce1) {
1437 logger.log(Level.WARNING, String.format("Could not save Sone: %s", sone), ce1);
1442 * Saves the current options.
1444 private void saveConfiguration() {
1445 synchronized (configuration) {
1446 if (storingConfiguration) {
1447 logger.log(Level.FINE, "Already storing configuration…");
1450 storingConfiguration = true;
1453 /* store the options first. */
1455 preferences.saveTo(configuration);
1457 /* save known Sones. */
1458 int soneCounter = 0;
1459 synchronized (knownSones) {
1460 for (String knownSoneId : knownSones) {
1461 configuration.getStringValue("KnownSone/" + soneCounter++ + "/ID").setValue(knownSoneId);
1463 configuration.getStringValue("KnownSone/" + soneCounter + "/ID").setValue(null);
1466 /* save known posts. */
1470 Stopwatch stopwatch = Stopwatch.createStarted();
1471 configuration.save();
1472 configurationSaveTimeHistogram.update(stopwatch.elapsed(TimeUnit.MICROSECONDS));
1474 } catch (ConfigurationException ce1) {
1475 logger.log(Level.SEVERE, "Could not store configuration!", ce1);
1476 } catch (DatabaseException de1) {
1477 logger.log(Level.SEVERE, "Could not save database!", de1);
1479 synchronized (configuration) {
1480 storingConfiguration = false;
1486 * Loads the configuration.
1488 private void loadConfiguration() {
1489 new PreferencesLoader(preferences).loadFrom(configuration);
1491 /* load known Sones. */
1492 int soneCounter = 0;
1494 String knownSoneId = configuration.getStringValue("KnownSone/" + soneCounter++ + "/ID").getValue(null);
1495 if (knownSoneId == null) {
1498 synchronized (knownSones) {
1499 knownSones.add(knownSoneId);
1505 * Notifies the core that a new {@link OwnIdentity} was added.
1507 * @param ownIdentityAddedEvent
1511 public void ownIdentityAdded(OwnIdentityAddedEvent ownIdentityAddedEvent) {
1512 OwnIdentity ownIdentity = ownIdentityAddedEvent.getOwnIdentity();
1513 logger.log(Level.FINEST, String.format("Adding OwnIdentity: %s", ownIdentity));
1514 if (ownIdentity.hasContext("Sone")) {
1515 addLocalSone(ownIdentity);
1520 * Notifies the core that an {@link OwnIdentity} was removed.
1522 * @param ownIdentityRemovedEvent
1526 public void ownIdentityRemoved(OwnIdentityRemovedEvent ownIdentityRemovedEvent) {
1527 OwnIdentity ownIdentity = ownIdentityRemovedEvent.getOwnIdentity();
1528 logger.log(Level.FINEST, String.format("Removing OwnIdentity: %s", ownIdentity));
1529 trustedIdentities.removeAll(ownIdentity);
1533 * Notifies the core that a new {@link Identity} was added.
1535 * @param identityAddedEvent
1539 public void identityAdded(IdentityAddedEvent identityAddedEvent) {
1540 Identity identity = identityAddedEvent.getIdentity();
1541 logger.log(Level.FINEST, String.format("Adding Identity: %s", identity));
1542 trustedIdentities.put(identityAddedEvent.getOwnIdentity(), identity);
1543 addRemoteSone(identity);
1547 * Notifies the core that an {@link Identity} was updated.
1549 * @param identityUpdatedEvent
1553 public void identityUpdated(IdentityUpdatedEvent identityUpdatedEvent) {
1554 Identity identity = identityUpdatedEvent.getIdentity();
1555 final Sone sone = getRemoteSone(identity.getId());
1556 if (sone.isLocal()) {
1559 String newLatestEdition = identity.getProperty("Sone.LatestEdition");
1560 if (newLatestEdition != null) {
1561 Long parsedNewLatestEdition = tryParse(newLatestEdition);
1562 if (parsedNewLatestEdition != null) {
1563 sone.setLatestEdition(parsedNewLatestEdition);
1566 soneDownloader.addSone(sone);
1567 soneDownloaders.execute(soneDownloader.fetchSoneAsSskAction(sone));
1571 * Notifies the core that an {@link Identity} was removed.
1573 * @param identityRemovedEvent
1577 public void identityRemoved(IdentityRemovedEvent identityRemovedEvent) {
1578 OwnIdentity ownIdentity = identityRemovedEvent.getOwnIdentity();
1579 Identity identity = identityRemovedEvent.getIdentity();
1580 trustedIdentities.remove(ownIdentity, identity);
1581 for (Entry<OwnIdentity, Collection<Identity>> trustedIdentity : trustedIdentities.asMap().entrySet()) {
1582 if (trustedIdentity.getKey().equals(ownIdentity)) {
1585 if (trustedIdentity.getValue().contains(identity)) {
1589 Sone sone = getSone(identity.getId());
1591 /* TODO - we don’t have the Sone anymore. should this happen? */
1594 for (PostReply postReply : sone.getReplies()) {
1595 eventBus.post(new PostReplyRemovedEvent(postReply));
1597 for (Post post : sone.getPosts()) {
1598 eventBus.post(new PostRemovedEvent(post));
1600 eventBus.post(new SoneRemovedEvent(sone));
1601 database.removeSone(sone);
1605 * Deletes the temporary image.
1607 * @param imageInsertFinishedEvent
1611 public void imageInsertFinished(ImageInsertFinishedEvent imageInsertFinishedEvent) {
1612 logger.log(Level.WARNING, String.format("Image insert finished for %s: %s", imageInsertFinishedEvent.getImage(), imageInsertFinishedEvent.getResultingUri()));
1613 imageInsertFinishedEvent.getImage().modify().setKey(imageInsertFinishedEvent.getResultingUri().toString()).update();
1614 deleteTemporaryImage(imageInsertFinishedEvent.getImage().getId());
1615 touchConfiguration();
1619 class MarkPostKnown implements Runnable {
1621 private final Post post;
1623 public MarkPostKnown(Post post) {
1629 markPostKnown(post);
1635 class MarkReplyKnown implements Runnable {
1637 private final PostReply postReply;
1639 public MarkReplyKnown(PostReply postReply) {
1640 this.postReply = postReply;
1645 markReplyKnown(postReply);