private Map<String, Sone> remoteSones = new HashMap<String, Sone>();
/** All new Sones. */
- private Set<Sone> newSones = new HashSet<Sone>();
+ private Set<String> newSones = new HashSet<String>();
/** All known Sones. */
/* synchronize access on {@link #newSones}. */
- private Set<Sone> knownSones = new HashSet<Sone>();
+ private Set<String> knownSones = new HashSet<String>();
/** All posts. */
private Map<String, Post> posts = new HashMap<String, Post>();
*/
public boolean isNewSone(Sone sone) {
synchronized (newSones) {
- boolean isNew = !knownSones.contains(sone) && newSones.remove(sone);
- knownSones.add(sone);
+ boolean isNew = !knownSones.contains(sone.getId()) && newSones.remove(sone.getId());
+ knownSones.add(sone.getId());
return isNew;
}
}
sone.setLatestEdition(Numbers.safeParseLong(identity.getProperty("Sone.LatestEdition"), (long) 0));
if (newSone) {
synchronized (newSones) {
- newSones.add(sone);
+ newSones.add(sone.getId());
}
}
remoteSones.put(identity.getId(), sone);
}
/* load friends. */
- Set<Sone> friends = new HashSet<Sone>();
+ Set<String> friends = new HashSet<String>();
while (true) {
String friendId = configuration.getStringValue(sonePrefix + "/Friends/" + friends.size() + "/ID").getValue(null);
if (friendId == null) {
break;
}
- Boolean friendLocal = configuration.getBooleanValue(sonePrefix + "/Friends/" + friends.size() + "/Local").getValue(null);
- if (friendLocal == null) {
- logger.log(Level.WARNING, "Invalid friend found, aborting load!");
- return;
- }
- friends.add(friendLocal ? getLocalSone(friendId) : getRemoteSone(friendId));
+ friends.add(friendId);
}
/* if we’re still here, Sone was loaded successfully. */
sone.setModificationCounter(soneModificationCounter);
}
synchronized (newSones) {
- for (Sone friend : friends) {
+ for (String friend : friends) {
knownSones.add(friend);
}
}
/* save friends. */
int friendCounter = 0;
- for (Sone friend : sone.getFriends()) {
- configuration.getStringValue(sonePrefix + "/Friends/" + friendCounter + "/ID").setValue(friend.getId());
- configuration.getBooleanValue(sonePrefix + "/Friends/" + friendCounter++ + "/Local").setValue(friend.getInsertUri() != null);
+ for (String friend : sone.getFriends()) {
+ configuration.getStringValue(sonePrefix + "/Friends/" + friendCounter + "/ID").setValue(friend);
}
configuration.getStringValue(sonePrefix + "/Friends/" + friendCounter + "/ID").setValue(null);
break;
}
synchronized (newSones) {
- knownSones.add(getRemoteSone(knownSoneId));
+ knownSones.add(knownSoneId);
}
}
}
/* save known Sones. */
int soneCounter = 0;
synchronized (newSones) {
- for (Sone knownSone : knownSones) {
- configuration.getStringValue("KnownSone/" + soneCounter++ + "/ID").setValue(knownSone.getId());
+ for (String knownSoneId : knownSones) {
+ configuration.getStringValue("KnownSone/" + soneCounter++ + "/ID").setValue(knownSoneId);
}
configuration.getStringValue("KnownSone/" + soneCounter + "/ID").setValue(null);
}
private volatile Profile profile;
/** All friend Sones. */
- private final Set<Sone> friendSones = Collections.synchronizedSet(new HashSet<Sone>());
+ private final Set<String> friendSones = Collections.synchronizedSet(new HashSet<String>());
/** All posts. */
private final Set<Post> posts = Collections.synchronizedSet(new HashSet<Post>());
*
* @return The friend Sones of this Sone
*/
- public List<Sone> getFriends() {
- List<Sone> friends = new ArrayList<Sone>(friendSones);
- Collections.sort(friends, NICE_NAME_COMPARATOR);
+ public List<String> getFriends() {
+ List<String> friends = new ArrayList<String>(friendSones);
return friends;
}
* The new (and only) friends of this Sone
* @return This Sone (for method chaining)
*/
- public Sone setFriends(Collection<Sone> friends) {
+ public Sone setFriends(Collection<String> friends) {
friendSones.clear();
friendSones.addAll(friends);
return this;
* The friend Sone to add
* @return This Sone (for method chaining)
*/
- public Sone addFriend(Sone friendSone) {
- if (!friendSone.equals(this)) {
+ public Sone addFriend(String friendSone) {
+ if (!friendSone.equals(id)) {
friendSones.add(friendSone);
}
return this;
String soneId = request.getHttpRequest().getPartAsStringFailsafe("sone", 44);
String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 64);
Sone currentSone = getCurrentSone(request.getToadletContext());
- Sone sone = webInterface.getCore().getSone(soneId);
- if (!sone.equals(currentSone)) {
- currentSone.addFriend(sone);
- webInterface.getCore().saveSone(currentSone);
- }
+ currentSone.addFriend(soneId);
+ webInterface.getCore().saveSone(currentSone);
throw new RedirectException(returnPage);
}
}
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Comparator;
import java.util.List;
import net.pterodactylus.sone.data.Post;
Sone sone = getCurrentSone(request.getToadletContext());
List<Post> allPosts = new ArrayList<Post>();
allPosts.addAll(sone.getPosts());
- for (Sone friendSone : sone.getFriends()) {
- allPosts.addAll(friendSone.getPosts());
- }
- Collections.sort(allPosts, new Comparator<Post>() {
-
- @Override
- public int compare(Post leftPost, Post rightPost) {
- return (int) Math.max(Integer.MIN_VALUE, Math.min(Integer.MAX_VALUE, rightPost.getTime() - leftPost.getTime()));
+ for (String friendSoneId : sone.getFriends()) {
+ if (!webInterface.getCore().hasSone(friendSoneId)) {
+ continue;
}
-
- });
+ allPosts.addAll(webInterface.getCore().getSone(friendSoneId).getPosts());
+ }
+ Collections.sort(allPosts, Post.TIME_COMPARATOR);
template.set("posts", allPosts);
}
@Override
protected JsonObject createJsonObject(Request request) {
String soneId = request.getHttpRequest().getParam("sone");
- Sone sone = webInterface.getCore().getSone(soneId);
- if (sone == null) {
+ if (!webInterface.getCore().hasSone(soneId)) {
return new JsonObject().put("success", false).put("error", "invalid-sone-id");
}
Sone currentSone = getCurrentSone(request.getToadletContext());
if (currentSone == null) {
return new JsonObject().put("success", false).put("error", "auth-required");
}
- currentSone.addFriend(sone);
+ currentSone.addFriend(soneId);
webInterface.getCore().saveSone(currentSone);
return new JsonObject().put("success", true);
}