Save the configuration after storing all values.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / Core.java
index 33c4dbb..1f89196 100644 (file)
@@ -84,7 +84,7 @@ public class Core implements IdentityListener {
        private final CoreListenerManager coreListenerManager = new CoreListenerManager(this);
 
        /** The configuration. */
-       private final Configuration configuration;
+       private Configuration configuration;
 
        /** The identity manager. */
        private final IdentityManager identityManager;
@@ -190,6 +190,18 @@ public class Core implements IdentityListener {
        //
 
        /**
+        * Sets the configuration to use. This will automatically save the current
+        * configuration to the given configuration.
+        *
+        * @param configuration
+        *            The new configuration to use
+        */
+       public void setConfiguration(Configuration configuration) {
+               this.configuration = configuration;
+               saveConfiguration();
+       }
+
+       /**
         * Returns the options used by the core.
         *
         * @return The options of the core
@@ -851,7 +863,9 @@ public class Core implements IdentityListener {
                                }
                        }
                        synchronized (storedSone) {
-                               storedSone.setTime(sone.getTime());
+                               if (!soneRescueMode || (sone.getTime() > storedSone.getTime())) {
+                                       storedSone.setTime(sone.getTime());
+                               }
                                storedSone.setClient(sone.getClient());
                                storedSone.setProfile(sone.getProfile());
                                if (soneRescueMode) {
@@ -873,7 +887,7 @@ public class Core implements IdentityListener {
                                        storedSone.setLikePostIds(sone.getLikedPostIds());
                                        storedSone.setLikeReplyIds(sone.getLikedReplyIds());
                                }
-                               storedSone.setLatestEdition(sone.getRequestUri().getEdition());
+                               storedSone.setLatestEdition(sone.getLatestEdition());
                        }
                }
        }
@@ -1366,6 +1380,9 @@ public class Core implements IdentityListener {
                                configuration.getStringValue("KnownReplies/" + replyCounter + "/ID").setValue(null);
                        }
 
+                       /* now save it. */
+                       configuration.save();
+
                } catch (ConfigurationException ce1) {
                        logger.log(Level.SEVERE, "Could not store configuration!", ce1);
                }