From 5b88a7355c554e500199d6c233ae891459b602ac Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 24 Oct 2018 00:31:28 +0300 Subject: Fix deserialisation and tests --- .../src/main/java/com/juick/server/ActivityPubManager.java | 4 ++-- .../main/java/com/juick/server/api/activity/model/Context.java | 2 ++ .../java/com/juick/server/api/activity/model/objects/Mention.java | 6 +++++- .../java/com/juick/server/api/activity/model/objects/Note.java | 8 +++++--- 4 files changed, 14 insertions(+), 6 deletions(-) (limited to 'juick-server/src/main/java/com/juick/server') diff --git a/juick-server/src/main/java/com/juick/server/ActivityPubManager.java b/juick-server/src/main/java/com/juick/server/ActivityPubManager.java index 4a6ed7be..6cfcf377 100644 --- a/juick-server/src/main/java/com/juick/server/ActivityPubManager.java +++ b/juick-server/src/main/java/com/juick/server/ActivityPubManager.java @@ -214,7 +214,7 @@ public class ActivityPubManager implements ActivityListener, NotificationListene attachment.setId(msg.getAttachment().getMedium().getUrl()); attachment.setUrl(msg.getAttachment().getMedium().getUrl()); attachment.setMediaType(HttpUtils.mediaType(msg.getAttachmentType())); - note.setAttachment(attachment); + note.setAttachment(Collections.singletonList(attachment)); } note.setTags(msg.getTags().stream().map(t -> { Hashtag hashtag = new Hashtag(); @@ -222,7 +222,7 @@ public class ActivityPubManager implements ActivityListener, NotificationListene hashtag.setName("#" + t.getName()); return hashtag; }).collect(Collectors.toList())); - if (msg.getReplyToUri().toASCIIString().length() > 0) { + if (msg.getReplyToUri() != null && msg.getReplyToUri().toASCIIString().length() > 0) { Optional createContext = signatureManager.getContext(msg.getReplyToUri()); if (createContext.isPresent()) { Create activity = (Create) createContext.get(); diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/Context.java b/juick-server/src/main/java/com/juick/server/api/activity/model/Context.java index dd67fa64..544f1aa2 100644 --- a/juick-server/src/main/java/com/juick/server/api/activity/model/Context.java +++ b/juick-server/src/main/java/com/juick/server/api/activity/model/Context.java @@ -28,6 +28,8 @@ import java.util.List; @JsonSubTypes.Type(value = Image.class, name = "Image"), @JsonSubTypes.Type(value = Key.class, name = "Key"), @JsonSubTypes.Type(value = Link.class, name = "Link"), + @JsonSubTypes.Type(value = Hashtag.class, name = "Hashtag"), + @JsonSubTypes.Type(value = Mention.class, name = "Mention"), @JsonSubTypes.Type(value = Note.class, name = "Note"), @JsonSubTypes.Type(value = OrderedCollection.class, name = "OrderedCollection"), @JsonSubTypes.Type(value = OrderedCollectionPage.class, name = "OrderedCollectionPage"), diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/objects/Mention.java b/juick-server/src/main/java/com/juick/server/api/activity/model/objects/Mention.java index dbf3bec9..bcb52d37 100644 --- a/juick-server/src/main/java/com/juick/server/api/activity/model/objects/Mention.java +++ b/juick-server/src/main/java/com/juick/server/api/activity/model/objects/Mention.java @@ -1,7 +1,11 @@ package com.juick.server.api.activity.model.objects; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + public class Mention extends Link { - public Mention(String href, String name) { + @JsonCreator + public Mention(@JsonProperty("href") String href, @JsonProperty("name") String name) { this.setHref(href); this.setName(name); } diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/objects/Note.java b/juick-server/src/main/java/com/juick/server/api/activity/model/objects/Note.java index 458b925c..baad2d3b 100644 --- a/juick-server/src/main/java/com/juick/server/api/activity/model/objects/Note.java +++ b/juick-server/src/main/java/com/juick/server/api/activity/model/objects/Note.java @@ -1,5 +1,6 @@ package com.juick.server.api.activity.model.objects; +import com.fasterxml.jackson.annotation.JsonFormat; import com.juick.server.api.activity.model.Context; import java.util.List; @@ -8,7 +9,7 @@ public class Note extends Context { private String content; private String attributedTo; private String inReplyTo; - private Image attachment; + private List attachment; private List to; private List cc; @@ -28,11 +29,12 @@ public class Note extends Context { this.attributedTo = attributedTo; } - public Image getAttachment() { + @JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY) + public List getAttachment() { return attachment; } - public void setAttachment(Image attachment) { + public void setAttachment(List attachment) { this.attachment = attachment; } -- cgit v1.2.3