From 3896f8c0877d4f935fce8a9c8e4109cfeb3e7203 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 23 Oct 2010 13:23:38 +0200 Subject: [PATCH] Persist likes replies over plugin restarts. --- src/main/java/net/pterodactylus/sone/core/Core.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index a4b3569..8bf2cea 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -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); -- 2.7.4