aboutsummaryrefslogtreecommitdiff
path: root/juick-server
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-10-24 00:31:28 +0300
committerGravatar Vitaly Takmazov2018-10-24 00:34:42 +0300
commit5b88a7355c554e500199d6c233ae891459b602ac (patch)
treecca19bfa8fa75e06debf1b072e979be68035fab7 /juick-server
parent8e6d764d6bb4391532e5376c795f634ee3898872 (diff)
Fix deserialisation and tests
Diffstat (limited to 'juick-server')
-rw-r--r--juick-server/src/main/java/com/juick/server/ActivityPubManager.java4
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/Context.java2
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/objects/Mention.java6
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/objects/Note.java8
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java6
-rw-r--r--juick-server/src/test/resources/mention.json62
6 files changed, 80 insertions, 8 deletions
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<Context> 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<Image> attachment;
private List<String> to;
private List<String> 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<Image> getAttachment() {
return attachment;
}
- public void setAttachment(Image attachment) {
+ public void setAttachment(List<Image> attachment) {
this.attachment = attachment;
}
diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
index 8a49d96a..cf189799 100644
--- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
@@ -1705,16 +1705,18 @@ public class ServerTests {
Delete delete = jsonMapper.readValue(deleteJsonStr, Delete.class);
int mid = messagesService.createMessage(ugnich.getUid(), "YO", "", null);
User extUser = new User();
- extUser.setUri(URI.create("https://ext.social/users/xwatt"));
+ extUser.setUri(URI.create("http://localhost:8080/users/xwatt"));
int rid = messagesService.createReply(mid, 0, extUser, "PEOPLE", null);
Message replyFromExt = messagesService.getReply(mid, rid);
- String extMessageUri = "https://ext.social/statuses/12345";
+ String extMessageUri = "http://localhost:8080/statuses/12345";
messagesService.updateReplyUri(replyFromExt, URI.create(extMessageUri));
int rid2 = messagesService.createReply(mid, rid, ugnich, "HI", null);
Message replyToExt = messagesService.getReply(mid, rid2);
Note replyNote = activityPubManager.makeNote(replyToExt);
assertThat(replyNote.getInReplyTo(), equalTo(extMessageUri));
+ String noteStr = IOUtils.toString(URI.create("classpath:mention.json"), StandardCharsets.UTF_8);
+ Note create2 = jsonMapper.readValue(noteStr, Note.class);
}
@Test
public void activitySerialization() throws JsonProcessingException {
diff --git a/juick-server/src/test/resources/mention.json b/juick-server/src/test/resources/mention.json
new file mode 100644
index 00000000..c51265f1
--- /dev/null
+++ b/juick-server/src/test/resources/mention.json
@@ -0,0 +1,62 @@
+{
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://w3id.org/security/v1",
+ {
+ "manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
+ "sensitive": "as:sensitive",
+ "movedTo": {
+ "@id": "as:movedTo",
+ "@type": "@id"
+ },
+ "Hashtag": "as:Hashtag",
+ "ostatus": "http://ostatus.org#",
+ "atomUri": "ostatus:atomUri",
+ "inReplyToAtomUri": "ostatus:inReplyToAtomUri",
+ "conversation": "ostatus:conversation",
+ "toot": "http://joinmastodon.org/ns#",
+ "Emoji": "toot:Emoji",
+ "focalPoint": {
+ "@container": "@list",
+ "@id": "toot:focalPoint"
+ },
+ "featured": {
+ "@id": "toot:featured",
+ "@type": "@id"
+ },
+ "schema": "http://schema.org#",
+ "PropertyValue": "schema:PropertyValue",
+ "value": "schema:value"
+ }
+ ],
+ "id": "https://mastodonsocial.ru/users/inhosin/statuses/100946127454503070",
+ "type": "Note",
+ "summary": null,
+ "inReplyTo": "https://juick.com/n/2923741-40",
+ "published": "2018-10-23T17:27:45Z",
+ "url": "https://mastodonsocial.ru/@inhosin/100946127454503070",
+ "attributedTo": "https://mastodonsocial.ru/users/inhosin",
+ "to": [
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "cc": [
+ "https://mastodonsocial.ru/users/inhosin/followers",
+ "https://juick.com/u/vt"
+ ],
+ "sensitive": false,
+ "atomUri": "https://mastodonsocial.ru/users/inhosin/statuses/100946127454503070",
+ "inReplyToAtomUri": "https://juick.com/n/2923741-40",
+ "conversation": "tag:mastodonsocial.ru,2018-10-16:objectId=609790:objectType=Conversation",
+ "content": "<p><span class=\"h-card\"><a href=\"https://juick.com/vt/\" class=\"u-url mention\">@<span>vt</span></a></span> а лайки между серверами ходят? И ещё вопрос: нельзя всёже в ответ транслировать ник, чтобы нотификация поступала, а то приходится лопатить ленту что искать ответы. Я сейчас тоже с ActivityPub ковыряюсь.</p>",
+ "contentMap": {
+ "ru": "<p><span class=\"h-card\"><a href=\"https://juick.com/vt/\" class=\"u-url mention\">@<span>vt</span></a></span> а лайки между серверами ходят? И ещё вопрос: нельзя всёже в ответ транслировать ник, чтобы нотификация поступала, а то приходится лопатить ленту что искать ответы. Я сейчас тоже с ActivityPub ковыряюсь.</p>"
+ },
+ "attachment": [],
+ "tag": [
+ {
+ "type": "Mention",
+ "href": "https://juick.com/u/vt",
+ "name": "@vt@juick.com"
+ }
+ ]
+} \ No newline at end of file