Remove Sone following time if last local Sone unfollows
[Sone.git] / src / main / java / net / pterodactylus / sone / database / memory / MemoryFriendDatabase.java
index a2d51a3..692d7c4 100644 (file)
@@ -66,6 +66,13 @@ class MemoryFriendDatabase {
                try {
                        if (soneFriends.remove(localSoneId, friendSoneId)) {
                                configurationLoader.saveFriends(localSoneId, soneFriends.get(localSoneId));
                try {
                        if (soneFriends.remove(localSoneId, friendSoneId)) {
                                configurationLoader.saveFriends(localSoneId, soneFriends.get(localSoneId));
+                               boolean unfollowedSoneStillFollowed = false;
+                               for (String soneId : soneFriends.keys()) {
+                                       unfollowedSoneStillFollowed |= getFriends(soneId).contains(friendSoneId);
+                               }
+                               if (!unfollowedSoneStillFollowed) {
+                                       configurationLoader.removeSoneFollowingTime(friendSoneId);
+                               }
                        }
                } finally {
                        lock.writeLock().unlock();
                        }
                } finally {
                        lock.writeLock().unlock();