aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-10-05 12:57:43 +0300
committerGravatar Vitaly Takmazov2018-10-05 13:00:08 +0300
commit25e10eabde194dd75d3f91d2ed5683f1858cf7e1 (patch)
tree6caccf6101fedbc22165a915926715ecc32d923b /juick-server/src/main/java/com/juick/server
parent2379429b534ff5d93cb54f835e95a059fa5f3fc9 (diff)
ActivityPub: web urls for Note and Person
Diffstat (limited to 'juick-server/src/main/java/com/juick/server')
-rw-r--r--juick-server/src/main/java/com/juick/server/ActivityPubManager.java6
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/Profile.java17
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/Context.java9
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/Image.java9
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/Person.java9
5 files changed, 20 insertions, 30 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 3a32b4e5..77f96347 100644
--- a/juick-server/src/main/java/com/juick/server/ActivityPubManager.java
+++ b/juick-server/src/main/java/com/juick/server/ActivityPubManager.java
@@ -2,6 +2,7 @@ package com.juick.server;
import com.juick.Message;
import com.juick.User;
+import com.juick.formatters.PlainTextFormatter;
import com.juick.server.api.activity.model.Image;
import com.juick.server.api.activity.model.Link;
import com.juick.server.api.activity.model.Note;
@@ -151,6 +152,10 @@ public class ActivityPubManager implements ActivityListener, NotificationListene
UriComponentsBuilder uri = UriComponentsBuilder.fromUriString(baseUri);
return uri.replacePath(String.format("/u/%s", user.getName())).toUriString();
}
+ public String personWebUri(User user) {
+ UriComponentsBuilder uri = UriComponentsBuilder.fromUriString(baseUri);
+ return uri.replacePath(String.format("/%s/", user.getName())).toUriString();
+ }
public String followersUri(User user) {
UriComponentsBuilder uri = UriComponentsBuilder.fromUriString(baseUri);
@@ -181,6 +186,7 @@ public class ActivityPubManager implements ActivityListener, NotificationListene
public Note makeNote(Message msg) {
Note note = new Note();
note.setId(messageUri(msg));
+ note.setUrl(PlainTextFormatter.formatUrl(msg));
note.setAttributedTo(personUri(msg.getUser()));
if (MessageUtils.isReply(msg)) {
note.setInReplyTo(messageUri(msg.getMid(), msg.getReplyto()));
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/Profile.java b/juick-server/src/main/java/com/juick/server/api/activity/Profile.java
index 160270f4..98d2ba9d 100644
--- a/juick-server/src/main/java/com/juick/server/api/activity/Profile.java
+++ b/juick-server/src/main/java/com/juick/server/api/activity/Profile.java
@@ -68,7 +68,7 @@ public class Profile {
if (!user.isAnonymous()) {
Person person = new Person();
person.setId(activityPubManager.personUri(user));
- person.setUrl(activityPubManager.personUri(user));
+ person.setUrl(activityPubManager.personWebUri(user));
person.setName(userName);
person.setPreferredUsername(userName);
Key publicKey = new Key();
@@ -113,11 +113,8 @@ public class Profile {
if (!user.isAnonymous()) {
UriComponentsBuilder uri = UriComponentsBuilder.fromUriString(baseUri);
String personUri = uri.path(String.format("/u/%s", userName)).toUriString();
- String followersUri = activityPubManager.followersUri(user);
List<Integer> mids = messagesService.getUserBlog(user.getUid(), 0, before);
List<Note> notes = messagesService.getMessages(visitor, mids).stream().map(activityPubManager::makeNote).collect(Collectors.toList());
- Person person = new Person();
- person.setName(user.getName());
OrderedCollectionPage page = new OrderedCollectionPage();
page.setPartOf(uri.replacePath(String.format("/u/%s/blog/toc", userName)).toUriString());
page.setFirst(uri.replacePath(String.format("/u/%s/blog", userName)).toUriString());
@@ -165,15 +162,13 @@ public class Profile {
List<User> followers = userService.getUserReaders(user.getUid());
Stream<User> followersPage = followers.stream().skip(20 * page).limit(20);
- Person person = new Person();
- person.setName(user.getName());
OrderedCollectionPage result = new OrderedCollectionPage();
result.setId(ServletUriComponentsBuilder.fromCurrentRequestUri().toUriString());
result.setOrderedItems(followersPage.map(a -> {
Person follower = new Person();
follower.setName(a.getName());
- person.setPreferredUsername(a.getName());
- follower.setUrl(uriComponentsBuilder.replacePath(String.format("/u/%s", a.getName())).toUriString());
+ follower.setPreferredUsername(a.getName());
+ follower.setUrl(activityPubManager.personWebUri(a));
return follower;
}).collect(Collectors.toList()));
boolean hasNext = followers.size() <= 20 * page;
@@ -209,15 +204,13 @@ public class Profile {
List<User> following = userService.getUserFriends(user.getUid());
Stream<User> followingPage = following.stream().skip(20 * page).limit(20);
- Person person = new Person();
- person.setName(user.getName());
- person.setPreferredUsername(user.getName());
OrderedCollectionPage result = new OrderedCollectionPage();
result.setId(ServletUriComponentsBuilder.fromCurrentRequestUri().toUriString());
result.setOrderedItems(followingPage.map(a -> {
Person follower = new Person();
follower.setName(a.getName());
- follower.setUrl(uriComponentsBuilder.replacePath(String.format("/u/%s", a.getName())).toUriString());
+ follower.setPreferredUsername(a.getName());
+ follower.setUrl(activityPubManager.personWebUri(a));
return follower;
}).collect(Collectors.toList()));
boolean hasNext = following.size() <= 20 * page;
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 9eb03c6f..2bc499aa 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
@@ -36,6 +36,7 @@ public abstract class Context {
private Instant published;
+ private String url;
private List<String> to;
@@ -81,4 +82,12 @@ public abstract class Context {
response.context = Arrays.asList(ACTIVITY_STREAMS_URI, SECURITY_URI);
return response;
}
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
}
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/Image.java b/juick-server/src/main/java/com/juick/server/api/activity/model/Image.java
index c8f869a5..07d6ff99 100644
--- a/juick-server/src/main/java/com/juick/server/api/activity/model/Image.java
+++ b/juick-server/src/main/java/com/juick/server/api/activity/model/Image.java
@@ -2,7 +2,6 @@ package com.juick.server.api.activity.model;
public class Image extends Context {
private String mediaType;
- private String url;
public String getMediaType() {
return mediaType;
@@ -11,12 +10,4 @@ public class Image extends Context {
public void setMediaType(String mediaType) {
this.mediaType = mediaType;
}
-
- public String getUrl() {
- return url;
- }
-
- public void setUrl(String url) {
- this.url = url;
- }
}
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
index 8a817c18..00006d4f 100644
--- 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
@@ -11,7 +11,6 @@ public class Person extends Context {
private String outbox;
private String following;
private String followers;
- private String url;
private Key publicKey;
@Override
@@ -68,14 +67,6 @@ public class Person extends Context {
this.followers = followers;
}
- public String getUrl() {
- return url;
- }
-
- public void setUrl(String url) {
- this.url = url;
- }
-
@JsonTypeInfo(use = JsonTypeInfo.Id.NONE)
public Key getPublicKey() {
return publicKey;