aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-09-04 12:25:14 +0300
committerGravatar Vitaly Takmazov2018-09-04 12:25:14 +0300
commit5c491c20f8201b1a90335899aa0f2eb72ed0daff (patch)
treedd4f7857f0a3745030e08eea999676a8cbc462be
parentb3d633cf0e8a6c35be9755702dedbea29ff3d897 (diff)
ActivityStreams initial support
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/Info.java44
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/ActivityObject.java18
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/Person.java47
-rw-r--r--juick-server/src/main/java/com/juick/server/api/webfinger/Resource.java1
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java8
5 files changed, 117 insertions, 1 deletions
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/Info.java b/juick-server/src/main/java/com/juick/server/api/activity/Info.java
new file mode 100644
index 00000000..4cff15c1
--- /dev/null
+++ b/juick-server/src/main/java/com/juick/server/api/activity/Info.java
@@ -0,0 +1,44 @@
+package com.juick.server.api.activity;
+
+import com.juick.User;
+import com.juick.server.api.activity.model.ActivityObject;
+import com.juick.server.api.activity.model.Person;
+import com.juick.server.util.HttpNotFoundException;
+import com.juick.service.UserService;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.util.UriComponentsBuilder;
+
+import javax.inject.Inject;
+
+@RestController
+public class Info {
+ @Inject
+ private UserService userService;
+ @Value("${web_domain:localhost}")
+ private String domain;
+ @Value("${ap_base_uri:http://localhost:8080/}")
+ private String baseUri;
+ @Value("${img_url:http://localhost:8080/i/}")
+ private String baseImagesUri;
+
+ @GetMapping(value = "/u/{userName}", produces = ActivityObject.CONTENT_TYPE)
+ public Person getUser(@PathVariable String userName) {
+ User user = userService.getUserByName(userName);
+ if (!user.isAnonymous()) {
+ Person person = new Person();
+ UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(baseUri);
+ builder.path(String.format("/u/%s", userName));
+ person.setId(builder.toUriString());
+ person.setName(userName);
+ person.setOutbox(builder.path(String.format("/u/%s/blog", userName)).toUriString());
+ UriComponentsBuilder imgBuilder = UriComponentsBuilder.fromUriString(baseImagesUri);
+ imgBuilder.path(String.format("/a/%d.png", user.getUid()));
+ person.setIcon(imgBuilder.toUriString());
+ return person;
+ }
+ throw new HttpNotFoundException();
+ }
+}
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/ActivityObject.java b/juick-server/src/main/java/com/juick/server/api/activity/model/ActivityObject.java
new file mode 100644
index 00000000..bc682d2b
--- /dev/null
+++ b/juick-server/src/main/java/com/juick/server/api/activity/model/ActivityObject.java
@@ -0,0 +1,18 @@
+package com.juick.server.api.activity.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public abstract class ActivityObject {
+
+ public abstract String getId();
+
+ public abstract String getType();
+
+ @JsonProperty("@context")
+ public String getContext() {
+ return CONTEXT_URI;
+ }
+
+ public final static String CONTEXT_URI = "https://www.w3.org/ns/activitystreams";
+ public final static String CONTENT_TYPE = "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"";
+}
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/Person.java b/juick-server/src/main/java/com/juick/server/api/activity/model/Person.java
new file mode 100644
index 00000000..031cd73b
--- /dev/null
+++ b/juick-server/src/main/java/com/juick/server/api/activity/model/Person.java
@@ -0,0 +1,47 @@
+package com.juick.server.api.activity.model;
+
+public class Person extends ActivityObject {
+
+ private String id;
+ private String name;
+ private String icon;
+ private String outbox;
+
+ @Override
+ public String getId() {
+ return id;
+ }
+
+ @Override
+ public String getType() {
+ return "Person";
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getIcon() {
+ return icon;
+ }
+
+ public void setIcon(String icon) {
+ this.icon = icon;
+ }
+
+ public String getOutbox() {
+ return outbox;
+ }
+
+ public void setOutbox(String outbox) {
+ this.outbox = outbox;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+}
diff --git a/juick-server/src/main/java/com/juick/server/api/webfinger/Resource.java b/juick-server/src/main/java/com/juick/server/api/webfinger/Resource.java
index e43e02d1..d3829de4 100644
--- a/juick-server/src/main/java/com/juick/server/api/webfinger/Resource.java
+++ b/juick-server/src/main/java/com/juick/server/api/webfinger/Resource.java
@@ -14,7 +14,6 @@ import rocks.xmpp.addr.Jid;
import javax.inject.Inject;
import java.util.Arrays;
-import java.util.Collections;
@RestController
public class Resource {
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 9a4fb93a..63ba4b3e 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
@@ -23,6 +23,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.jayway.jsonpath.JsonPath;
import com.juick.*;
import com.juick.server.*;
+import com.juick.server.api.activity.model.ActivityObject;
import com.juick.server.component.MessageEvent;
import com.juick.server.helpers.AnonymousUser;
import com.juick.server.helpers.CommandResult;
@@ -1332,4 +1333,11 @@ public class ServerTests {
mockMvc.perform(get("/.well-known/webfinger?resource=acct:durov@localhost"))
.andExpect(status().isNotFound());
}
+ @Test
+ public void userProfilesShouldBeExposedAsActivityStream() throws Exception {
+ mockMvc.perform(get("/u/ugnich").accept(ActivityObject.CONTENT_TYPE))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.@context", is(ActivityObject.CONTEXT_URI)))
+ .andExpect(jsonPath("$.icon", is("http://localhost:8080/i/a/1.png")));
+ }
}