- if (hasSone(sone.getId())) {
- boolean soneRescueMode = isLocalSone(sone) && preferences.isSoneRescueMode();
- Sone storedSone = getSone(sone.getId());
- if (!soneRescueMode && !(sone.getTime() > storedSone.getTime())) {
- logger.log(Level.FINE, "Downloaded Sone %s is not newer than stored Sone %s.", new Object[] { sone, storedSone });
- return;
- }
- synchronized (posts) {
- if (!soneRescueMode) {
- for (Post post : storedSone.getPosts()) {
- posts.remove(post.getId());
- if (!sone.getPosts().contains(post)) {
- coreListenerManager.firePostRemoved(post);
- }
- }
- }
- List<Post> storedPosts = storedSone.getPosts();
- synchronized (newPosts) {
- for (Post post : sone.getPosts()) {
- post.setSone(storedSone);
- if (!storedPosts.contains(post) && !knownPosts.contains(post.getId())) {
- newPosts.add(post.getId());
- coreListenerManager.fireNewPostFound(post);
- }
- posts.put(post.getId(), post);
- }
- }
- }
- synchronized (replies) {
- if (!soneRescueMode) {
- for (Reply reply : storedSone.getReplies()) {
- replies.remove(reply.getId());
- if (!sone.getReplies().contains(reply)) {
- coreListenerManager.fireReplyRemoved(reply);
- }
- }
- }
- Set<Reply> storedReplies = storedSone.getReplies();
- synchronized (newReplies) {
- for (Reply reply : sone.getReplies()) {
- reply.setSone(storedSone);
- if (!storedReplies.contains(reply) && !knownReplies.contains(reply.getId())) {
- newReplies.add(reply.getId());
- coreListenerManager.fireNewReplyFound(reply);
- }
- replies.put(reply.getId(), reply);
- }
- }
- }
- synchronized (storedSone) {
- if (!soneRescueMode || (sone.getTime() > storedSone.getTime())) {
- storedSone.setTime(sone.getTime());
- }
- storedSone.setClient(sone.getClient());
- storedSone.setProfile(sone.getProfile());
- if (soneRescueMode) {
- for (Post post : sone.getPosts()) {
- storedSone.addPost(post);
- }
- for (Reply reply : sone.getReplies()) {
- storedSone.addReply(reply);
- }
- for (String likedPostId : sone.getLikedPostIds()) {
- storedSone.addLikedPostId(likedPostId);
- }
- for (String likedReplyId : sone.getLikedReplyIds()) {
- storedSone.addLikedReplyId(likedReplyId);
- }
- } else {
- storedSone.setPosts(sone.getPosts());
- storedSone.setReplies(sone.getReplies());
- storedSone.setLikePostIds(sone.getLikedPostIds());
- storedSone.setLikeReplyIds(sone.getLikedReplyIds());
- }
- storedSone.setLatestEdition(sone.getLatestEdition());
- }
- }
- }
-
- /**
- * Deletes the given Sone. This will remove the Sone from the
- * {@link #getLocalSone(String) local Sones}, stops its {@link SoneInserter}
- * and remove the context from its identity.
- *
- * @param sone
- * The Sone to delete
- */
- public void deleteSone(Sone sone) {
- if (!(sone.getIdentity() instanceof OwnIdentity)) {
- logger.log(Level.WARNING, "Tried to delete Sone of non-own identity: %s", sone);
- return;
- }
- synchronized (localSones) {
- if (!localSones.containsKey(sone.getId())) {
- logger.log(Level.WARNING, "Tried to delete non-local Sone: %s", sone);
- return;
- }
- localSones.remove(sone.getId());
- soneInserters.remove(sone).stop();
- }
- try {
- ((OwnIdentity) sone.getIdentity()).removeContext("Sone");
- ((OwnIdentity) sone.getIdentity()).removeProperty("Sone.LatestEdition");
- } catch (WebOfTrustException wote1) {
- logger.log(Level.WARNING, "Could not remove context and properties from Sone: " + sone, wote1);
- }
- try {
- configuration.getLongValue("Sone/" + sone.getId() + "/Time").setValue(null);
- } catch (ConfigurationException ce1) {
- logger.log(Level.WARNING, "Could not remove Sone from configuration!", ce1);
- }
- }
-
- /**
- * Marks the given Sone as known. If the Sone was {@link #isNewPost(String)
- * new} before, a {@link CoreListener#markSoneKnown(Sone)} event is fired.
- *
- * @param sone
- * The Sone to mark as known
- */
- public void markSoneKnown(Sone sone) {
- synchronized (newSones) {
- if (newSones.remove(sone.getId())) {
- knownSones.add(sone.getId());
- coreListenerManager.fireMarkSoneKnown(sone);
- saveConfiguration();
- }
- }