aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server
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 /juick-server/src/main/java/com/juick/server
parentb3d633cf0e8a6c35be9755702dedbea29ff3d897 (diff)
ActivityStreams initial support
Diffstat (limited to 'juick-server/src/main/java/com/juick/server')
-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
4 files changed, 109 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 {