Store a Sone’s name in its own class, use a modifier to modify a Sone’s name.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / Core.java
index af81054..20983e3 100644 (file)
@@ -62,7 +62,7 @@ import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.PostReply;
 import net.pterodactylus.sone.data.Profile;
 import net.pterodactylus.sone.data.Profile.Field;
-import net.pterodactylus.sone.data.Reply;
+import net.pterodactylus.sone.data.Profile.Name;
 import net.pterodactylus.sone.data.Reply.Modifier.ReplyUpdated;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.data.Sone.ShowCustomAvatars;
@@ -678,7 +678,7 @@ public class Core extends AbstractService implements SoneProvider {
                                }
                                for (PostReply reply : followedSone.get().getReplies()) {
                                        if (reply.getTime() < now) {
-                                               markReplyKnown(reply);
+                                               reply.modify().setKnown().update(Optional.<ReplyUpdated<PostReply>>absent());
                                        }
                                }
                        }
@@ -953,9 +953,10 @@ public class Core extends AbstractService implements SoneProvider {
 
                /* load profile. */
                Profile profile = new Profile(sone);
-               profile.setFirstName(configuration.getStringValue(sonePrefix + "/Profile/FirstName").getValue(null));
-               profile.setMiddleName(configuration.getStringValue(sonePrefix + "/Profile/MiddleName").getValue(null));
-               profile.setLastName(configuration.getStringValue(sonePrefix + "/Profile/LastName").getValue(null));
+               String firstName = configuration.getStringValue(sonePrefix + "/Profile/FirstName").getValue(null);
+               String middleName = configuration.getStringValue(sonePrefix + "/Profile/MiddleName").getValue(null);
+               String lastName = configuration.getStringValue(sonePrefix + "/Profile/LastName").getValue(null);
+               profile.modify().setFirstName(firstName).setMiddleName(middleName).setLastName(lastName).update();
                profile.setBirthDay(configuration.getIntValue(sonePrefix + "/Profile/BirthDay").getValue(null));
                profile.setBirthMonth(configuration.getIntValue(sonePrefix + "/Profile/BirthMonth").getValue(null));
                profile.setBirthYear(configuration.getIntValue(sonePrefix + "/Profile/BirthYear").getValue(null));
@@ -1170,7 +1171,7 @@ public class Core extends AbstractService implements SoneProvider {
                eventBus.post(new MarkPostKnownEvent(post));
                touchConfiguration();
                for (PostReply reply : post.getReplies()) {
-                       markReplyKnown(reply);
+                       reply.modify().setKnown().update(postReplyUpdated());
                }
        }
 
@@ -1220,28 +1221,12 @@ public class Core extends AbstractService implements SoneProvider {
                        logger.log(Level.FINE, String.format("Tried to delete non-local reply: %s", reply));
                        return;
                }
+               postReplyUpdated().get().replyUpdated(reply);
                database.removePostReply(reply);
-               markReplyKnown(reply);
-               sone.removeReply(reply);
                touchConfiguration();
        }
 
        /**
-        * Marks the given reply as known, if it is currently not a known reply
-        * (according to {@link Reply#isKnown()}).
-        *
-        * @param reply
-        *              The reply to mark as known
-        */
-       public void markReplyKnown(PostReply reply) {
-               boolean previouslyKnown = reply.isKnown();
-               reply.modify().setKnown().update(postReplyUpdated());
-               if (!previouslyKnown) {
-                       touchConfiguration();
-               }
-       }
-
-       /**
         * Creates a new image.
         *
         * @param sone
@@ -1844,7 +1829,7 @@ public class Core extends AbstractService implements SoneProvider {
                                                 */
                                                @Override
                                                public void run() {
-                                                       markReplyKnown(postReply);
+                                                       postReplyUpdated().get().replyUpdated(postReply);
                                                }
                                        }, 10, TimeUnit.SECONDS);
                                }