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()) {
641 eventBus.post(new SoneLockedOnStartup(sone));
643 soneInserter.start();
648 * Creates a new Sone for the given own identity.
651 * The own identity to create a Sone for
652 * @return The created Sone
654 public Sone createSone(OwnIdentity ownIdentity) {
655 if (!webOfTrustUpdater.addContextWait(ownIdentity, "Sone")) {
656 logger.log(Level.SEVERE, String.format("Could not add “Sone” context to own identity: %s", ownIdentity));
659 Sone sone = addLocalSone(ownIdentity);
661 followSone(sone, "nwa8lHa271k2QvJ8aa0Ov7IHAV-DFOCFgmDt3X6BpCI");
662 touchConfiguration();
667 * Adds the Sone of the given identity.
670 * The identity whose Sone to add
671 * @return The added or already existing Sone
673 public Sone addRemoteSone(Identity identity) {
674 if (identity == null) {
675 logger.log(Level.WARNING, "Given Identity is null!");
678 String property = fromNullable(identity.getProperty("Sone.LatestEdition")).or("0");
679 long latestEdition = fromNullable(tryParse(property)).or(0L);
680 Sone existingSone = getSone(identity.getId());
681 if ((existingSone != null )&& existingSone.isLocal()) {
684 boolean newSone = existingSone == null;
685 Sone sone = !newSone ? existingSone : database.newSoneBuilder().from(identity).build();
686 sone.setLatestEdition(latestEdition);
688 synchronized (knownSones) {
689 newSone = !knownSones.contains(sone.getId());
691 sone.setKnown(!newSone);
693 eventBus.post(new NewSoneFoundEvent(sone));
694 for (Sone localSone : getLocalSones()) {
695 if (localSone.getOptions().isAutoFollow()) {
696 followSone(localSone, sone.getId());
701 database.storeSone(sone);
702 soneDownloader.addSone(sone);
703 soneDownloaders.execute(soneDownloader.fetchSoneAsUskAction(sone));
708 * Lets the given local Sone follow the Sone with the given ID.
711 * The local Sone that should follow another Sone
713 * The ID of the Sone to follow
715 public void followSone(Sone sone, String soneId) {
716 checkNotNull(sone, "sone must not be null");
717 checkNotNull(soneId, "soneId must not be null");
718 database.addFriend(sone, soneId);
719 @SuppressWarnings("ConstantConditions") // we just followed, this can’t be null.
720 long now = database.getFollowingTime(soneId);
721 Sone followedSone = getSone(soneId);
722 if (followedSone == null) {
725 for (Post post : followedSone.getPosts()) {
726 if (post.getTime() < now) {
730 for (PostReply reply : followedSone.getReplies()) {
731 if (reply.getTime() < now) {
732 markReplyKnown(reply);
735 touchConfiguration();
739 * Lets the given local Sone unfollow the Sone with the given ID.
742 * The local Sone that should unfollow another Sone
744 * The ID of the Sone being unfollowed
746 public void unfollowSone(Sone sone, String soneId) {
747 checkNotNull(sone, "sone must not be null");
748 checkNotNull(soneId, "soneId must not be null");
749 database.removeFriend(sone, soneId);
750 touchConfiguration();
754 * Updates the stored Sone with the given Sone.
759 public void updateSone(Sone sone) {
760 updateSone(sone, false);
764 * Updates the stored Sone with the given Sone. If {@code soneRescueMode} is
765 * {@code true}, an older Sone than the current Sone can be given to restore
770 * @param soneRescueMode
771 * {@code true} if the stored Sone should be updated regardless
772 * of the age of the given Sone
774 public void updateSone(final Sone sone, boolean soneRescueMode) {
775 Sone storedSone = getSone(sone.getId());
776 if (storedSone != null) {
777 if (!soneRescueMode && !(sone.getTime() > storedSone.getTime())) {
778 logger.log(Level.FINE, String.format("Downloaded Sone %s is not newer than stored Sone %s.", sone, storedSone));
781 List<Object> events =
782 collectEventsForChangesInSone(storedSone, sone);
783 database.storeSone(sone);
784 for (Object event : events) {
785 eventBus.post(event);
787 sone.setOptions(storedSone.getOptions());
788 sone.setKnown(storedSone.isKnown());
789 sone.setStatus((sone.getTime() == 0) ? SoneStatus.unknown : SoneStatus.idle);
790 if (sone.isLocal()) {
791 touchConfiguration();
796 private List<Object> collectEventsForChangesInSone(Sone oldSone, Sone newSone) {
797 List<Object> events = new ArrayList<>();
798 SoneComparison soneComparison = new SoneComparison(oldSone, newSone);
799 for (Post newPost : soneComparison.getNewPosts()) {
800 if (newPost.getSone().equals(newSone)) {
801 newPost.setKnown(true);
802 } else if (newPost.getTime() < database.getFollowingTime(newSone.getId())) {
803 newPost.setKnown(true);
804 } else if (!newPost.isKnown()) {
805 events.add(new NewPostFoundEvent(newPost));
808 for (Post post : soneComparison.getRemovedPosts()) {
809 events.add(new PostRemovedEvent(post));
811 for (PostReply postReply : soneComparison.getNewPostReplies()) {
812 if (postReply.getSone().equals(newSone)) {
813 postReply.setKnown(true);
814 } else if (postReply.getTime() < database.getFollowingTime(newSone.getId())) {
815 postReply.setKnown(true);
816 } else if (!postReply.isKnown()) {
817 events.add(new NewPostReplyFoundEvent(postReply));
820 for (PostReply postReply : soneComparison.getRemovedPostReplies()) {
821 events.add(new PostReplyRemovedEvent(postReply));
827 * Deletes the given Sone. This will remove the Sone from the
828 * {@link #getLocalSones() local Sones}, stop its {@link SoneInserter} and
829 * remove the context from its identity.
834 public void deleteSone(Sone sone) {
835 if (!(sone.getIdentity() instanceof OwnIdentity)) {
836 logger.log(Level.WARNING, String.format("Tried to delete Sone of non-own identity: %s", sone));
839 if (!getLocalSones().contains(sone)) {
840 logger.log(Level.WARNING, String.format("Tried to delete non-local Sone: %s", sone));
843 SoneInserter soneInserter = soneInserters.remove(sone);
845 database.removeSone(sone);
846 webOfTrustUpdater.removeContext((OwnIdentity) sone.getIdentity(), "Sone");
847 webOfTrustUpdater.removeProperty((OwnIdentity) sone.getIdentity(), "Sone.LatestEdition");
849 configuration.getLongValue("Sone/" + sone.getId() + "/Time").setValue(null);
850 } catch (ConfigurationException ce1) {
851 logger.log(Level.WARNING, "Could not remove Sone from configuration!", ce1);
856 * Marks the given Sone as known. If the Sone was not {@link Post#isKnown()
857 * known} before, a {@link MarkSoneKnownEvent} is fired.
860 * The Sone to mark as known
862 public void markSoneKnown(Sone sone) {
863 if (!sone.isKnown()) {
865 synchronized (knownSones) {
866 knownSones.add(sone.getId());
868 eventBus.post(new MarkSoneKnownEvent(sone));
869 touchConfiguration();
874 * Loads and updates the given Sone from the configuration. If any error is
875 * encountered, loading is aborted and the given Sone is not changed.
878 * The Sone to load and update
880 public void loadSone(Sone sone) {
881 if (!sone.isLocal()) {
882 logger.log(Level.FINE, String.format("Tried to load non-local Sone: %s", sone));
885 logger.info(String.format("Loading local Sone: %s", sone));
888 String sonePrefix = "Sone/" + sone.getId();
889 Long soneTime = configuration.getLongValue(sonePrefix + "/Time").getValue(null);
890 if (soneTime == null) {
891 logger.log(Level.INFO, "Could not load Sone because no Sone has been saved.");
894 String lastInsertFingerprint = configuration.getStringValue(sonePrefix + "/LastInsertFingerprint").getValue("");
897 ConfigurationSoneParser configurationSoneParser = new ConfigurationSoneParser(configuration, sone);
898 Profile profile = configurationSoneParser.parseProfile();
901 Collection<Post> posts;
903 posts = configurationSoneParser.parsePosts(database);
904 } catch (InvalidPostFound ipf) {
905 logger.log(Level.WARNING, "Invalid post found, aborting load!");
910 Collection<PostReply> replies;
912 replies = configurationSoneParser.parsePostReplies(database);
913 } catch (InvalidPostReplyFound iprf) {
914 logger.log(Level.WARNING, "Invalid reply found, aborting load!");
918 /* load post likes. */
919 Set<String> likedPostIds =
920 configurationSoneParser.parseLikedPostIds();
922 /* load reply likes. */
923 Set<String> likedReplyIds =
924 configurationSoneParser.parseLikedPostReplyIds();
927 List<Album> topLevelAlbums;
930 configurationSoneParser.parseTopLevelAlbums(database);
931 } catch (InvalidAlbumFound iaf) {
932 logger.log(Level.WARNING, "Invalid album found, aborting load!");
934 } catch (InvalidParentAlbumFound ipaf) {
935 logger.log(Level.WARNING, format("Invalid parent album ID: %s",
936 ipaf.getAlbumParentId()));
942 configurationSoneParser.parseImages(database);
943 } catch (InvalidImageFound iif) {
944 logger.log(WARNING, "Invalid image found, aborting load!");
946 } catch (InvalidParentAlbumFound ipaf) {
947 logger.log(Level.WARNING,
948 format("Invalid album image (%s) encountered, aborting load!",
949 ipaf.getAlbumParentId()));
954 String avatarId = configuration.getStringValue(sonePrefix + "/Profile/Avatar").getValue(null);
955 if (avatarId != null) {
956 final Map<String, Image> images =
957 configurationSoneParser.getImages();
958 profile.setAvatar(images.get(avatarId));
962 sone.getOptions().setAutoFollow(configuration.getBooleanValue(sonePrefix + "/Options/AutoFollow").getValue(false));
963 sone.getOptions().setSoneInsertNotificationEnabled(configuration.getBooleanValue(sonePrefix + "/Options/EnableSoneInsertNotifications").getValue(false));
964 sone.getOptions().setShowNewSoneNotifications(configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewSones").getValue(true));
965 sone.getOptions().setShowNewPostNotifications(configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewPosts").getValue(true));
966 sone.getOptions().setShowNewReplyNotifications(configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewReplies").getValue(true));
967 sone.getOptions().setShowCustomAvatars(LoadExternalContent.valueOf(configuration.getStringValue(sonePrefix + "/Options/ShowCustomAvatars").getValue(LoadExternalContent.NEVER.name())));
968 sone.getOptions().setLoadLinkedImages(LoadExternalContent.valueOf(configuration.getStringValue(sonePrefix + "/Options/LoadLinkedImages").getValue(LoadExternalContent.NEVER.name())));
970 /* if we’re still here, Sone was loaded successfully. */
971 synchronized (sone) {
972 sone.setTime(soneTime);
973 sone.setProfile(profile);
974 sone.setPosts(posts);
975 sone.setReplies(replies);
976 sone.setLikePostIds(likedPostIds);
977 sone.setLikeReplyIds(likedReplyIds);
978 for (Album album : sone.getRootAlbum().getAlbums()) {
979 sone.getRootAlbum().removeAlbum(album);
981 for (Album album : topLevelAlbums) {
982 sone.getRootAlbum().addAlbum(album);
984 synchronized (soneInserters) {
985 soneInserters.get(sone).setLastInsertFingerprint(lastInsertFingerprint);
988 for (Post post : posts) {
991 for (PostReply reply : replies) {
992 reply.setKnown(true);
995 logger.info(String.format("Sone loaded successfully: %s", sone));
999 * Creates a new post.
1002 * The Sone that creates the post
1004 * The recipient Sone, or {@code null} if this post does not have
1007 * The text of the post
1008 * @return The created post
1010 public Post createPost(Sone sone, @Nullable Sone recipient, String text) {
1011 checkNotNull(text, "text must not be null");
1012 checkArgument(text.trim().length() > 0, "text must not be empty");
1013 if (!sone.isLocal()) {
1014 logger.log(Level.FINE, String.format("Tried to create post for non-local Sone: %s", sone));
1017 PostBuilder postBuilder = database.newPostBuilder();
1018 postBuilder.from(sone.getId()).randomId().currentTime().withText(text.trim());
1019 if (recipient != null) {
1020 postBuilder.to(recipient.getId());
1022 final Post post = postBuilder.build();
1023 database.storePost(post);
1024 eventBus.post(new NewPostFoundEvent(post));
1026 touchConfiguration();
1027 localElementTicker.schedule(new MarkPostKnown(post), 10, TimeUnit.SECONDS);
1032 * Deletes the given post.
1035 * The post to delete
1037 public void deletePost(Post post) {
1038 if (!post.getSone().isLocal()) {
1039 logger.log(Level.WARNING, String.format("Tried to delete post of non-local Sone: %s", post.getSone()));
1042 database.removePost(post);
1043 eventBus.post(new PostRemovedEvent(post));
1044 markPostKnown(post);
1045 touchConfiguration();
1049 * Marks the given post as known, if it is currently not a known post
1050 * (according to {@link Post#isKnown()}).
1053 * The post to mark as known
1055 public void markPostKnown(Post post) {
1056 post.setKnown(true);
1057 eventBus.post(new MarkPostKnownEvent(post));
1058 touchConfiguration();
1059 for (PostReply reply : getReplies(post.getId())) {
1060 markReplyKnown(reply);
1064 public void bookmarkPost(Post post) {
1065 database.bookmarkPost(post);
1069 * Removes the given post from the bookmarks.
1072 * The post to unbookmark
1074 public void unbookmarkPost(Post post) {
1075 database.unbookmarkPost(post);
1079 * Creates a new reply.
1082 * The Sone that creates the reply
1084 * The post that this reply refers to
1086 * The text of the reply
1087 * @return The created reply
1089 public PostReply createReply(Sone sone, Post post, String text) {
1090 checkNotNull(text, "text must not be null");
1091 checkArgument(text.trim().length() > 0, "text must not be empty");
1092 if (!sone.isLocal()) {
1093 logger.log(Level.FINE, String.format("Tried to create reply for non-local Sone: %s", sone));
1096 PostReplyBuilder postReplyBuilder = postReplyBuilder();
1097 postReplyBuilder.randomId().from(sone.getId()).to(post.getId()).currentTime().withText(text.trim());
1098 final PostReply reply = postReplyBuilder.build();
1099 database.storePostReply(reply);
1100 eventBus.post(new NewPostReplyFoundEvent(reply));
1101 sone.addReply(reply);
1102 touchConfiguration();
1103 localElementTicker.schedule(new MarkReplyKnown(reply), 10, TimeUnit.SECONDS);
1108 * Deletes the given reply.
1111 * The reply to delete
1113 public void deleteReply(PostReply reply) {
1114 Sone sone = reply.getSone();
1115 if (!sone.isLocal()) {
1116 logger.log(Level.FINE, String.format("Tried to delete non-local reply: %s", reply));
1119 database.removePostReply(reply);
1120 markReplyKnown(reply);
1121 sone.removeReply(reply);
1122 touchConfiguration();
1126 * Marks the given reply as known, if it is currently not a known reply
1127 * (according to {@link Reply#isKnown()}).
1130 * The reply to mark as known
1132 public void markReplyKnown(PostReply reply) {
1133 boolean previouslyKnown = reply.isKnown();
1134 reply.setKnown(true);
1135 eventBus.post(new MarkPostReplyKnownEvent(reply));
1136 if (!previouslyKnown) {
1137 touchConfiguration();
1142 * Creates a new album for the given Sone.
1145 * The Sone to create the album for
1147 * The parent of the album (may be {@code null} to create a
1149 * @return The new album
1151 public Album createAlbum(Sone sone, Album parent) {
1152 Album album = database.newAlbumBuilder().randomId().by(sone).build();
1153 database.storeAlbum(album);
1154 parent.addAlbum(album);
1159 * Deletes the given album. The owner of the album has to be a local Sone,
1160 * and the album has to be {@link Album#isEmpty() empty} to be deleted.
1163 * The album to remove
1165 public void deleteAlbum(Album album) {
1166 checkNotNull(album, "album must not be null");
1167 checkArgument(album.getSone().isLocal(), "album’s Sone must be a local Sone");
1168 if (!album.isEmpty()) {
1171 album.getParent().removeAlbum(album);
1172 database.removeAlbum(album);
1173 touchConfiguration();
1177 * Creates a new image.
1180 * The Sone creating the image
1182 * The album the image will be inserted into
1183 * @param temporaryImage
1184 * The temporary image to create the image from
1185 * @return The newly created image
1187 public Image createImage(Sone sone, Album album, TemporaryImage temporaryImage) {
1188 checkNotNull(sone, "sone must not be null");
1189 checkNotNull(album, "album must not be null");
1190 checkNotNull(temporaryImage, "temporaryImage must not be null");
1191 checkArgument(sone.isLocal(), "sone must be a local Sone");
1192 checkArgument(sone.equals(album.getSone()), "album must belong to the given Sone");
1193 Image image = database.newImageBuilder().withId(temporaryImage.getId()).build().modify().setSone(sone).setCreationTime(System.currentTimeMillis()).update();
1194 album.addImage(image);
1195 database.storeImage(image);
1196 imageInserter.insertImage(temporaryImage, image);
1201 * Deletes the given image. This method will also delete a matching
1204 * @see #deleteTemporaryImage(String)
1206 * The image to delete
1208 public void deleteImage(Image image) {
1209 checkNotNull(image, "image must not be null");
1210 checkArgument(image.getSone().isLocal(), "image must belong to a local Sone");
1211 deleteTemporaryImage(image.getId());
1212 image.getAlbum().removeImage(image);
1213 database.removeImage(image);
1214 touchConfiguration();
1218 * Creates a new temporary image.
1221 * The MIME type of the temporary image
1223 * The encoded data of the image
1224 * @return The temporary image
1226 public TemporaryImage createTemporaryImage(String mimeType, byte[] imageData) {
1227 TemporaryImage temporaryImage = new TemporaryImage();
1228 temporaryImage.setMimeType(mimeType).setImageData(imageData);
1229 synchronized (temporaryImages) {
1230 temporaryImages.put(temporaryImage.getId(), temporaryImage);
1232 return temporaryImage;
1236 * Deletes the temporary image with the given ID.
1239 * The ID of the temporary image to delete
1241 public void deleteTemporaryImage(String imageId) {
1242 checkNotNull(imageId, "imageId must not be null");
1243 synchronized (temporaryImages) {
1244 temporaryImages.remove(imageId);
1246 Image image = getImage(imageId, false);
1247 if (image != null) {
1248 imageInserter.cancelImageInsert(image);
1253 * Notifies the core that the configuration, either of the core or of a
1254 * single local Sone, has changed, and that the configuration should be
1257 public void touchConfiguration() {
1258 lastConfigurationUpdate = System.currentTimeMillis();
1269 public void serviceStart() {
1270 loadConfiguration();
1271 updateChecker.start();
1272 identityManager.start();
1273 webOfTrustUpdater.init();
1274 webOfTrustUpdater.start();
1275 database.startAsync();
1282 public void serviceRun() {
1283 long lastSaved = System.currentTimeMillis();
1284 while (!shouldStop()) {
1286 long now = System.currentTimeMillis();
1287 if (shouldStop() || ((lastConfigurationUpdate > lastSaved) && ((now - lastConfigurationUpdate) > 5000))) {
1288 for (Sone localSone : getLocalSones()) {
1289 saveSone(localSone);
1291 saveConfiguration();
1301 public void serviceStop() {
1302 localElementTicker.shutdownNow();
1303 synchronized (soneInserters) {
1304 for (Entry<Sone, SoneInserter> soneInserter : soneInserters.entrySet()) {
1305 soneInserter.getValue().stop();
1306 Sone latestSone = getLocalSone(soneInserter.getKey().getId());
1307 saveSone(latestSone);
1310 synchronized (soneRescuers) {
1311 for (SoneRescuer soneRescuer : soneRescuers.values()) {
1315 saveConfiguration();
1316 database.stopAsync();
1317 webOfTrustUpdater.stop();
1318 updateChecker.stop();
1319 soneDownloader.stop();
1320 soneDownloaders.shutdown();
1321 identityManager.stop();
1329 * Saves the given Sone. This will persist all local settings for the given
1330 * Sone, such as the friends list and similar, private options.
1335 private synchronized void saveSone(Sone sone) {
1336 if (!sone.isLocal()) {
1337 logger.log(Level.FINE, String.format("Tried to save non-local Sone: %s", sone));
1340 if (!(sone.getIdentity() instanceof OwnIdentity)) {
1341 logger.log(Level.WARNING, String.format("Local Sone without OwnIdentity found, refusing to save: %s", sone));
1345 logger.log(Level.INFO, String.format("Saving Sone: %s", sone));
1347 /* save Sone into configuration. */
1348 String sonePrefix = "Sone/" + sone.getId();
1349 configuration.getLongValue(sonePrefix + "/Time").setValue(sone.getTime());
1350 configuration.getStringValue(sonePrefix + "/LastInsertFingerprint").setValue(soneInserters.get(sone).getLastInsertFingerprint());
1353 Profile profile = sone.getProfile();
1354 configuration.getStringValue(sonePrefix + "/Profile/FirstName").setValue(profile.getFirstName());
1355 configuration.getStringValue(sonePrefix + "/Profile/MiddleName").setValue(profile.getMiddleName());
1356 configuration.getStringValue(sonePrefix + "/Profile/LastName").setValue(profile.getLastName());
1357 configuration.getIntValue(sonePrefix + "/Profile/BirthDay").setValue(profile.getBirthDay());
1358 configuration.getIntValue(sonePrefix + "/Profile/BirthMonth").setValue(profile.getBirthMonth());
1359 configuration.getIntValue(sonePrefix + "/Profile/BirthYear").setValue(profile.getBirthYear());
1360 configuration.getStringValue(sonePrefix + "/Profile/Avatar").setValue(profile.getAvatar());
1362 /* save profile fields. */
1363 int fieldCounter = 0;
1364 for (Field profileField : profile.getFields()) {
1365 String fieldPrefix = sonePrefix + "/Profile/Fields/" + fieldCounter++;
1366 configuration.getStringValue(fieldPrefix + "/Name").setValue(profileField.getName());
1367 configuration.getStringValue(fieldPrefix + "/Value").setValue(profileField.getValue());
1369 configuration.getStringValue(sonePrefix + "/Profile/Fields/" + fieldCounter + "/Name").setValue(null);
1372 int postCounter = 0;
1373 for (Post post : sone.getPosts()) {
1374 String postPrefix = sonePrefix + "/Posts/" + postCounter++;
1375 configuration.getStringValue(postPrefix + "/ID").setValue(post.getId());
1376 configuration.getStringValue(postPrefix + "/Recipient").setValue(post.getRecipientId().orNull());
1377 configuration.getLongValue(postPrefix + "/Time").setValue(post.getTime());
1378 configuration.getStringValue(postPrefix + "/Text").setValue(post.getText());
1380 configuration.getStringValue(sonePrefix + "/Posts/" + postCounter + "/ID").setValue(null);
1383 int replyCounter = 0;
1384 for (PostReply reply : sone.getReplies()) {
1385 String replyPrefix = sonePrefix + "/Replies/" + replyCounter++;
1386 configuration.getStringValue(replyPrefix + "/ID").setValue(reply.getId());
1387 configuration.getStringValue(replyPrefix + "/Post/ID").setValue(reply.getPostId());
1388 configuration.getLongValue(replyPrefix + "/Time").setValue(reply.getTime());
1389 configuration.getStringValue(replyPrefix + "/Text").setValue(reply.getText());
1391 configuration.getStringValue(sonePrefix + "/Replies/" + replyCounter + "/ID").setValue(null);
1393 /* save post likes. */
1394 int postLikeCounter = 0;
1395 for (String postId : sone.getLikedPostIds()) {
1396 configuration.getStringValue(sonePrefix + "/Likes/Post/" + postLikeCounter++ + "/ID").setValue(postId);
1398 configuration.getStringValue(sonePrefix + "/Likes/Post/" + postLikeCounter + "/ID").setValue(null);
1400 /* save reply likes. */
1401 int replyLikeCounter = 0;
1402 for (String replyId : sone.getLikedReplyIds()) {
1403 configuration.getStringValue(sonePrefix + "/Likes/Reply/" + replyLikeCounter++ + "/ID").setValue(replyId);
1405 configuration.getStringValue(sonePrefix + "/Likes/Reply/" + replyLikeCounter + "/ID").setValue(null);
1407 /* save albums. first, collect in a flat structure, top-level first. */
1408 List<Album> albums = FluentIterable.from(sone.getRootAlbum().getAlbums()).transformAndConcat(Album.FLATTENER).toList();
1410 int albumCounter = 0;
1411 for (Album album : albums) {
1412 String albumPrefix = sonePrefix + "/Albums/" + albumCounter++;
1413 configuration.getStringValue(albumPrefix + "/ID").setValue(album.getId());
1414 configuration.getStringValue(albumPrefix + "/Title").setValue(album.getTitle());
1415 configuration.getStringValue(albumPrefix + "/Description").setValue(album.getDescription());
1416 configuration.getStringValue(albumPrefix + "/Parent").setValue(album.getParent().equals(sone.getRootAlbum()) ? null : album.getParent().getId());
1418 configuration.getStringValue(sonePrefix + "/Albums/" + albumCounter + "/ID").setValue(null);
1421 int imageCounter = 0;
1422 for (Album album : albums) {
1423 for (Image image : album.getImages()) {
1424 if (!image.isInserted()) {
1427 String imagePrefix = sonePrefix + "/Images/" + imageCounter++;
1428 configuration.getStringValue(imagePrefix + "/ID").setValue(image.getId());
1429 configuration.getStringValue(imagePrefix + "/Album").setValue(album.getId());
1430 configuration.getStringValue(imagePrefix + "/Key").setValue(image.getKey());
1431 configuration.getStringValue(imagePrefix + "/Title").setValue(image.getTitle());
1432 configuration.getStringValue(imagePrefix + "/Description").setValue(image.getDescription());
1433 configuration.getLongValue(imagePrefix + "/CreationTime").setValue(image.getCreationTime());
1434 configuration.getIntValue(imagePrefix + "/Width").setValue(image.getWidth());
1435 configuration.getIntValue(imagePrefix + "/Height").setValue(image.getHeight());
1438 configuration.getStringValue(sonePrefix + "/Images/" + imageCounter + "/ID").setValue(null);
1441 configuration.getBooleanValue(sonePrefix + "/Options/AutoFollow").setValue(sone.getOptions().isAutoFollow());
1442 configuration.getBooleanValue(sonePrefix + "/Options/EnableSoneInsertNotifications").setValue(sone.getOptions().isSoneInsertNotificationEnabled());
1443 configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewSones").setValue(sone.getOptions().isShowNewSoneNotifications());
1444 configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewPosts").setValue(sone.getOptions().isShowNewPostNotifications());
1445 configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewReplies").setValue(sone.getOptions().isShowNewReplyNotifications());
1446 configuration.getStringValue(sonePrefix + "/Options/ShowCustomAvatars").setValue(sone.getOptions().getShowCustomAvatars().name());
1447 configuration.getStringValue(sonePrefix + "/Options/LoadLinkedImages").setValue(sone.getOptions().getLoadLinkedImages().name());
1449 webOfTrustUpdater.setProperty((OwnIdentity) sone.getIdentity(), "Sone.LatestEdition", String.valueOf(sone.getLatestEdition()));
1451 logger.log(Level.INFO, String.format("Sone %s saved.", sone));
1452 } catch (ConfigurationException ce1) {
1453 logger.log(Level.WARNING, String.format("Could not save Sone: %s", sone), ce1);
1458 * Saves the current options.
1460 private void saveConfiguration() {
1461 synchronized (configuration) {
1462 if (storingConfiguration) {
1463 logger.log(Level.FINE, "Already storing configuration…");
1466 storingConfiguration = true;
1469 /* store the options first. */
1471 preferences.saveTo(configuration);
1473 /* save known Sones. */
1474 int soneCounter = 0;
1475 synchronized (knownSones) {
1476 for (String knownSoneId : knownSones) {
1477 configuration.getStringValue("KnownSone/" + soneCounter++ + "/ID").setValue(knownSoneId);
1479 configuration.getStringValue("KnownSone/" + soneCounter + "/ID").setValue(null);
1482 /* save known posts. */
1486 Stopwatch stopwatch = Stopwatch.createStarted();
1487 configuration.save();
1488 configurationSaveTimeHistogram.update(stopwatch.elapsed(TimeUnit.MICROSECONDS));
1490 } catch (ConfigurationException ce1) {
1491 logger.log(Level.SEVERE, "Could not store configuration!", ce1);
1492 } catch (DatabaseException de1) {
1493 logger.log(Level.SEVERE, "Could not save database!", de1);
1495 synchronized (configuration) {
1496 storingConfiguration = false;
1502 * Loads the configuration.
1504 private void loadConfiguration() {
1505 new PreferencesLoader(preferences).loadFrom(configuration);
1507 /* load known Sones. */
1508 int soneCounter = 0;
1510 String knownSoneId = configuration.getStringValue("KnownSone/" + soneCounter++ + "/ID").getValue(null);
1511 if (knownSoneId == null) {
1514 synchronized (knownSones) {
1515 knownSones.add(knownSoneId);
1521 * Notifies the core that a new {@link OwnIdentity} was added.
1523 * @param ownIdentityAddedEvent
1527 public void ownIdentityAdded(OwnIdentityAddedEvent ownIdentityAddedEvent) {
1528 OwnIdentity ownIdentity = ownIdentityAddedEvent.getOwnIdentity();
1529 logger.log(Level.FINEST, String.format("Adding OwnIdentity: %s", ownIdentity));
1530 if (ownIdentity.hasContext("Sone")) {
1531 addLocalSone(ownIdentity);
1536 * Notifies the core that an {@link OwnIdentity} was removed.
1538 * @param ownIdentityRemovedEvent
1542 public void ownIdentityRemoved(OwnIdentityRemovedEvent ownIdentityRemovedEvent) {
1543 OwnIdentity ownIdentity = ownIdentityRemovedEvent.getOwnIdentity();
1544 logger.log(Level.FINEST, String.format("Removing OwnIdentity: %s", ownIdentity));
1545 trustedIdentities.removeAll(ownIdentity);
1549 * Notifies the core that a new {@link Identity} was added.
1551 * @param identityAddedEvent
1555 public void identityAdded(IdentityAddedEvent identityAddedEvent) {
1556 Identity identity = identityAddedEvent.getIdentity();
1557 logger.log(Level.FINEST, String.format("Adding Identity: %s", identity));
1558 trustedIdentities.put(identityAddedEvent.getOwnIdentity(), identity);
1559 addRemoteSone(identity);
1563 * Notifies the core that an {@link Identity} was updated.
1565 * @param identityUpdatedEvent
1569 public void identityUpdated(IdentityUpdatedEvent identityUpdatedEvent) {
1570 Identity identity = identityUpdatedEvent.getIdentity();
1571 final Sone sone = getRemoteSone(identity.getId());
1572 if (sone.isLocal()) {
1575 String newLatestEdition = identity.getProperty("Sone.LatestEdition");
1576 if (newLatestEdition != null) {
1577 Long parsedNewLatestEdition = tryParse(newLatestEdition);
1578 if (parsedNewLatestEdition != null) {
1579 sone.setLatestEdition(parsedNewLatestEdition);
1582 soneDownloader.addSone(sone);
1583 soneDownloaders.execute(soneDownloader.fetchSoneAsSskAction(sone));
1587 * Notifies the core that an {@link Identity} was removed.
1589 * @param identityRemovedEvent
1593 public void identityRemoved(IdentityRemovedEvent identityRemovedEvent) {
1594 OwnIdentity ownIdentity = identityRemovedEvent.getOwnIdentity();
1595 Identity identity = identityRemovedEvent.getIdentity();
1596 trustedIdentities.remove(ownIdentity, identity);
1597 for (Entry<OwnIdentity, Collection<Identity>> trustedIdentity : trustedIdentities.asMap().entrySet()) {
1598 if (trustedIdentity.getKey().equals(ownIdentity)) {
1601 if (trustedIdentity.getValue().contains(identity)) {
1605 Sone sone = getSone(identity.getId());
1607 /* TODO - we don’t have the Sone anymore. should this happen? */
1610 for (PostReply postReply : sone.getReplies()) {
1611 eventBus.post(new PostReplyRemovedEvent(postReply));
1613 for (Post post : sone.getPosts()) {
1614 eventBus.post(new PostRemovedEvent(post));
1616 eventBus.post(new SoneRemovedEvent(sone));
1617 database.removeSone(sone);
1621 * Deletes the temporary image.
1623 * @param imageInsertFinishedEvent
1627 public void imageInsertFinished(ImageInsertFinishedEvent imageInsertFinishedEvent) {
1628 logger.log(Level.WARNING, String.format("Image insert finished for %s: %s", imageInsertFinishedEvent.getImage(), imageInsertFinishedEvent.getResultingUri()));
1629 imageInsertFinishedEvent.getImage().modify().setKey(imageInsertFinishedEvent.getResultingUri().toString()).update();
1630 deleteTemporaryImage(imageInsertFinishedEvent.getImage().getId());
1631 touchConfiguration();
1635 class MarkPostKnown implements Runnable {
1637 private final Post post;
1639 public MarkPostKnown(Post post) {
1645 markPostKnown(post);
1651 class MarkReplyKnown implements Runnable {
1653 private final PostReply postReply;
1655 public MarkReplyKnown(PostReply postReply) {
1656 this.postReply = postReply;
1661 markReplyKnown(postReply);