From 7edffb4478bdeae16b009bced9d6769d0cb50a3b Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 17 Jan 2011 10:39:55 +0100 Subject: [PATCH] Rewrite isNewSone() to match isNewPost() and isNewReply(). --- .../java/net/pterodactylus/sone/core/Core.java | 38 ++++++++++++++++------ .../pterodactylus/sone/template/SoneAccessor.java | 2 +- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 8cf8834..22ab47b 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -494,20 +494,38 @@ public class Core implements IdentityListener, UpdateListener { } /** - * Returns whether the given Sone is a new Sone. After this check, the Sone - * is marked as known, i.e. a second call with the same parameters will - * always yield {@code false}. + * Returns whether the Sone with the given ID is a new Sone. After this + * check, the Sone is marked as known, i.e. a second call with the same + * parameters will always yield {@code false}. * - * @param sone - * The sone to check for + * @param soneId + * The ID of the sone to check for * @return {@code true} if the given Sone is new, false otherwise */ - public boolean isNewSone(Sone sone) { + public boolean isNewSone(String soneId) { + return isNewSone(soneId, true); + } + + /** + * Returns whether the Sone with the given ID is a new Sone. The Sone will + * be marked as known if {@code markAsKnown} is {@code true}, otherwise the + * Sone will keep its current “new” state. + * + * @param soneId + * The ID of the sone to check for + * @param markAsKnown + * {@code true} to mark the Sone as known in any case, + * {@code false} to not mark it as known + * @return {@code true} if the given Sone is new, false otherwise + */ + public boolean isNewSone(String soneId, boolean markAsKnown) { synchronized (newSones) { - boolean isNew = !knownSones.contains(sone.getId()) && newSones.remove(sone.getId()); - knownSones.add(sone.getId()); - if (isNew) { - coreListenerManager.fireMarkSoneKnown(sone); + boolean isNew = !knownSones.contains(soneId) && newSones.contains(soneId); + if (markAsKnown) { + Sone sone = getSone(soneId, false); + if (sone != null) { + markSoneKnown(sone); + } } return isNew; } diff --git a/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java b/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java index 52424e6..ac4ab28 100644 --- a/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java +++ b/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java @@ -94,7 +94,7 @@ public class SoneAccessor extends ReflectionAccessor { } else if (member.equals("downloading")) { return core.getSoneStatus(sone) == SoneStatus.downloading; } else if (member.equals("new")) { - return core.isNewSone(sone); + return core.isNewSone(sone.getId(), false); } else if (member.equals("locked")) { return core.isLocked(sone); } else if (member.equals("trust")) { -- 2.7.4