Fix error message.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / Core.java
index a4b3569..a3c8dc4 100644 (file)
@@ -540,6 +540,23 @@ public class Core extends AbstractService {
        }
 
        /**
+        * Gets all Sones that like the given reply.
+        *
+        * @param reply
+        *            The reply to check for
+        * @return All Sones that like the reply
+        */
+       public Set<Sone> getLikes(final Reply reply) {
+               return Filters.filteredSet(getSones(), new Filter<Sone>() {
+
+                       @Override
+                       public boolean filterObject(Sone sone) {
+                               return sone.isLikedReplyId(reply.getId());
+                       }
+               });
+       }
+
+       /**
         * Deletes the given reply. It is removed from its Sone and from the reply
         * cache.
         *
@@ -673,6 +690,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 +802,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);