X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffcp%2FAbstractSoneCommand.java;h=f3e29232e4777762cf5d3e164de9429bb99a496c;hb=6326513ecf086da2a2909a0d2a61913078b2870a;hp=6473e4da0660e5fc64b2330db22aca60e4767fea;hpb=1155e00836b6d71915c13d849cb48f264c07a9d8;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java b/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java index 6473e4d..f3e2923 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java +++ b/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java @@ -172,6 +172,7 @@ public abstract class AbstractSoneCommand extends AbstractCommand { } postBuilder.put(prefix + "Time", post.getTime()); postBuilder.put(prefix + "Text", post.getText()); + postBuilder.put(encodeLikes(core.getLikes(post), prefix + "Likes.")); if (includeReplies) { List replies = core.getReplies(post); @@ -236,4 +237,28 @@ public abstract class AbstractSoneCommand extends AbstractCommand { return replyBuilder.get(); } + /** + * Creates a simple field set from the given collection of Sones that like + * an element. + * + * @param likes + * The liking Sones + * @param prefix + * The prefix for the field names (may be empty but not + * {@code null}) + * @return The simple field set containing the likes + */ + protected SimpleFieldSet encodeLikes(Collection likes, String prefix) { + SimpleFieldSetBuilder likesBuilder = new SimpleFieldSetBuilder(); + + int likeIndex = 0; + likesBuilder.put(prefix + "Count", likes.size()); + for (Sone sone : likes) { + String sonePrefix = prefix + likeIndex++ + "."; + likesBuilder.put(sonePrefix + "ID", sone.getId()); + } + + return likesBuilder.get(); + } + }