Persist likes replies over plugin restarts.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 23 Oct 2010 11:23:38 +0000 (13:23 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 23 Oct 2010 11:23:38 +0000 (13:23 +0200)
src/main/java/net/pterodactylus/sone/core/Core.java

index a4b3569..8bf2cea 100644 (file)
@@ -673,6 +673,17 @@ public class Core extends AbstractService {
                                        sone.addLikedPostId(likedPostId);
                                }
 
+                               /* load liked reply IDs. */
+                               int likedReplyIdCounter = 0;
+                               while (true) {
+                                       String likedReplyIdPrefix = sonePrefix + "/LikedReplyId." + likedReplyIdCounter++;
+                                       String likedReplyId = configuration.getStringValue(likedReplyIdPrefix + "/ID").getValue(null);
+                                       if (likedReplyId == null) {
+                                               break;
+                                       }
+                                       sone.addLikedReplyId(likedReplyId);
+                               }
+
                                sone.setModificationCounter(modificationCounter);
                                addLocalSone(sone);
                        } catch (MalformedURLException mue1) {
@@ -774,6 +785,14 @@ public class Core extends AbstractService {
                                }
                                configuration.getStringValue(sonePrefix + "/LikedPostId." + likedPostIdCounter + "/ID").setValue(null);
 
+                               /* write all liked replies. */
+                               int likedReplyIdCounter = 0;
+                               for (String soneLikedReplyId : sone.getLikedReplyIds()) {
+                                       String likedReplyIdPrefix = sonePrefix + "/LikedReplyId." + likedReplyIdCounter++;
+                                       configuration.getStringValue(likedReplyIdPrefix + "/ID").setValue(soneLikedReplyId);
+                               }
+                               configuration.getStringValue(sonePrefix + "/LikedReplyId." + likedReplyIdCounter + "/ID").setValue(null);
+
                        }
                        /* write null ID as terminator. */
                        configuration.getStringValue("Sone/Sone." + soneId + "/ID").setValue(null);