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.AlbumKt.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.SoneKt;
66 import net.pterodactylus.sone.data.SoneOptions.LoadExternalContent;
67 import net.pterodactylus.sone.data.TemporaryImage;
68 import net.pterodactylus.sone.database.AlbumBuilder;
69 import net.pterodactylus.sone.database.Database;
70 import net.pterodactylus.sone.database.DatabaseException;
71 import net.pterodactylus.sone.database.ImageBuilder;
72 import net.pterodactylus.sone.database.PostBuilder;
73 import net.pterodactylus.sone.database.PostProvider;
74 import net.pterodactylus.sone.database.PostReplyBuilder;
75 import net.pterodactylus.sone.database.PostReplyProvider;
76 import net.pterodactylus.sone.database.SoneBuilder;
77 import net.pterodactylus.sone.database.SoneProvider;
78 import net.pterodactylus.sone.freenet.wot.Identity;
79 import net.pterodactylus.sone.freenet.wot.IdentityManager;
80 import net.pterodactylus.sone.freenet.wot.OwnIdentity;
81 import net.pterodactylus.sone.freenet.wot.event.IdentityAddedEvent;
82 import net.pterodactylus.sone.freenet.wot.event.IdentityRemovedEvent;
83 import net.pterodactylus.sone.freenet.wot.event.IdentityUpdatedEvent;
84 import net.pterodactylus.sone.freenet.wot.event.OwnIdentityAddedEvent;
85 import net.pterodactylus.sone.freenet.wot.event.OwnIdentityRemovedEvent;
86 import net.pterodactylus.sone.main.SonePlugin;
87 import net.pterodactylus.util.config.Configuration;
88 import net.pterodactylus.util.config.ConfigurationException;
89 import net.pterodactylus.util.service.AbstractService;
90 import net.pterodactylus.util.thread.NamedThreadFactory;
92 import com.google.common.annotations.VisibleForTesting;
93 import com.google.common.base.Stopwatch;
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;
183 private final SoneUriCreator soneUriCreator;
186 public Core(Configuration configuration, FreenetInterface freenetInterface, IdentityManager identityManager, SoneDownloader soneDownloader, ImageInserter imageInserter, UpdateChecker updateChecker, WebOfTrustUpdater webOfTrustUpdater, EventBus eventBus, Database database, MetricRegistry metricRegistry, SoneUriCreator soneUriCreator) {
188 this.configuration = configuration;
189 this.freenetInterface = freenetInterface;
190 this.identityManager = identityManager;
191 this.soneDownloader = soneDownloader;
192 this.imageInserter = imageInserter;
193 this.updateChecker = updateChecker;
194 this.webOfTrustUpdater = webOfTrustUpdater;
195 this.eventBus = eventBus;
196 this.database = database;
197 this.metricRegistry = metricRegistry;
198 this.soneUriCreator = soneUriCreator;
199 preferences = new Preferences(eventBus);
200 this.configurationSaveTimeHistogram = metricRegistry.histogram("configuration.save.duration", () -> new Histogram(new ExponentiallyDecayingReservoir(3000, 0)));
208 * Returns the time Sone was started.
210 * @return The startup time (in milliseconds since Jan 1, 1970 UTC)
212 public long getStartupTime() {
217 public boolean getDebug() {
221 public void setDebug() {
223 eventBus.post(new DebugActivatedEvent());
227 * Returns the options used by the core.
229 * @return The options of the core
231 public Preferences getPreferences() {
236 * Returns the identity manager used by the core.
238 * @return The identity manager
240 public IdentityManager getIdentityManager() {
241 return identityManager;
245 * Returns the update checker.
247 * @return The update checker
249 public UpdateChecker getUpdateChecker() {
250 return updateChecker;
254 * Returns the Sone rescuer for the given local Sone.
257 * The local Sone to get the rescuer for
258 * @return The Sone rescuer for the given Sone
260 public SoneRescuer getSoneRescuer(Sone sone) {
261 checkNotNull(sone, "sone must not be null");
262 checkArgument(sone.isLocal(), "sone must be local");
263 synchronized (soneRescuers) {
264 SoneRescuer soneRescuer = soneRescuers.get(sone);
265 if (soneRescuer == null) {
266 soneRescuer = new SoneRescuer(this, soneDownloader, sone);
267 soneRescuers.put(sone, soneRescuer);
275 * Returns whether the given Sone is currently locked.
279 * @return {@code true} if the Sone is locked, {@code false} if it is not
281 public boolean isLocked(Sone sone) {
282 synchronized (lockedSones) {
283 return lockedSones.contains(sone);
287 public SoneBuilder soneBuilder() {
288 return database.newSoneBuilder();
296 public Collection<Sone> getSones() {
297 return database.getSones();
302 public Function1<String, Sone> getSoneLoader() {
303 return database.getSoneLoader();
307 * Returns the Sone with the given ID, regardless whether it’s local or
311 * The ID of the Sone to get
312 * @return The Sone with the given ID, or {@code null} if there is no such
317 public Sone getSone(@Nonnull String id) {
318 return database.getSone(id);
325 public Collection<Sone> getLocalSones() {
326 return database.getLocalSones();
330 * Returns the local Sone with the given ID, optionally creating a new Sone.
334 * @return The Sone with the given ID, or {@code null}
336 public Sone getLocalSone(String id) {
337 Sone sone = database.getSone(id);
338 if ((sone != null) && sone.isLocal()) {
348 public Collection<Sone> getRemoteSones() {
349 return database.getRemoteSones();
353 * Returns the remote Sone with the given ID.
357 * The ID of the remote Sone to get
358 * @return The Sone with the given ID
360 public Sone getRemoteSone(String id) {
361 return database.getSone(id);
365 * Returns whether the given Sone has been modified.
368 * The Sone to check for modifications
369 * @return {@code true} if a modification has been detected in the Sone,
370 * {@code false} otherwise
372 public boolean isModifiedSone(Sone sone) {
373 return soneInserters.containsKey(sone) && soneInserters.get(sone).isModified();
377 * Returns a post builder.
379 * @return A new post builder
381 public PostBuilder postBuilder() {
382 return database.newPostBuilder();
387 public Post getPost(@Nonnull String postId) {
388 return database.getPost(postId);
395 public Collection<Post> getPosts(String soneId) {
396 return database.getPosts(soneId);
403 public Collection<Post> getDirectedPosts(final String recipientId) {
404 checkNotNull(recipientId, "recipient must not be null");
405 return database.getDirectedPosts(recipientId);
409 * Returns a post reply builder.
411 * @return A new post reply builder
413 public PostReplyBuilder postReplyBuilder() {
414 return database.newPostReplyBuilder();
422 public PostReply getPostReply(String replyId) {
423 return database.getPostReply(replyId);
430 public List<PostReply> getReplies(final String postId) {
431 return database.getReplies(postId);
435 * Returns all Sones that have liked the given post.
438 * The post to get the liking Sones for
439 * @return The Sones that like the given post
441 public Set<Sone> getLikes(Post post) {
442 Set<Sone> sones = new HashSet<>();
443 for (Sone sone : getSones()) {
444 if (sone.getLikedPostIds().contains(post.getId())) {
452 * Returns all Sones that have liked the given reply.
455 * The reply to get the liking Sones for
456 * @return The Sones that like the given reply
458 public Set<Sone> getLikes(PostReply reply) {
459 Set<Sone> sones = new HashSet<>();
460 for (Sone sone : getSones()) {
461 if (sone.getLikedReplyIds().contains(reply.getId())) {
469 * Returns whether the given post is bookmarked.
473 * @return {@code true} if the given post is bookmarked, {@code false}
476 public boolean isBookmarked(Post post) {
477 return database.isPostBookmarked(post);
481 * Returns all currently known bookmarked posts.
483 * @return All bookmarked posts
485 public Set<Post> getBookmarkedPosts() {
486 return database.getBookmarkedPosts();
489 public AlbumBuilder albumBuilder() {
490 return database.newAlbumBuilder();
494 * Returns the album with the given ID, optionally creating a new album if
495 * an album with the given ID can not be found.
498 * The ID of the album
499 * @return The album with the given ID, or {@code null} if no album with the
503 public Album getAlbum(@Nonnull String albumId) {
504 return database.getAlbum(albumId);
507 public ImageBuilder imageBuilder() {
508 return database.newImageBuilder();
512 * Returns the image with the given ID, creating it if necessary.
515 * The ID of the image
516 * @return The image with the given ID
519 public Image getImage(String imageId) {
520 return getImage(imageId, true);
524 * Returns the image with the given ID, optionally creating it if it does
528 * The ID of the image
530 * {@code true} to create an image if none exists with the given
532 * @return The image with the given ID, or {@code null} if none exists and
536 public Image getImage(String imageId, boolean create) {
537 Image image = database.getImage(imageId);
544 Image newImage = database.newImageBuilder().withId(imageId).build();
545 database.storeImage(newImage);
550 * Returns the temporary image with the given ID.
553 * The ID of the temporary image
554 * @return The temporary image, or {@code null} if there is no temporary
555 * image with the given ID
557 public TemporaryImage getTemporaryImage(String imageId) {
558 synchronized (temporaryImages) {
559 return temporaryImages.get(imageId);
568 * Locks the given Sone. A locked Sone will not be inserted by
569 * {@link SoneInserter} until it is {@link #unlockSone(Sone) unlocked}
575 public void lockSone(Sone sone) {
576 synchronized (lockedSones) {
577 if (lockedSones.add(sone)) {
578 eventBus.post(new SoneLockedEvent(sone));
584 * Unlocks the given Sone.
586 * @see #lockSone(Sone)
590 public void unlockSone(Sone sone) {
591 synchronized (lockedSones) {
592 if (lockedSones.remove(sone)) {
593 eventBus.post(new SoneUnlockedEvent(sone));
599 * Adds a local Sone from the given own identity.
602 * The own identity to create a Sone from
603 * @return The added (or already existing) Sone
605 public Sone addLocalSone(OwnIdentity ownIdentity) {
606 if (ownIdentity == null) {
607 logger.log(Level.WARNING, "Given OwnIdentity is null!");
610 logger.info(String.format("Adding Sone from OwnIdentity: %s", ownIdentity));
611 Sone sone = database.newSoneBuilder().local().from(ownIdentity).build();
612 String property = fromNullable(ownIdentity.getProperty("Sone.LatestEdition")).or("0");
613 sone.setLatestEdition(fromNullable(tryParse(property)).or(0L));
614 sone.setClient(new Client("Sone", SonePlugin.getPluginVersion()));
616 SoneInserter soneInserter = new SoneInserter(this, eventBus, freenetInterface, metricRegistry, soneUriCreator, ownIdentity.getId());
617 soneInserter.insertionDelayChanged(new InsertionDelayChangedEvent(preferences.getInsertionDelay()));
618 eventBus.register(soneInserter);
619 synchronized (soneInserters) {
620 soneInserters.put(sone, soneInserter);
623 database.storeSone(sone);
624 sone.setStatus(SoneStatus.idle);
625 if (sone.getPosts().isEmpty() && sone.getReplies().isEmpty() && getAllImages(sone.getRootAlbum()).isEmpty()) {
628 eventBus.post(new SoneLockedOnStartup(sone));
630 soneInserter.start();
635 * Creates a new Sone for the given own identity.
638 * The own identity to create a Sone for
639 * @return The created Sone
641 public Sone createSone(OwnIdentity ownIdentity) {
642 if (!webOfTrustUpdater.addContextWait(ownIdentity, "Sone")) {
643 logger.log(Level.SEVERE, String.format("Could not add “Sone” context to own identity: %s", ownIdentity));
646 Sone sone = addLocalSone(ownIdentity);
648 followSone(sone, "nwa8lHa271k2QvJ8aa0Ov7IHAV-DFOCFgmDt3X6BpCI");
649 touchConfiguration();
654 * Adds the Sone of the given identity.
657 * The identity whose Sone to add
658 * @return The added or already existing Sone
660 public Sone addRemoteSone(Identity identity) {
661 if (identity == null) {
662 logger.log(Level.WARNING, "Given Identity is null!");
665 String property = fromNullable(identity.getProperty("Sone.LatestEdition")).or("0");
666 long latestEdition = fromNullable(tryParse(property)).or(0L);
667 Sone existingSone = getSone(identity.getId());
668 if ((existingSone != null )&& existingSone.isLocal()) {
671 boolean newSone = existingSone == null;
672 Sone sone = !newSone ? existingSone : database.newSoneBuilder().from(identity).build();
673 sone.setLatestEdition(latestEdition);
675 synchronized (knownSones) {
676 newSone = !knownSones.contains(sone.getId());
678 sone.setKnown(!newSone);
680 eventBus.post(new NewSoneFoundEvent(sone));
681 for (Sone localSone : getLocalSones()) {
682 if (localSone.getOptions().isAutoFollow()) {
683 followSone(localSone, sone.getId());
688 database.storeSone(sone);
689 soneDownloader.addSone(sone);
690 soneDownloaders.execute(soneDownloader.fetchSoneAsUskAction(sone));
695 * Lets the given local Sone follow the Sone with the given ID.
698 * The local Sone that should follow another Sone
700 * The ID of the Sone to follow
702 public void followSone(Sone sone, String soneId) {
703 checkNotNull(sone, "sone must not be null");
704 checkNotNull(soneId, "soneId must not be null");
705 database.addFriend(sone, soneId);
706 @SuppressWarnings("ConstantConditions") // we just followed, this can’t be null.
707 long now = database.getFollowingTime(soneId);
708 Sone followedSone = getSone(soneId);
709 if (followedSone == null) {
712 for (Post post : followedSone.getPosts()) {
713 if (post.getTime() < now) {
717 for (PostReply reply : followedSone.getReplies()) {
718 if (reply.getTime() < now) {
719 markReplyKnown(reply);
722 touchConfiguration();
726 * Lets the given local Sone unfollow the Sone with the given ID.
729 * The local Sone that should unfollow another Sone
731 * The ID of the Sone being unfollowed
733 public void unfollowSone(Sone sone, String soneId) {
734 checkNotNull(sone, "sone must not be null");
735 checkNotNull(soneId, "soneId must not be null");
736 database.removeFriend(sone, soneId);
737 touchConfiguration();
741 * Updates the stored Sone with the given Sone.
746 public void updateSone(Sone sone) {
747 updateSone(sone, false);
751 * Updates the stored Sone with the given Sone. If {@code soneRescueMode} is
752 * {@code true}, an older Sone than the current Sone can be given to restore
757 * @param soneRescueMode
758 * {@code true} if the stored Sone should be updated regardless
759 * of the age of the given Sone
761 public void updateSone(final Sone sone, boolean soneRescueMode) {
762 Sone storedSone = getSone(sone.getId());
763 if (storedSone != null) {
764 if (!soneRescueMode && !(sone.getTime() > storedSone.getTime())) {
765 logger.log(Level.FINE, String.format("Downloaded Sone %s is not newer than stored Sone %s.", sone, storedSone));
768 List<Object> events =
769 collectEventsForChangesInSone(storedSone, sone);
770 database.storeSone(sone);
771 for (Object event : events) {
772 eventBus.post(event);
774 sone.setOptions(storedSone.getOptions());
775 sone.setKnown(storedSone.isKnown());
776 sone.setStatus((sone.getTime() == 0) ? SoneStatus.unknown : SoneStatus.idle);
777 if (sone.isLocal()) {
778 touchConfiguration();
783 private List<Object> collectEventsForChangesInSone(Sone oldSone, Sone newSone) {
784 List<Object> events = new ArrayList<>();
785 SoneComparison soneComparison = new SoneComparison(oldSone, newSone);
786 for (Post newPost : soneComparison.getNewPosts()) {
787 if (newPost.getSone().equals(newSone)) {
788 newPost.setKnown(true);
789 } else if (newPost.getTime() < database.getFollowingTime(newSone.getId())) {
790 newPost.setKnown(true);
791 } else if (!newPost.isKnown()) {
792 events.add(new NewPostFoundEvent(newPost));
795 for (Post post : soneComparison.getRemovedPosts()) {
796 events.add(new PostRemovedEvent(post));
798 for (PostReply postReply : soneComparison.getNewPostReplies()) {
799 if (postReply.getSone().equals(newSone)) {
800 database.setPostReplyKnown(postReply);
801 } else if (postReply.getTime() < database.getFollowingTime(newSone.getId())) {
802 database.setPostReplyKnown(postReply);
803 } else if (!postReply.isKnown()) {
804 events.add(new NewPostReplyFoundEvent(postReply));
807 for (PostReply postReply : soneComparison.getRemovedPostReplies()) {
808 events.add(new PostReplyRemovedEvent(postReply));
814 * Deletes the given Sone. This will remove the Sone from the
815 * {@link #getLocalSones() local Sones}, stop its {@link SoneInserter} and
816 * remove the context from its identity.
821 public void deleteSone(Sone sone) {
822 if (!(sone.getIdentity() instanceof OwnIdentity)) {
823 logger.log(Level.WARNING, String.format("Tried to delete Sone of non-own identity: %s", sone));
826 if (!getLocalSones().contains(sone)) {
827 logger.log(Level.WARNING, String.format("Tried to delete non-local Sone: %s", sone));
830 SoneInserter soneInserter = soneInserters.remove(sone);
832 database.removeSone(sone);
833 webOfTrustUpdater.removeContext((OwnIdentity) sone.getIdentity(), "Sone");
834 webOfTrustUpdater.removeProperty((OwnIdentity) sone.getIdentity(), "Sone.LatestEdition");
836 configuration.getLongValue("Sone/" + sone.getId() + "/Time").setValue(null);
837 } catch (ConfigurationException ce1) {
838 logger.log(Level.WARNING, "Could not remove Sone from configuration!", ce1);
843 * Marks the given Sone as known. If the Sone was not {@link Post#isKnown()
844 * known} before, a {@link MarkSoneKnownEvent} is fired.
847 * The Sone to mark as known
849 public void markSoneKnown(Sone sone) {
850 if (!sone.isKnown()) {
852 synchronized (knownSones) {
853 knownSones.add(sone.getId());
855 eventBus.post(new MarkSoneKnownEvent(sone));
856 touchConfiguration();
861 * Loads and updates the given Sone from the configuration. If any error is
862 * encountered, loading is aborted and the given Sone is not changed.
865 * The Sone to load and update
867 public void loadSone(Sone sone) {
868 if (!sone.isLocal()) {
869 logger.log(Level.FINE, String.format("Tried to load non-local Sone: %s", sone));
872 logger.info(String.format("Loading local Sone: %s", sone));
875 String sonePrefix = "Sone/" + sone.getId();
876 Long soneTime = configuration.getLongValue(sonePrefix + "/Time").getValue(null);
877 if (soneTime == null) {
878 logger.log(Level.INFO, "Could not load Sone because no Sone has been saved.");
881 String lastInsertFingerprint = configuration.getStringValue(sonePrefix + "/LastInsertFingerprint").getValue("");
884 ConfigurationSoneParser configurationSoneParser = new ConfigurationSoneParser(configuration, sone);
885 Profile profile = configurationSoneParser.parseProfile();
888 Collection<Post> posts;
890 posts = configurationSoneParser.parsePosts(database);
891 } catch (InvalidPostFound ipf) {
892 logger.log(Level.WARNING, "Invalid post found, aborting load!");
897 Collection<PostReply> replies;
899 replies = configurationSoneParser.parsePostReplies(database);
900 } catch (InvalidPostReplyFound iprf) {
901 logger.log(Level.WARNING, "Invalid reply found, aborting load!");
905 /* load post likes. */
906 Set<String> likedPostIds =
907 configurationSoneParser.parseLikedPostIds();
909 /* load reply likes. */
910 Set<String> likedReplyIds =
911 configurationSoneParser.parseLikedPostReplyIds();
914 List<Album> topLevelAlbums;
917 configurationSoneParser.parseTopLevelAlbums(database);
918 } catch (InvalidAlbumFound iaf) {
919 logger.log(Level.WARNING, "Invalid album found, aborting load!");
921 } catch (InvalidParentAlbumFound ipaf) {
922 logger.log(Level.WARNING, format("Invalid parent album ID: %s",
923 ipaf.getAlbumParentId()));
929 configurationSoneParser.parseImages(database);
930 } catch (InvalidImageFound iif) {
931 logger.log(WARNING, "Invalid image found, aborting load!");
933 } catch (InvalidParentAlbumFound ipaf) {
934 logger.log(Level.WARNING,
935 format("Invalid album image (%s) encountered, aborting load!",
936 ipaf.getAlbumParentId()));
941 String avatarId = configuration.getStringValue(sonePrefix + "/Profile/Avatar").getValue(null);
942 if (avatarId != null) {
943 final Map<String, Image> images =
944 configurationSoneParser.getImages();
945 profile.setAvatar(images.get(avatarId));
949 sone.getOptions().setAutoFollow(configuration.getBooleanValue(sonePrefix + "/Options/AutoFollow").getValue(false));
950 sone.getOptions().setSoneInsertNotificationEnabled(configuration.getBooleanValue(sonePrefix + "/Options/EnableSoneInsertNotifications").getValue(false));
951 sone.getOptions().setShowNewSoneNotifications(configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewSones").getValue(true));
952 sone.getOptions().setShowNewPostNotifications(configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewPosts").getValue(true));
953 sone.getOptions().setShowNewReplyNotifications(configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewReplies").getValue(true));
954 sone.getOptions().setShowCustomAvatars(LoadExternalContent.valueOf(configuration.getStringValue(sonePrefix + "/Options/ShowCustomAvatars").getValue(LoadExternalContent.NEVER.name())));
955 sone.getOptions().setLoadLinkedImages(LoadExternalContent.valueOf(configuration.getStringValue(sonePrefix + "/Options/LoadLinkedImages").getValue(LoadExternalContent.NEVER.name())));
957 /* if we’re still here, Sone was loaded successfully. */
958 synchronized (sone) {
959 sone.setTime(soneTime);
960 sone.setProfile(profile);
961 sone.setPosts(posts);
962 sone.setReplies(replies);
963 sone.setLikePostIds(likedPostIds);
964 sone.setLikeReplyIds(likedReplyIds);
965 for (Album album : sone.getRootAlbum().getAlbums()) {
966 sone.getRootAlbum().removeAlbum(album);
968 for (Album album : topLevelAlbums) {
969 sone.getRootAlbum().addAlbum(album);
971 synchronized (soneInserters) {
972 soneInserters.get(sone).setLastInsertFingerprint(lastInsertFingerprint);
975 for (Post post : posts) {
978 for (PostReply reply : replies) {
979 database.setPostReplyKnown(reply);
982 logger.info(String.format("Sone loaded successfully: %s", sone));
986 * Creates a new post.
989 * The Sone that creates the post
991 * The recipient Sone, or {@code null} if this post does not have
994 * The text of the post
995 * @return The created post
997 public Post createPost(Sone sone, @Nullable Sone recipient, String text) {
998 checkNotNull(text, "text must not be null");
999 checkArgument(text.trim().length() > 0, "text must not be empty");
1000 if (!sone.isLocal()) {
1001 logger.log(Level.FINE, String.format("Tried to create post for non-local Sone: %s", sone));
1004 PostBuilder postBuilder = database.newPostBuilder();
1005 postBuilder.from(sone.getId()).randomId().currentTime().withText(text.trim());
1006 if (recipient != null) {
1007 postBuilder.to(recipient.getId());
1009 final Post post = postBuilder.build();
1010 database.storePost(post);
1011 eventBus.post(new NewPostFoundEvent(post));
1013 touchConfiguration();
1014 localElementTicker.schedule(new MarkPostKnown(post), 10, TimeUnit.SECONDS);
1019 * Deletes the given post.
1022 * The post to delete
1024 public void deletePost(Post post) {
1025 if (!post.getSone().isLocal()) {
1026 logger.log(Level.WARNING, String.format("Tried to delete post of non-local Sone: %s", post.getSone()));
1029 database.removePost(post);
1030 eventBus.post(new PostRemovedEvent(post));
1031 markPostKnown(post);
1032 touchConfiguration();
1036 * Marks the given post as known, if it is currently not a known post
1037 * (according to {@link Post#isKnown()}).
1040 * The post to mark as known
1042 public void markPostKnown(Post post) {
1043 post.setKnown(true);
1044 eventBus.post(new MarkPostKnownEvent(post));
1045 touchConfiguration();
1046 for (PostReply reply : getReplies(post.getId())) {
1047 markReplyKnown(reply);
1051 public void bookmarkPost(Post post) {
1052 database.bookmarkPost(post);
1056 * Removes the given post from the bookmarks.
1059 * The post to unbookmark
1061 public void unbookmarkPost(Post post) {
1062 database.unbookmarkPost(post);
1066 * Creates a new reply.
1069 * The Sone that creates the reply
1071 * The post that this reply refers to
1073 * The text of the reply
1074 * @return The created reply
1076 public PostReply createReply(Sone sone, Post post, String text) {
1077 checkNotNull(text, "text must not be null");
1078 checkArgument(text.trim().length() > 0, "text must not be empty");
1079 if (!sone.isLocal()) {
1080 logger.log(Level.FINE, String.format("Tried to create reply for non-local Sone: %s", sone));
1083 PostReplyBuilder postReplyBuilder = postReplyBuilder();
1084 postReplyBuilder.randomId().from(sone.getId()).to(post.getId()).currentTime().withText(text.trim());
1085 final PostReply reply = postReplyBuilder.build();
1086 database.storePostReply(reply);
1087 eventBus.post(new NewPostReplyFoundEvent(reply));
1088 sone.addReply(reply);
1089 touchConfiguration();
1090 localElementTicker.schedule(new MarkReplyKnown(reply), 10, TimeUnit.SECONDS);
1095 * Deletes the given reply.
1098 * The reply to delete
1100 public void deleteReply(PostReply reply) {
1101 Sone sone = reply.getSone();
1102 if (!sone.isLocal()) {
1103 logger.log(Level.FINE, String.format("Tried to delete non-local reply: %s", reply));
1106 database.removePostReply(reply);
1107 markReplyKnown(reply);
1108 sone.removeReply(reply);
1109 touchConfiguration();
1113 * Marks the given reply as known, if it is currently not a known reply
1114 * (according to {@link Reply#isKnown()}).
1117 * The reply to mark as known
1119 public void markReplyKnown(PostReply reply) {
1120 boolean previouslyKnown = reply.isKnown();
1121 database.setPostReplyKnown(reply);
1122 eventBus.post(new MarkPostReplyKnownEvent(reply));
1123 if (!previouslyKnown) {
1124 touchConfiguration();
1129 * Creates a new album for the given Sone.
1132 * The Sone to create the album for
1134 * The parent of the album (may be {@code null} to create a
1136 * @return The new album
1138 public Album createAlbum(Sone sone, Album parent) {
1139 Album album = database.newAlbumBuilder().randomId().by(sone).build();
1140 database.storeAlbum(album);
1141 parent.addAlbum(album);
1146 * Deletes the given album. The owner of the album has to be a local Sone,
1147 * and the album has to be {@link Album#isEmpty() empty} to be deleted.
1150 * The album to remove
1152 public void deleteAlbum(Album album) {
1153 checkNotNull(album, "album must not be null");
1154 checkArgument(album.getSone().isLocal(), "album’s Sone must be a local Sone");
1155 if (!album.isEmpty()) {
1158 album.getParent().removeAlbum(album);
1159 database.removeAlbum(album);
1160 touchConfiguration();
1164 * Creates a new image.
1167 * The Sone creating the image
1169 * The album the image will be inserted into
1170 * @param temporaryImage
1171 * The temporary image to create the image from
1172 * @return The newly created image
1174 public Image createImage(Sone sone, Album album, TemporaryImage temporaryImage) {
1175 checkNotNull(sone, "sone must not be null");
1176 checkNotNull(album, "album must not be null");
1177 checkNotNull(temporaryImage, "temporaryImage must not be null");
1178 checkArgument(sone.isLocal(), "sone must be a local Sone");
1179 checkArgument(sone.equals(album.getSone()), "album must belong to the given Sone");
1180 Image image = database.newImageBuilder().withId(temporaryImage.getId()).build().modify().setSone(sone).setCreationTime(System.currentTimeMillis()).update();
1181 album.addImage(image);
1182 database.storeImage(image);
1183 imageInserter.insertImage(temporaryImage, image);
1188 * Deletes the given image. This method will also delete a matching
1191 * @see #deleteTemporaryImage(String)
1193 * The image to delete
1195 public void deleteImage(Image image) {
1196 checkNotNull(image, "image must not be null");
1197 checkArgument(image.getSone().isLocal(), "image must belong to a local Sone");
1198 deleteTemporaryImage(image.getId());
1199 image.getAlbum().removeImage(image);
1200 database.removeImage(image);
1201 touchConfiguration();
1205 * Creates a new temporary image.
1208 * The MIME type of the temporary image
1210 * The encoded data of the image
1211 * @return The temporary image
1213 public TemporaryImage createTemporaryImage(String mimeType, byte[] imageData) {
1214 TemporaryImage temporaryImage = new TemporaryImage();
1215 temporaryImage.setMimeType(mimeType).setImageData(imageData);
1216 synchronized (temporaryImages) {
1217 temporaryImages.put(temporaryImage.getId(), temporaryImage);
1219 return temporaryImage;
1223 * Deletes the temporary image with the given ID.
1226 * The ID of the temporary image to delete
1228 public void deleteTemporaryImage(String imageId) {
1229 checkNotNull(imageId, "imageId must not be null");
1230 synchronized (temporaryImages) {
1231 temporaryImages.remove(imageId);
1233 Image image = getImage(imageId, false);
1234 if (image != null) {
1235 imageInserter.cancelImageInsert(image);
1240 * Notifies the core that the configuration, either of the core or of a
1241 * single local Sone, has changed, and that the configuration should be
1244 public void touchConfiguration() {
1245 lastConfigurationUpdate = System.currentTimeMillis();
1256 public void serviceStart() {
1257 loadConfiguration();
1258 updateChecker.start();
1259 identityManager.start();
1260 webOfTrustUpdater.init();
1261 webOfTrustUpdater.start();
1262 database.startAsync();
1269 public void serviceRun() {
1270 long lastSaved = System.currentTimeMillis();
1271 while (!shouldStop()) {
1273 long now = System.currentTimeMillis();
1274 if (shouldStop() || ((lastConfigurationUpdate > lastSaved) && ((now - lastConfigurationUpdate) > 5000))) {
1275 for (Sone localSone : getLocalSones()) {
1276 saveSone(localSone);
1278 saveConfiguration();
1288 public void serviceStop() {
1289 localElementTicker.shutdownNow();
1290 synchronized (soneInserters) {
1291 for (Entry<Sone, SoneInserter> soneInserter : soneInserters.entrySet()) {
1292 soneInserter.getValue().stop();
1293 Sone latestSone = getLocalSone(soneInserter.getKey().getId());
1294 saveSone(latestSone);
1297 synchronized (soneRescuers) {
1298 for (SoneRescuer soneRescuer : soneRescuers.values()) {
1302 saveConfiguration();
1303 database.stopAsync();
1304 webOfTrustUpdater.stop();
1305 updateChecker.stop();
1306 soneDownloader.stop();
1307 soneDownloaders.shutdown();
1308 identityManager.stop();
1316 * Saves the given Sone. This will persist all local settings for the given
1317 * Sone, such as the friends list and similar, private options.
1322 private synchronized void saveSone(Sone sone) {
1323 if (!sone.isLocal()) {
1324 logger.log(Level.FINE, String.format("Tried to save non-local Sone: %s", sone));
1327 if (!(sone.getIdentity() instanceof OwnIdentity)) {
1328 logger.log(Level.WARNING, String.format("Local Sone without OwnIdentity found, refusing to save: %s", sone));
1332 logger.log(Level.INFO, String.format("Saving Sone: %s", sone));
1334 /* save Sone into configuration. */
1335 String sonePrefix = "Sone/" + sone.getId();
1336 configuration.getLongValue(sonePrefix + "/Time").setValue(sone.getTime());
1337 configuration.getStringValue(sonePrefix + "/LastInsertFingerprint").setValue(soneInserters.get(sone).getLastInsertFingerprint());
1340 Profile profile = sone.getProfile();
1341 configuration.getStringValue(sonePrefix + "/Profile/FirstName").setValue(profile.getFirstName());
1342 configuration.getStringValue(sonePrefix + "/Profile/MiddleName").setValue(profile.getMiddleName());
1343 configuration.getStringValue(sonePrefix + "/Profile/LastName").setValue(profile.getLastName());
1344 configuration.getIntValue(sonePrefix + "/Profile/BirthDay").setValue(profile.getBirthDay());
1345 configuration.getIntValue(sonePrefix + "/Profile/BirthMonth").setValue(profile.getBirthMonth());
1346 configuration.getIntValue(sonePrefix + "/Profile/BirthYear").setValue(profile.getBirthYear());
1347 configuration.getStringValue(sonePrefix + "/Profile/Avatar").setValue(profile.getAvatar());
1349 /* save profile fields. */
1350 int fieldCounter = 0;
1351 for (Field profileField : profile.getFields()) {
1352 String fieldPrefix = sonePrefix + "/Profile/Fields/" + fieldCounter++;
1353 configuration.getStringValue(fieldPrefix + "/Name").setValue(profileField.getName());
1354 configuration.getStringValue(fieldPrefix + "/Value").setValue(profileField.getValue());
1356 configuration.getStringValue(sonePrefix + "/Profile/Fields/" + fieldCounter + "/Name").setValue(null);
1359 int postCounter = 0;
1360 for (Post post : sone.getPosts()) {
1361 String postPrefix = sonePrefix + "/Posts/" + postCounter++;
1362 configuration.getStringValue(postPrefix + "/ID").setValue(post.getId());
1363 configuration.getStringValue(postPrefix + "/Recipient").setValue(post.getRecipientId().orNull());
1364 configuration.getLongValue(postPrefix + "/Time").setValue(post.getTime());
1365 configuration.getStringValue(postPrefix + "/Text").setValue(post.getText());
1367 configuration.getStringValue(sonePrefix + "/Posts/" + postCounter + "/ID").setValue(null);
1370 int replyCounter = 0;
1371 for (PostReply reply : sone.getReplies()) {
1372 String replyPrefix = sonePrefix + "/Replies/" + replyCounter++;
1373 configuration.getStringValue(replyPrefix + "/ID").setValue(reply.getId());
1374 configuration.getStringValue(replyPrefix + "/Post/ID").setValue(reply.getPostId());
1375 configuration.getLongValue(replyPrefix + "/Time").setValue(reply.getTime());
1376 configuration.getStringValue(replyPrefix + "/Text").setValue(reply.getText());
1378 configuration.getStringValue(sonePrefix + "/Replies/" + replyCounter + "/ID").setValue(null);
1380 /* save post likes. */
1381 int postLikeCounter = 0;
1382 for (String postId : sone.getLikedPostIds()) {
1383 configuration.getStringValue(sonePrefix + "/Likes/Post/" + postLikeCounter++ + "/ID").setValue(postId);
1385 configuration.getStringValue(sonePrefix + "/Likes/Post/" + postLikeCounter + "/ID").setValue(null);
1387 /* save reply likes. */
1388 int replyLikeCounter = 0;
1389 for (String replyId : sone.getLikedReplyIds()) {
1390 configuration.getStringValue(sonePrefix + "/Likes/Reply/" + replyLikeCounter++ + "/ID").setValue(replyId);
1392 configuration.getStringValue(sonePrefix + "/Likes/Reply/" + replyLikeCounter + "/ID").setValue(null);
1394 /* save albums. first, collect in a flat structure, top-level first. */
1395 List<Album> albums = SoneKt.getAllAlbums(sone);
1397 int albumCounter = 0;
1398 for (Album album : albums) {
1399 String albumPrefix = sonePrefix + "/Albums/" + albumCounter++;
1400 configuration.getStringValue(albumPrefix + "/ID").setValue(album.getId());
1401 configuration.getStringValue(albumPrefix + "/Title").setValue(album.getTitle());
1402 configuration.getStringValue(albumPrefix + "/Description").setValue(album.getDescription());
1403 configuration.getStringValue(albumPrefix + "/Parent").setValue(album.getParent().equals(sone.getRootAlbum()) ? null : album.getParent().getId());
1405 configuration.getStringValue(sonePrefix + "/Albums/" + albumCounter + "/ID").setValue(null);
1408 int imageCounter = 0;
1409 for (Album album : albums) {
1410 for (Image image : album.getImages()) {
1411 if (!image.isInserted()) {
1414 String imagePrefix = sonePrefix + "/Images/" + imageCounter++;
1415 configuration.getStringValue(imagePrefix + "/ID").setValue(image.getId());
1416 configuration.getStringValue(imagePrefix + "/Album").setValue(album.getId());
1417 configuration.getStringValue(imagePrefix + "/Key").setValue(image.getKey());
1418 configuration.getStringValue(imagePrefix + "/Title").setValue(image.getTitle());
1419 configuration.getStringValue(imagePrefix + "/Description").setValue(image.getDescription());
1420 configuration.getLongValue(imagePrefix + "/CreationTime").setValue(image.getCreationTime());
1421 configuration.getIntValue(imagePrefix + "/Width").setValue(image.getWidth());
1422 configuration.getIntValue(imagePrefix + "/Height").setValue(image.getHeight());
1425 configuration.getStringValue(sonePrefix + "/Images/" + imageCounter + "/ID").setValue(null);
1428 configuration.getBooleanValue(sonePrefix + "/Options/AutoFollow").setValue(sone.getOptions().isAutoFollow());
1429 configuration.getBooleanValue(sonePrefix + "/Options/EnableSoneInsertNotifications").setValue(sone.getOptions().isSoneInsertNotificationEnabled());
1430 configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewSones").setValue(sone.getOptions().isShowNewSoneNotifications());
1431 configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewPosts").setValue(sone.getOptions().isShowNewPostNotifications());
1432 configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewReplies").setValue(sone.getOptions().isShowNewReplyNotifications());
1433 configuration.getStringValue(sonePrefix + "/Options/ShowCustomAvatars").setValue(sone.getOptions().getShowCustomAvatars().name());
1434 configuration.getStringValue(sonePrefix + "/Options/LoadLinkedImages").setValue(sone.getOptions().getLoadLinkedImages().name());
1436 webOfTrustUpdater.setProperty((OwnIdentity) sone.getIdentity(), "Sone.LatestEdition", String.valueOf(sone.getLatestEdition()));
1438 logger.log(Level.INFO, String.format("Sone %s saved.", sone));
1439 } catch (ConfigurationException ce1) {
1440 logger.log(Level.WARNING, String.format("Could not save Sone: %s", sone), ce1);
1445 * Saves the current options.
1447 private void saveConfiguration() {
1448 synchronized (configuration) {
1449 if (storingConfiguration) {
1450 logger.log(Level.FINE, "Already storing configuration…");
1453 storingConfiguration = true;
1456 /* store the options first. */
1458 preferences.saveTo(configuration);
1460 /* save known Sones. */
1461 int soneCounter = 0;
1462 synchronized (knownSones) {
1463 for (String knownSoneId : knownSones) {
1464 configuration.getStringValue("KnownSone/" + soneCounter++ + "/ID").setValue(knownSoneId);
1466 configuration.getStringValue("KnownSone/" + soneCounter + "/ID").setValue(null);
1469 /* save known posts. */
1473 Stopwatch stopwatch = Stopwatch.createStarted();
1474 configuration.save();
1475 configurationSaveTimeHistogram.update(stopwatch.elapsed(TimeUnit.MICROSECONDS));
1477 } catch (ConfigurationException ce1) {
1478 logger.log(Level.SEVERE, "Could not store configuration!", ce1);
1479 } catch (DatabaseException de1) {
1480 logger.log(Level.SEVERE, "Could not save database!", de1);
1482 synchronized (configuration) {
1483 storingConfiguration = false;
1489 * Loads the configuration.
1491 private void loadConfiguration() {
1492 new PreferencesLoader(preferences).loadFrom(configuration);
1494 /* load known Sones. */
1495 int soneCounter = 0;
1497 String knownSoneId = configuration.getStringValue("KnownSone/" + soneCounter++ + "/ID").getValue(null);
1498 if (knownSoneId == null) {
1501 synchronized (knownSones) {
1502 knownSones.add(knownSoneId);
1508 * Notifies the core that a new {@link OwnIdentity} was added.
1510 * @param ownIdentityAddedEvent
1514 public void ownIdentityAdded(OwnIdentityAddedEvent ownIdentityAddedEvent) {
1515 OwnIdentity ownIdentity = ownIdentityAddedEvent.getOwnIdentity();
1516 logger.log(Level.FINEST, String.format("Adding OwnIdentity: %s", ownIdentity));
1517 if (ownIdentity.hasContext("Sone")) {
1518 addLocalSone(ownIdentity);
1523 * Notifies the core that an {@link OwnIdentity} was removed.
1525 * @param ownIdentityRemovedEvent
1529 public void ownIdentityRemoved(OwnIdentityRemovedEvent ownIdentityRemovedEvent) {
1530 OwnIdentity ownIdentity = ownIdentityRemovedEvent.getOwnIdentity();
1531 logger.log(Level.FINEST, String.format("Removing OwnIdentity: %s", ownIdentity));
1532 trustedIdentities.removeAll(ownIdentity);
1536 * Notifies the core that a new {@link Identity} was added.
1538 * @param identityAddedEvent
1542 public void identityAdded(IdentityAddedEvent identityAddedEvent) {
1543 Identity identity = identityAddedEvent.getIdentity();
1544 logger.log(Level.FINEST, String.format("Adding Identity: %s", identity));
1545 trustedIdentities.put(identityAddedEvent.getOwnIdentity(), identity);
1546 addRemoteSone(identity);
1550 * Notifies the core that an {@link Identity} was updated.
1552 * @param identityUpdatedEvent
1556 public void identityUpdated(IdentityUpdatedEvent identityUpdatedEvent) {
1557 Identity identity = identityUpdatedEvent.getIdentity();
1558 final Sone sone = getRemoteSone(identity.getId());
1559 if (sone.isLocal()) {
1562 String newLatestEdition = identity.getProperty("Sone.LatestEdition");
1563 if (newLatestEdition != null) {
1564 Long parsedNewLatestEdition = tryParse(newLatestEdition);
1565 if (parsedNewLatestEdition != null) {
1566 sone.setLatestEdition(parsedNewLatestEdition);
1569 soneDownloader.addSone(sone);
1570 soneDownloaders.execute(soneDownloader.fetchSoneAsSskAction(sone));
1574 * Notifies the core that an {@link Identity} was removed.
1576 * @param identityRemovedEvent
1580 public void identityRemoved(IdentityRemovedEvent identityRemovedEvent) {
1581 OwnIdentity ownIdentity = identityRemovedEvent.getOwnIdentity();
1582 Identity identity = identityRemovedEvent.getIdentity();
1583 trustedIdentities.remove(ownIdentity, identity);
1584 for (Entry<OwnIdentity, Collection<Identity>> trustedIdentity : trustedIdentities.asMap().entrySet()) {
1585 if (trustedIdentity.getKey().equals(ownIdentity)) {
1588 if (trustedIdentity.getValue().contains(identity)) {
1592 Sone sone = getSone(identity.getId());
1594 /* TODO - we don’t have the Sone anymore. should this happen? */
1597 for (PostReply postReply : sone.getReplies()) {
1598 eventBus.post(new PostReplyRemovedEvent(postReply));
1600 for (Post post : sone.getPosts()) {
1601 eventBus.post(new PostRemovedEvent(post));
1603 eventBus.post(new SoneRemovedEvent(sone));
1604 database.removeSone(sone);
1608 * Deletes the temporary image.
1610 * @param imageInsertFinishedEvent
1614 public void imageInsertFinished(ImageInsertFinishedEvent imageInsertFinishedEvent) {
1615 logger.log(Level.WARNING, String.format("Image insert finished for %s: %s", imageInsertFinishedEvent.getImage(), imageInsertFinishedEvent.getResultingUri()));
1616 imageInsertFinishedEvent.getImage().modify().setKey(imageInsertFinishedEvent.getResultingUri().toString()).update();
1617 deleteTemporaryImage(imageInsertFinishedEvent.getImage().getId());
1618 touchConfiguration();
1622 class MarkPostKnown implements Runnable {
1624 private final Post post;
1626 public MarkPostKnown(Post post) {
1632 markPostKnown(post);
1638 class MarkReplyKnown implements Runnable {
1640 private final PostReply postReply;
1642 public MarkReplyKnown(PostReply postReply) {
1643 this.postReply = postReply;
1648 markReplyKnown(postReply);