2 * Sone - Core.java - Copyright © 2010–2019 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 * Creates a new core.
186 * @param configuration
187 * The configuration of the core
188 * @param freenetInterface
189 * The freenet interface
190 * @param identityManager
191 * The identity manager
192 * @param webOfTrustUpdater
193 * The WebOfTrust updater
200 public Core(Configuration configuration, FreenetInterface freenetInterface, IdentityManager identityManager, SoneDownloader soneDownloader, ImageInserter imageInserter, UpdateChecker updateChecker, WebOfTrustUpdater webOfTrustUpdater, EventBus eventBus, Database database, MetricRegistry metricRegistry) {
202 this.configuration = configuration;
203 this.freenetInterface = freenetInterface;
204 this.identityManager = identityManager;
205 this.soneDownloader = soneDownloader;
206 this.imageInserter = imageInserter;
207 this.updateChecker = updateChecker;
208 this.webOfTrustUpdater = webOfTrustUpdater;
209 this.eventBus = eventBus;
210 this.database = database;
211 this.metricRegistry = metricRegistry;
212 preferences = new Preferences(eventBus);
213 this.configurationSaveTimeHistogram = metricRegistry.histogram("configuration.save.duration", () -> new Histogram(new ExponentiallyDecayingReservoir(3000, 0)));
221 * Returns the time Sone was started.
223 * @return The startup time (in milliseconds since Jan 1, 1970 UTC)
225 public long getStartupTime() {
230 public boolean getDebug() {
234 public void setDebug() {
236 eventBus.post(new DebugActivatedEvent());
240 * Returns the options used by the core.
242 * @return The options of the core
244 public Preferences getPreferences() {
249 * Returns the identity manager used by the core.
251 * @return The identity manager
253 public IdentityManager getIdentityManager() {
254 return identityManager;
258 * Returns the update checker.
260 * @return The update checker
262 public UpdateChecker getUpdateChecker() {
263 return updateChecker;
267 * Returns the Sone rescuer for the given local Sone.
270 * The local Sone to get the rescuer for
271 * @return The Sone rescuer for the given Sone
273 public SoneRescuer getSoneRescuer(Sone sone) {
274 checkNotNull(sone, "sone must not be null");
275 checkArgument(sone.isLocal(), "sone must be local");
276 synchronized (soneRescuers) {
277 SoneRescuer soneRescuer = soneRescuers.get(sone);
278 if (soneRescuer == null) {
279 soneRescuer = new SoneRescuer(this, soneDownloader, sone);
280 soneRescuers.put(sone, soneRescuer);
288 * Returns whether the given Sone is currently locked.
292 * @return {@code true} if the Sone is locked, {@code false} if it is not
294 public boolean isLocked(Sone sone) {
295 synchronized (lockedSones) {
296 return lockedSones.contains(sone);
300 public SoneBuilder soneBuilder() {
301 return database.newSoneBuilder();
309 public Collection<Sone> getSones() {
310 return database.getSones();
315 public Function1<String, Sone> getSoneLoader() {
316 return database.getSoneLoader();
320 * Returns the Sone with the given ID, regardless whether it’s local or
324 * The ID of the Sone to get
325 * @return The Sone with the given ID, or {@code null} if there is no such
330 public Sone getSone(@Nonnull String id) {
331 return database.getSone(id);
338 public Collection<Sone> getLocalSones() {
339 return database.getLocalSones();
343 * Returns the local Sone with the given ID, optionally creating a new Sone.
347 * @return The Sone with the given ID, or {@code null}
349 public Sone getLocalSone(String id) {
350 Sone sone = database.getSone(id);
351 if ((sone != null) && sone.isLocal()) {
361 public Collection<Sone> getRemoteSones() {
362 return database.getRemoteSones();
366 * Returns the remote Sone with the given ID.
370 * The ID of the remote Sone to get
371 * @return The Sone with the given ID
373 public Sone getRemoteSone(String id) {
374 return database.getSone(id);
378 * Returns whether the given Sone has been modified.
381 * The Sone to check for modifications
382 * @return {@code true} if a modification has been detected in the Sone,
383 * {@code false} otherwise
385 public boolean isModifiedSone(Sone sone) {
386 return soneInserters.containsKey(sone) && soneInserters.get(sone).isModified();
390 * Returns a post builder.
392 * @return A new post builder
394 public PostBuilder postBuilder() {
395 return database.newPostBuilder();
400 public Post getPost(@Nonnull String postId) {
401 return database.getPost(postId);
408 public Collection<Post> getPosts(String soneId) {
409 return database.getPosts(soneId);
416 public Collection<Post> getDirectedPosts(final String recipientId) {
417 checkNotNull(recipientId, "recipient must not be null");
418 return database.getDirectedPosts(recipientId);
422 * Returns a post reply builder.
424 * @return A new post reply builder
426 public PostReplyBuilder postReplyBuilder() {
427 return database.newPostReplyBuilder();
435 public PostReply getPostReply(String replyId) {
436 return database.getPostReply(replyId);
443 public List<PostReply> getReplies(final String postId) {
444 return database.getReplies(postId);
448 * Returns all Sones that have liked the given post.
451 * The post to get the liking Sones for
452 * @return The Sones that like the given post
454 public Set<Sone> getLikes(Post post) {
455 Set<Sone> sones = new HashSet<>();
456 for (Sone sone : getSones()) {
457 if (sone.getLikedPostIds().contains(post.getId())) {
465 * Returns all Sones that have liked the given reply.
468 * The reply to get the liking Sones for
469 * @return The Sones that like the given reply
471 public Set<Sone> getLikes(PostReply reply) {
472 Set<Sone> sones = new HashSet<>();
473 for (Sone sone : getSones()) {
474 if (sone.getLikedReplyIds().contains(reply.getId())) {
482 * Returns whether the given post is bookmarked.
486 * @return {@code true} if the given post is bookmarked, {@code false}
489 public boolean isBookmarked(Post post) {
490 return database.isPostBookmarked(post);
494 * Returns all currently known bookmarked posts.
496 * @return All bookmarked posts
498 public Set<Post> getBookmarkedPosts() {
499 return database.getBookmarkedPosts();
502 public AlbumBuilder albumBuilder() {
503 return database.newAlbumBuilder();
507 * Returns the album with the given ID, optionally creating a new album if
508 * an album with the given ID can not be found.
511 * The ID of the album
512 * @return The album with the given ID, or {@code null} if no album with the
516 public Album getAlbum(@Nonnull String albumId) {
517 return database.getAlbum(albumId);
520 public ImageBuilder imageBuilder() {
521 return database.newImageBuilder();
525 * Returns the image with the given ID, creating it if necessary.
528 * The ID of the image
529 * @return The image with the given ID
532 public Image getImage(String imageId) {
533 return getImage(imageId, true);
537 * Returns the image with the given ID, optionally creating it if it does
541 * The ID of the image
543 * {@code true} to create an image if none exists with the given
545 * @return The image with the given ID, or {@code null} if none exists and
549 public Image getImage(String imageId, boolean create) {
550 Image image = database.getImage(imageId);
557 Image newImage = database.newImageBuilder().withId(imageId).build();
558 database.storeImage(newImage);
563 * Returns the temporary image with the given ID.
566 * The ID of the temporary image
567 * @return The temporary image, or {@code null} if there is no temporary
568 * image with the given ID
570 public TemporaryImage getTemporaryImage(String imageId) {
571 synchronized (temporaryImages) {
572 return temporaryImages.get(imageId);
581 * Locks the given Sone. A locked Sone will not be inserted by
582 * {@link SoneInserter} until it is {@link #unlockSone(Sone) unlocked}
588 public void lockSone(Sone sone) {
589 synchronized (lockedSones) {
590 if (lockedSones.add(sone)) {
591 eventBus.post(new SoneLockedEvent(sone));
597 * Unlocks the given Sone.
599 * @see #lockSone(Sone)
603 public void unlockSone(Sone sone) {
604 synchronized (lockedSones) {
605 if (lockedSones.remove(sone)) {
606 eventBus.post(new SoneUnlockedEvent(sone));
612 * Adds a local Sone from the given own identity.
615 * The own identity to create a Sone from
616 * @return The added (or already existing) Sone
618 public Sone addLocalSone(OwnIdentity ownIdentity) {
619 if (ownIdentity == null) {
620 logger.log(Level.WARNING, "Given OwnIdentity is null!");
623 logger.info(String.format("Adding Sone from OwnIdentity: %s", ownIdentity));
624 Sone sone = database.newSoneBuilder().local().from(ownIdentity).build();
625 String property = fromNullable(ownIdentity.getProperty("Sone.LatestEdition")).or("0");
626 sone.setLatestEdition(fromNullable(tryParse(property)).or(0L));
627 sone.setClient(new Client("Sone", SonePlugin.getPluginVersion()));
629 SoneInserter soneInserter = new SoneInserter(this, eventBus, freenetInterface, metricRegistry, ownIdentity.getId());
630 soneInserter.insertionDelayChanged(new InsertionDelayChangedEvent(preferences.getInsertionDelay()));
631 eventBus.register(soneInserter);
632 synchronized (soneInserters) {
633 soneInserters.put(sone, soneInserter);
636 database.storeSone(sone);
637 sone.setStatus(SoneStatus.idle);
638 if (sone.getPosts().isEmpty() && sone.getReplies().isEmpty() && getAllImages(sone.getRootAlbum()).isEmpty()) {
642 soneInserter.start();
647 * Creates a new Sone for the given own identity.
650 * The own identity to create a Sone for
651 * @return The created Sone
653 public Sone createSone(OwnIdentity ownIdentity) {
654 if (!webOfTrustUpdater.addContextWait(ownIdentity, "Sone")) {
655 logger.log(Level.SEVERE, String.format("Could not add “Sone” context to own identity: %s", ownIdentity));
658 Sone sone = addLocalSone(ownIdentity);
660 followSone(sone, "nwa8lHa271k2QvJ8aa0Ov7IHAV-DFOCFgmDt3X6BpCI");
661 touchConfiguration();
666 * Adds the Sone of the given identity.
669 * The identity whose Sone to add
670 * @return The added or already existing Sone
672 public Sone addRemoteSone(Identity identity) {
673 if (identity == null) {
674 logger.log(Level.WARNING, "Given Identity is null!");
677 String property = fromNullable(identity.getProperty("Sone.LatestEdition")).or("0");
678 long latestEdition = fromNullable(tryParse(property)).or(0L);
679 Sone existingSone = getSone(identity.getId());
680 if ((existingSone != null )&& existingSone.isLocal()) {
683 boolean newSone = existingSone == null;
684 Sone sone = !newSone ? existingSone : database.newSoneBuilder().from(identity).build();
685 sone.setLatestEdition(latestEdition);
687 synchronized (knownSones) {
688 newSone = !knownSones.contains(sone.getId());
690 sone.setKnown(!newSone);
692 eventBus.post(new NewSoneFoundEvent(sone));
693 for (Sone localSone : getLocalSones()) {
694 if (localSone.getOptions().isAutoFollow()) {
695 followSone(localSone, sone.getId());
700 database.storeSone(sone);
701 soneDownloader.addSone(sone);
702 soneDownloaders.execute(soneDownloader.fetchSoneAsUskAction(sone));
707 * Lets the given local Sone follow the Sone with the given ID.
710 * The local Sone that should follow another Sone
712 * The ID of the Sone to follow
714 public void followSone(Sone sone, String soneId) {
715 checkNotNull(sone, "sone must not be null");
716 checkNotNull(soneId, "soneId must not be null");
717 database.addFriend(sone, soneId);
718 @SuppressWarnings("ConstantConditions") // we just followed, this can’t be null.
719 long now = database.getFollowingTime(soneId);
720 Sone followedSone = getSone(soneId);
721 if (followedSone == null) {
724 for (Post post : followedSone.getPosts()) {
725 if (post.getTime() < now) {
729 for (PostReply reply : followedSone.getReplies()) {
730 if (reply.getTime() < now) {
731 markReplyKnown(reply);
734 touchConfiguration();
738 * Lets the given local Sone unfollow the Sone with the given ID.
741 * The local Sone that should unfollow another Sone
743 * The ID of the Sone being unfollowed
745 public void unfollowSone(Sone sone, String soneId) {
746 checkNotNull(sone, "sone must not be null");
747 checkNotNull(soneId, "soneId must not be null");
748 database.removeFriend(sone, soneId);
749 touchConfiguration();
753 * Updates the stored Sone with the given Sone.
758 public void updateSone(Sone sone) {
759 updateSone(sone, false);
763 * Updates the stored Sone with the given Sone. If {@code soneRescueMode} is
764 * {@code true}, an older Sone than the current Sone can be given to restore
769 * @param soneRescueMode
770 * {@code true} if the stored Sone should be updated regardless
771 * of the age of the given Sone
773 public void updateSone(final Sone sone, boolean soneRescueMode) {
774 Sone storedSone = getSone(sone.getId());
775 if (storedSone != null) {
776 if (!soneRescueMode && !(sone.getTime() > storedSone.getTime())) {
777 logger.log(Level.FINE, String.format("Downloaded Sone %s is not newer than stored Sone %s.", sone, storedSone));
780 List<Object> events =
781 collectEventsForChangesInSone(storedSone, sone);
782 database.storeSone(sone);
783 for (Object event : events) {
784 eventBus.post(event);
786 sone.setOptions(storedSone.getOptions());
787 sone.setKnown(storedSone.isKnown());
788 sone.setStatus((sone.getTime() == 0) ? SoneStatus.unknown : SoneStatus.idle);
789 if (sone.isLocal()) {
790 touchConfiguration();
795 private List<Object> collectEventsForChangesInSone(Sone oldSone, Sone newSone) {
796 List<Object> events = new ArrayList<>();
797 SoneComparison soneComparison = new SoneComparison(oldSone, newSone);
798 for (Post newPost : soneComparison.getNewPosts()) {
799 if (newPost.getSone().equals(newSone)) {
800 newPost.setKnown(true);
801 } else if (newPost.getTime() < database.getFollowingTime(newSone.getId())) {
802 newPost.setKnown(true);
803 } else if (!newPost.isKnown()) {
804 events.add(new NewPostFoundEvent(newPost));
807 for (Post post : soneComparison.getRemovedPosts()) {
808 events.add(new PostRemovedEvent(post));
810 for (PostReply postReply : soneComparison.getNewPostReplies()) {
811 if (postReply.getSone().equals(newSone)) {
812 postReply.setKnown(true);
813 } else if (postReply.getTime() < database.getFollowingTime(newSone.getId())) {
814 postReply.setKnown(true);
815 } else if (!postReply.isKnown()) {
816 events.add(new NewPostReplyFoundEvent(postReply));
819 for (PostReply postReply : soneComparison.getRemovedPostReplies()) {
820 events.add(new PostReplyRemovedEvent(postReply));
826 * Deletes the given Sone. This will remove the Sone from the
827 * {@link #getLocalSones() local Sones}, stop its {@link SoneInserter} and
828 * remove the context from its identity.
833 public void deleteSone(Sone sone) {
834 if (!(sone.getIdentity() instanceof OwnIdentity)) {
835 logger.log(Level.WARNING, String.format("Tried to delete Sone of non-own identity: %s", sone));
838 if (!getLocalSones().contains(sone)) {
839 logger.log(Level.WARNING, String.format("Tried to delete non-local Sone: %s", sone));
842 SoneInserter soneInserter = soneInserters.remove(sone);
844 database.removeSone(sone);
845 webOfTrustUpdater.removeContext((OwnIdentity) sone.getIdentity(), "Sone");
846 webOfTrustUpdater.removeProperty((OwnIdentity) sone.getIdentity(), "Sone.LatestEdition");
848 configuration.getLongValue("Sone/" + sone.getId() + "/Time").setValue(null);
849 } catch (ConfigurationException ce1) {
850 logger.log(Level.WARNING, "Could not remove Sone from configuration!", ce1);
855 * Marks the given Sone as known. If the Sone was not {@link Post#isKnown()
856 * known} before, a {@link MarkSoneKnownEvent} is fired.
859 * The Sone to mark as known
861 public void markSoneKnown(Sone sone) {
862 if (!sone.isKnown()) {
864 synchronized (knownSones) {
865 knownSones.add(sone.getId());
867 eventBus.post(new MarkSoneKnownEvent(sone));
868 touchConfiguration();
873 * Loads and updates the given Sone from the configuration. If any error is
874 * encountered, loading is aborted and the given Sone is not changed.
877 * The Sone to load and update
879 public void loadSone(Sone sone) {
880 if (!sone.isLocal()) {
881 logger.log(Level.FINE, String.format("Tried to load non-local Sone: %s", sone));
884 logger.info(String.format("Loading local Sone: %s", sone));
887 String sonePrefix = "Sone/" + sone.getId();
888 Long soneTime = configuration.getLongValue(sonePrefix + "/Time").getValue(null);
889 if (soneTime == null) {
890 logger.log(Level.INFO, "Could not load Sone because no Sone has been saved.");
893 String lastInsertFingerprint = configuration.getStringValue(sonePrefix + "/LastInsertFingerprint").getValue("");
896 ConfigurationSoneParser configurationSoneParser = new ConfigurationSoneParser(configuration, sone);
897 Profile profile = configurationSoneParser.parseProfile();
900 Collection<Post> posts;
902 posts = configurationSoneParser.parsePosts(database);
903 } catch (InvalidPostFound ipf) {
904 logger.log(Level.WARNING, "Invalid post found, aborting load!");
909 Collection<PostReply> replies;
911 replies = configurationSoneParser.parsePostReplies(database);
912 } catch (InvalidPostReplyFound iprf) {
913 logger.log(Level.WARNING, "Invalid reply found, aborting load!");
917 /* load post likes. */
918 Set<String> likedPostIds =
919 configurationSoneParser.parseLikedPostIds();
921 /* load reply likes. */
922 Set<String> likedReplyIds =
923 configurationSoneParser.parseLikedPostReplyIds();
926 List<Album> topLevelAlbums;
929 configurationSoneParser.parseTopLevelAlbums(database);
930 } catch (InvalidAlbumFound iaf) {
931 logger.log(Level.WARNING, "Invalid album found, aborting load!");
933 } catch (InvalidParentAlbumFound ipaf) {
934 logger.log(Level.WARNING, format("Invalid parent album ID: %s",
935 ipaf.getAlbumParentId()));
941 configurationSoneParser.parseImages(database);
942 } catch (InvalidImageFound iif) {
943 logger.log(WARNING, "Invalid image found, aborting load!");
945 } catch (InvalidParentAlbumFound ipaf) {
946 logger.log(Level.WARNING,
947 format("Invalid album image (%s) encountered, aborting load!",
948 ipaf.getAlbumParentId()));
953 String avatarId = configuration.getStringValue(sonePrefix + "/Profile/Avatar").getValue(null);
954 if (avatarId != null) {
955 final Map<String, Image> images =
956 configurationSoneParser.getImages();
957 profile.setAvatar(images.get(avatarId));
961 sone.getOptions().setAutoFollow(configuration.getBooleanValue(sonePrefix + "/Options/AutoFollow").getValue(false));
962 sone.getOptions().setSoneInsertNotificationEnabled(configuration.getBooleanValue(sonePrefix + "/Options/EnableSoneInsertNotifications").getValue(false));
963 sone.getOptions().setShowNewSoneNotifications(configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewSones").getValue(true));
964 sone.getOptions().setShowNewPostNotifications(configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewPosts").getValue(true));
965 sone.getOptions().setShowNewReplyNotifications(configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewReplies").getValue(true));
966 sone.getOptions().setShowCustomAvatars(LoadExternalContent.valueOf(configuration.getStringValue(sonePrefix + "/Options/ShowCustomAvatars").getValue(LoadExternalContent.NEVER.name())));
967 sone.getOptions().setLoadLinkedImages(LoadExternalContent.valueOf(configuration.getStringValue(sonePrefix + "/Options/LoadLinkedImages").getValue(LoadExternalContent.NEVER.name())));
969 /* if we’re still here, Sone was loaded successfully. */
970 synchronized (sone) {
971 sone.setTime(soneTime);
972 sone.setProfile(profile);
973 sone.setPosts(posts);
974 sone.setReplies(replies);
975 sone.setLikePostIds(likedPostIds);
976 sone.setLikeReplyIds(likedReplyIds);
977 for (Album album : sone.getRootAlbum().getAlbums()) {
978 sone.getRootAlbum().removeAlbum(album);
980 for (Album album : topLevelAlbums) {
981 sone.getRootAlbum().addAlbum(album);
983 synchronized (soneInserters) {
984 soneInserters.get(sone).setLastInsertFingerprint(lastInsertFingerprint);
987 for (Post post : posts) {
990 for (PostReply reply : replies) {
991 reply.setKnown(true);
994 logger.info(String.format("Sone loaded successfully: %s", sone));
998 * Creates a new post.
1001 * The Sone that creates the post
1003 * The recipient Sone, or {@code null} if this post does not have
1006 * The text of the post
1007 * @return The created post
1009 public Post createPost(Sone sone, @Nullable Sone recipient, String text) {
1010 checkNotNull(text, "text must not be null");
1011 checkArgument(text.trim().length() > 0, "text must not be empty");
1012 if (!sone.isLocal()) {
1013 logger.log(Level.FINE, String.format("Tried to create post for non-local Sone: %s", sone));
1016 PostBuilder postBuilder = database.newPostBuilder();
1017 postBuilder.from(sone.getId()).randomId().currentTime().withText(text.trim());
1018 if (recipient != null) {
1019 postBuilder.to(recipient.getId());
1021 final Post post = postBuilder.build();
1022 database.storePost(post);
1023 eventBus.post(new NewPostFoundEvent(post));
1025 touchConfiguration();
1026 localElementTicker.schedule(new MarkPostKnown(post), 10, TimeUnit.SECONDS);
1031 * Deletes the given post.
1034 * The post to delete
1036 public void deletePost(Post post) {
1037 if (!post.getSone().isLocal()) {
1038 logger.log(Level.WARNING, String.format("Tried to delete post of non-local Sone: %s", post.getSone()));
1041 database.removePost(post);
1042 eventBus.post(new PostRemovedEvent(post));
1043 markPostKnown(post);
1044 touchConfiguration();
1048 * Marks the given post as known, if it is currently not a known post
1049 * (according to {@link Post#isKnown()}).
1052 * The post to mark as known
1054 public void markPostKnown(Post post) {
1055 post.setKnown(true);
1056 eventBus.post(new MarkPostKnownEvent(post));
1057 touchConfiguration();
1058 for (PostReply reply : getReplies(post.getId())) {
1059 markReplyKnown(reply);
1063 public void bookmarkPost(Post post) {
1064 database.bookmarkPost(post);
1068 * Removes the given post from the bookmarks.
1071 * The post to unbookmark
1073 public void unbookmarkPost(Post post) {
1074 database.unbookmarkPost(post);
1078 * Creates a new reply.
1081 * The Sone that creates the reply
1083 * The post that this reply refers to
1085 * The text of the reply
1086 * @return The created reply
1088 public PostReply createReply(Sone sone, Post post, String text) {
1089 checkNotNull(text, "text must not be null");
1090 checkArgument(text.trim().length() > 0, "text must not be empty");
1091 if (!sone.isLocal()) {
1092 logger.log(Level.FINE, String.format("Tried to create reply for non-local Sone: %s", sone));
1095 PostReplyBuilder postReplyBuilder = postReplyBuilder();
1096 postReplyBuilder.randomId().from(sone.getId()).to(post.getId()).currentTime().withText(text.trim());
1097 final PostReply reply = postReplyBuilder.build();
1098 database.storePostReply(reply);
1099 eventBus.post(new NewPostReplyFoundEvent(reply));
1100 sone.addReply(reply);
1101 touchConfiguration();
1102 localElementTicker.schedule(new MarkReplyKnown(reply), 10, TimeUnit.SECONDS);
1107 * Deletes the given reply.
1110 * The reply to delete
1112 public void deleteReply(PostReply reply) {
1113 Sone sone = reply.getSone();
1114 if (!sone.isLocal()) {
1115 logger.log(Level.FINE, String.format("Tried to delete non-local reply: %s", reply));
1118 database.removePostReply(reply);
1119 markReplyKnown(reply);
1120 sone.removeReply(reply);
1121 touchConfiguration();
1125 * Marks the given reply as known, if it is currently not a known reply
1126 * (according to {@link Reply#isKnown()}).
1129 * The reply to mark as known
1131 public void markReplyKnown(PostReply reply) {
1132 boolean previouslyKnown = reply.isKnown();
1133 reply.setKnown(true);
1134 eventBus.post(new MarkPostReplyKnownEvent(reply));
1135 if (!previouslyKnown) {
1136 touchConfiguration();
1141 * Creates a new album for the given Sone.
1144 * The Sone to create the album for
1146 * The parent of the album (may be {@code null} to create a
1148 * @return The new album
1150 public Album createAlbum(Sone sone, Album parent) {
1151 Album album = database.newAlbumBuilder().randomId().by(sone).build();
1152 database.storeAlbum(album);
1153 parent.addAlbum(album);
1158 * Deletes the given album. The owner of the album has to be a local Sone,
1159 * and the album has to be {@link Album#isEmpty() empty} to be deleted.
1162 * The album to remove
1164 public void deleteAlbum(Album album) {
1165 checkNotNull(album, "album must not be null");
1166 checkArgument(album.getSone().isLocal(), "album’s Sone must be a local Sone");
1167 if (!album.isEmpty()) {
1170 album.getParent().removeAlbum(album);
1171 database.removeAlbum(album);
1172 touchConfiguration();
1176 * Creates a new image.
1179 * The Sone creating the image
1181 * The album the image will be inserted into
1182 * @param temporaryImage
1183 * The temporary image to create the image from
1184 * @return The newly created image
1186 public Image createImage(Sone sone, Album album, TemporaryImage temporaryImage) {
1187 checkNotNull(sone, "sone must not be null");
1188 checkNotNull(album, "album must not be null");
1189 checkNotNull(temporaryImage, "temporaryImage must not be null");
1190 checkArgument(sone.isLocal(), "sone must be a local Sone");
1191 checkArgument(sone.equals(album.getSone()), "album must belong to the given Sone");
1192 Image image = database.newImageBuilder().withId(temporaryImage.getId()).build().modify().setSone(sone).setCreationTime(System.currentTimeMillis()).update();
1193 album.addImage(image);
1194 database.storeImage(image);
1195 imageInserter.insertImage(temporaryImage, image);
1200 * Deletes the given image. This method will also delete a matching
1203 * @see #deleteTemporaryImage(String)
1205 * The image to delete
1207 public void deleteImage(Image image) {
1208 checkNotNull(image, "image must not be null");
1209 checkArgument(image.getSone().isLocal(), "image must belong to a local Sone");
1210 deleteTemporaryImage(image.getId());
1211 image.getAlbum().removeImage(image);
1212 database.removeImage(image);
1213 touchConfiguration();
1217 * Creates a new temporary image.
1220 * The MIME type of the temporary image
1222 * The encoded data of the image
1223 * @return The temporary image
1225 public TemporaryImage createTemporaryImage(String mimeType, byte[] imageData) {
1226 TemporaryImage temporaryImage = new TemporaryImage();
1227 temporaryImage.setMimeType(mimeType).setImageData(imageData);
1228 synchronized (temporaryImages) {
1229 temporaryImages.put(temporaryImage.getId(), temporaryImage);
1231 return temporaryImage;
1235 * Deletes the temporary image with the given ID.
1238 * The ID of the temporary image to delete
1240 public void deleteTemporaryImage(String imageId) {
1241 checkNotNull(imageId, "imageId must not be null");
1242 synchronized (temporaryImages) {
1243 temporaryImages.remove(imageId);
1245 Image image = getImage(imageId, false);
1246 if (image != null) {
1247 imageInserter.cancelImageInsert(image);
1252 * Notifies the core that the configuration, either of the core or of a
1253 * single local Sone, has changed, and that the configuration should be
1256 public void touchConfiguration() {
1257 lastConfigurationUpdate = System.currentTimeMillis();
1268 public void serviceStart() {
1269 loadConfiguration();
1270 updateChecker.start();
1271 identityManager.start();
1272 webOfTrustUpdater.init();
1273 webOfTrustUpdater.start();
1274 database.startAsync();
1281 public void serviceRun() {
1282 long lastSaved = System.currentTimeMillis();
1283 while (!shouldStop()) {
1285 long now = System.currentTimeMillis();
1286 if (shouldStop() || ((lastConfigurationUpdate > lastSaved) && ((now - lastConfigurationUpdate) > 5000))) {
1287 for (Sone localSone : getLocalSones()) {
1288 saveSone(localSone);
1290 saveConfiguration();
1300 public void serviceStop() {
1301 localElementTicker.shutdownNow();
1302 synchronized (soneInserters) {
1303 for (Entry<Sone, SoneInserter> soneInserter : soneInserters.entrySet()) {
1304 soneInserter.getValue().stop();
1305 Sone latestSone = getLocalSone(soneInserter.getKey().getId());
1306 saveSone(latestSone);
1309 synchronized (soneRescuers) {
1310 for (SoneRescuer soneRescuer : soneRescuers.values()) {
1314 saveConfiguration();
1315 database.stopAsync();
1316 webOfTrustUpdater.stop();
1317 updateChecker.stop();
1318 soneDownloader.stop();
1319 soneDownloaders.shutdown();
1320 identityManager.stop();
1328 * Saves the given Sone. This will persist all local settings for the given
1329 * Sone, such as the friends list and similar, private options.
1334 private synchronized void saveSone(Sone sone) {
1335 if (!sone.isLocal()) {
1336 logger.log(Level.FINE, String.format("Tried to save non-local Sone: %s", sone));
1339 if (!(sone.getIdentity() instanceof OwnIdentity)) {
1340 logger.log(Level.WARNING, String.format("Local Sone without OwnIdentity found, refusing to save: %s", sone));
1344 logger.log(Level.INFO, String.format("Saving Sone: %s", sone));
1346 /* save Sone into configuration. */
1347 String sonePrefix = "Sone/" + sone.getId();
1348 configuration.getLongValue(sonePrefix + "/Time").setValue(sone.getTime());
1349 configuration.getStringValue(sonePrefix + "/LastInsertFingerprint").setValue(soneInserters.get(sone).getLastInsertFingerprint());
1352 Profile profile = sone.getProfile();
1353 configuration.getStringValue(sonePrefix + "/Profile/FirstName").setValue(profile.getFirstName());
1354 configuration.getStringValue(sonePrefix + "/Profile/MiddleName").setValue(profile.getMiddleName());
1355 configuration.getStringValue(sonePrefix + "/Profile/LastName").setValue(profile.getLastName());
1356 configuration.getIntValue(sonePrefix + "/Profile/BirthDay").setValue(profile.getBirthDay());
1357 configuration.getIntValue(sonePrefix + "/Profile/BirthMonth").setValue(profile.getBirthMonth());
1358 configuration.getIntValue(sonePrefix + "/Profile/BirthYear").setValue(profile.getBirthYear());
1359 configuration.getStringValue(sonePrefix + "/Profile/Avatar").setValue(profile.getAvatar());
1361 /* save profile fields. */
1362 int fieldCounter = 0;
1363 for (Field profileField : profile.getFields()) {
1364 String fieldPrefix = sonePrefix + "/Profile/Fields/" + fieldCounter++;
1365 configuration.getStringValue(fieldPrefix + "/Name").setValue(profileField.getName());
1366 configuration.getStringValue(fieldPrefix + "/Value").setValue(profileField.getValue());
1368 configuration.getStringValue(sonePrefix + "/Profile/Fields/" + fieldCounter + "/Name").setValue(null);
1371 int postCounter = 0;
1372 for (Post post : sone.getPosts()) {
1373 String postPrefix = sonePrefix + "/Posts/" + postCounter++;
1374 configuration.getStringValue(postPrefix + "/ID").setValue(post.getId());
1375 configuration.getStringValue(postPrefix + "/Recipient").setValue(post.getRecipientId().orNull());
1376 configuration.getLongValue(postPrefix + "/Time").setValue(post.getTime());
1377 configuration.getStringValue(postPrefix + "/Text").setValue(post.getText());
1379 configuration.getStringValue(sonePrefix + "/Posts/" + postCounter + "/ID").setValue(null);
1382 int replyCounter = 0;
1383 for (PostReply reply : sone.getReplies()) {
1384 String replyPrefix = sonePrefix + "/Replies/" + replyCounter++;
1385 configuration.getStringValue(replyPrefix + "/ID").setValue(reply.getId());
1386 configuration.getStringValue(replyPrefix + "/Post/ID").setValue(reply.getPostId());
1387 configuration.getLongValue(replyPrefix + "/Time").setValue(reply.getTime());
1388 configuration.getStringValue(replyPrefix + "/Text").setValue(reply.getText());
1390 configuration.getStringValue(sonePrefix + "/Replies/" + replyCounter + "/ID").setValue(null);
1392 /* save post likes. */
1393 int postLikeCounter = 0;
1394 for (String postId : sone.getLikedPostIds()) {
1395 configuration.getStringValue(sonePrefix + "/Likes/Post/" + postLikeCounter++ + "/ID").setValue(postId);
1397 configuration.getStringValue(sonePrefix + "/Likes/Post/" + postLikeCounter + "/ID").setValue(null);
1399 /* save reply likes. */
1400 int replyLikeCounter = 0;
1401 for (String replyId : sone.getLikedReplyIds()) {
1402 configuration.getStringValue(sonePrefix + "/Likes/Reply/" + replyLikeCounter++ + "/ID").setValue(replyId);
1404 configuration.getStringValue(sonePrefix + "/Likes/Reply/" + replyLikeCounter + "/ID").setValue(null);
1406 /* save albums. first, collect in a flat structure, top-level first. */
1407 List<Album> albums = FluentIterable.from(sone.getRootAlbum().getAlbums()).transformAndConcat(Album.FLATTENER).toList();
1409 int albumCounter = 0;
1410 for (Album album : albums) {
1411 String albumPrefix = sonePrefix + "/Albums/" + albumCounter++;
1412 configuration.getStringValue(albumPrefix + "/ID").setValue(album.getId());
1413 configuration.getStringValue(albumPrefix + "/Title").setValue(album.getTitle());
1414 configuration.getStringValue(albumPrefix + "/Description").setValue(album.getDescription());
1415 configuration.getStringValue(albumPrefix + "/Parent").setValue(album.getParent().equals(sone.getRootAlbum()) ? null : album.getParent().getId());
1417 configuration.getStringValue(sonePrefix + "/Albums/" + albumCounter + "/ID").setValue(null);
1420 int imageCounter = 0;
1421 for (Album album : albums) {
1422 for (Image image : album.getImages()) {
1423 if (!image.isInserted()) {
1426 String imagePrefix = sonePrefix + "/Images/" + imageCounter++;
1427 configuration.getStringValue(imagePrefix + "/ID").setValue(image.getId());
1428 configuration.getStringValue(imagePrefix + "/Album").setValue(album.getId());
1429 configuration.getStringValue(imagePrefix + "/Key").setValue(image.getKey());
1430 configuration.getStringValue(imagePrefix + "/Title").setValue(image.getTitle());
1431 configuration.getStringValue(imagePrefix + "/Description").setValue(image.getDescription());
1432 configuration.getLongValue(imagePrefix + "/CreationTime").setValue(image.getCreationTime());
1433 configuration.getIntValue(imagePrefix + "/Width").setValue(image.getWidth());
1434 configuration.getIntValue(imagePrefix + "/Height").setValue(image.getHeight());
1437 configuration.getStringValue(sonePrefix + "/Images/" + imageCounter + "/ID").setValue(null);
1440 configuration.getBooleanValue(sonePrefix + "/Options/AutoFollow").setValue(sone.getOptions().isAutoFollow());
1441 configuration.getBooleanValue(sonePrefix + "/Options/EnableSoneInsertNotifications").setValue(sone.getOptions().isSoneInsertNotificationEnabled());
1442 configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewSones").setValue(sone.getOptions().isShowNewSoneNotifications());
1443 configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewPosts").setValue(sone.getOptions().isShowNewPostNotifications());
1444 configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewReplies").setValue(sone.getOptions().isShowNewReplyNotifications());
1445 configuration.getStringValue(sonePrefix + "/Options/ShowCustomAvatars").setValue(sone.getOptions().getShowCustomAvatars().name());
1446 configuration.getStringValue(sonePrefix + "/Options/LoadLinkedImages").setValue(sone.getOptions().getLoadLinkedImages().name());
1448 webOfTrustUpdater.setProperty((OwnIdentity) sone.getIdentity(), "Sone.LatestEdition", String.valueOf(sone.getLatestEdition()));
1450 logger.log(Level.INFO, String.format("Sone %s saved.", sone));
1451 } catch (ConfigurationException ce1) {
1452 logger.log(Level.WARNING, String.format("Could not save Sone: %s", sone), ce1);
1457 * Saves the current options.
1459 private void saveConfiguration() {
1460 synchronized (configuration) {
1461 if (storingConfiguration) {
1462 logger.log(Level.FINE, "Already storing configuration…");
1465 storingConfiguration = true;
1468 /* store the options first. */
1470 preferences.saveTo(configuration);
1472 /* save known Sones. */
1473 int soneCounter = 0;
1474 synchronized (knownSones) {
1475 for (String knownSoneId : knownSones) {
1476 configuration.getStringValue("KnownSone/" + soneCounter++ + "/ID").setValue(knownSoneId);
1478 configuration.getStringValue("KnownSone/" + soneCounter + "/ID").setValue(null);
1481 /* save known posts. */
1485 Stopwatch stopwatch = Stopwatch.createStarted();
1486 configuration.save();
1487 configurationSaveTimeHistogram.update(stopwatch.elapsed(TimeUnit.MICROSECONDS));
1489 } catch (ConfigurationException ce1) {
1490 logger.log(Level.SEVERE, "Could not store configuration!", ce1);
1491 } catch (DatabaseException de1) {
1492 logger.log(Level.SEVERE, "Could not save database!", de1);
1494 synchronized (configuration) {
1495 storingConfiguration = false;
1501 * Loads the configuration.
1503 private void loadConfiguration() {
1504 new PreferencesLoader(preferences).loadFrom(configuration);
1506 /* load known Sones. */
1507 int soneCounter = 0;
1509 String knownSoneId = configuration.getStringValue("KnownSone/" + soneCounter++ + "/ID").getValue(null);
1510 if (knownSoneId == null) {
1513 synchronized (knownSones) {
1514 knownSones.add(knownSoneId);
1520 * Notifies the core that a new {@link OwnIdentity} was added.
1522 * @param ownIdentityAddedEvent
1526 public void ownIdentityAdded(OwnIdentityAddedEvent ownIdentityAddedEvent) {
1527 OwnIdentity ownIdentity = ownIdentityAddedEvent.getOwnIdentity();
1528 logger.log(Level.FINEST, String.format("Adding OwnIdentity: %s", ownIdentity));
1529 if (ownIdentity.hasContext("Sone")) {
1530 addLocalSone(ownIdentity);
1535 * Notifies the core that an {@link OwnIdentity} was removed.
1537 * @param ownIdentityRemovedEvent
1541 public void ownIdentityRemoved(OwnIdentityRemovedEvent ownIdentityRemovedEvent) {
1542 OwnIdentity ownIdentity = ownIdentityRemovedEvent.getOwnIdentity();
1543 logger.log(Level.FINEST, String.format("Removing OwnIdentity: %s", ownIdentity));
1544 trustedIdentities.removeAll(ownIdentity);
1548 * Notifies the core that a new {@link Identity} was added.
1550 * @param identityAddedEvent
1554 public void identityAdded(IdentityAddedEvent identityAddedEvent) {
1555 Identity identity = identityAddedEvent.getIdentity();
1556 logger.log(Level.FINEST, String.format("Adding Identity: %s", identity));
1557 trustedIdentities.put(identityAddedEvent.getOwnIdentity(), identity);
1558 addRemoteSone(identity);
1562 * Notifies the core that an {@link Identity} was updated.
1564 * @param identityUpdatedEvent
1568 public void identityUpdated(IdentityUpdatedEvent identityUpdatedEvent) {
1569 Identity identity = identityUpdatedEvent.getIdentity();
1570 final Sone sone = getRemoteSone(identity.getId());
1571 if (sone.isLocal()) {
1574 String newLatestEdition = identity.getProperty("Sone.LatestEdition");
1575 if (newLatestEdition != null) {
1576 Long parsedNewLatestEdition = tryParse(newLatestEdition);
1577 if (parsedNewLatestEdition != null) {
1578 sone.setLatestEdition(parsedNewLatestEdition);
1581 soneDownloader.addSone(sone);
1582 soneDownloaders.execute(soneDownloader.fetchSoneAsSskAction(sone));
1586 * Notifies the core that an {@link Identity} was removed.
1588 * @param identityRemovedEvent
1592 public void identityRemoved(IdentityRemovedEvent identityRemovedEvent) {
1593 OwnIdentity ownIdentity = identityRemovedEvent.getOwnIdentity();
1594 Identity identity = identityRemovedEvent.getIdentity();
1595 trustedIdentities.remove(ownIdentity, identity);
1596 for (Entry<OwnIdentity, Collection<Identity>> trustedIdentity : trustedIdentities.asMap().entrySet()) {
1597 if (trustedIdentity.getKey().equals(ownIdentity)) {
1600 if (trustedIdentity.getValue().contains(identity)) {
1604 Sone sone = getSone(identity.getId());
1606 /* TODO - we don’t have the Sone anymore. should this happen? */
1609 for (PostReply postReply : sone.getReplies()) {
1610 eventBus.post(new PostReplyRemovedEvent(postReply));
1612 for (Post post : sone.getPosts()) {
1613 eventBus.post(new PostRemovedEvent(post));
1615 eventBus.post(new SoneRemovedEvent(sone));
1616 database.removeSone(sone);
1620 * Deletes the temporary image.
1622 * @param imageInsertFinishedEvent
1626 public void imageInsertFinished(ImageInsertFinishedEvent imageInsertFinishedEvent) {
1627 logger.log(Level.WARNING, String.format("Image insert finished for %s: %s", imageInsertFinishedEvent.getImage(), imageInsertFinishedEvent.getResultingUri()));
1628 imageInsertFinishedEvent.getImage().modify().setKey(imageInsertFinishedEvent.getResultingUri().toString()).update();
1629 deleteTemporaryImage(imageInsertFinishedEvent.getImage().getId());
1630 touchConfiguration();
1634 class MarkPostKnown implements Runnable {
1636 private final Post post;
1638 public MarkPostKnown(Post post) {
1644 markPostKnown(post);
1650 class MarkReplyKnown implements Runnable {
1652 private final PostReply postReply;
1654 public MarkReplyKnown(PostReply postReply) {
1655 this.postReply = postReply;
1660 markReplyKnown(postReply);