aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server/api
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-10-04 12:18:42 +0300
committerGravatar Vitaly Takmazov2018-10-04 09:35:24 +0000
commit5be22ee8963cf45190b13b41dc2dac7b7b0bfb01 (patch)
tree2ace48b2d11decb816638514157f71269c95e791 /juick-server/src/main/java/com/juick/server/api
parent7f9187d8a87a5cd6e2720eac0d03f1c2fcc507ed (diff)
ActivityPub: persist followers and forward message event to them
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/api')
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/Profile.java36
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/Note.java5
2 files changed, 16 insertions, 25 deletions
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 656d85dd..7b854d52 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
@@ -1,6 +1,7 @@
package com.juick.server.api.activity;
import com.juick.User;
+import com.juick.server.ActivityPubManager;
import com.juick.server.KeystoreManager;
import com.juick.server.SignatureManager;
import com.juick.server.api.activity.model.*;
@@ -43,6 +44,8 @@ public class Profile {
@Inject
private SignatureManager signatureManager;
@Inject
+ private ActivityPubManager activityPubManager;
+ @Inject
private ApplicationEventPublisher applicationEventPublisher;
@Value("${web_domain:localhost}")
private String domain;
@@ -55,11 +58,9 @@ public class Profile {
public Person getUser(@PathVariable String userName) {
User user = userService.getUserByName(userName);
if (!user.isAnonymous()) {
- UriComponentsBuilder uri = UriComponentsBuilder.fromUriString(baseUri);
Person person = new Person();
- uri.replacePath(String.format("/u/%s", userName));
- person.setId(uri.toUriString());
- person.setUrl(uri.toUriString());
+ person.setId(activityPubManager.personUri(user));
+ person.setUrl(activityPubManager.personUri(user));
person.setName(userName);
person.setPreferredUsername(userName);
Key publicKey = new Key();
@@ -67,11 +68,10 @@ public class Profile {
publicKey.setOwner(person.getId());
publicKey.setPublicKeyPem(keystoreManager.getPublicKeyPem());
person.setPublicKey(publicKey);
- uri.replacePath("/api/inbox");
- person.setInbox(uri.toUriString());
- person.setOutbox(uri.replacePath(String.format("/u/%s/blog/toc", userName)).toUriString());
- person.setFollowers(uri.replacePath(String.format("/u/%s/followers/toc", userName)).toUriString());
- person.setFollowing(uri.replacePath(String.format("/u/%s/following/toc", userName)).toUriString());
+ person.setInbox(activityPubManager.inboxUri());
+ person.setOutbox(activityPubManager.outboxUri(user));
+ person.setFollowers(activityPubManager.followersUri(user));
+ person.setFollowing(activityPubManager.followingUri(user));
UriComponentsBuilder image = UriComponentsBuilder.fromUriString(baseImagesUri);
image.path(String.format("/a/%d.png", user.getUid()));
Image avatar = new Image();
@@ -103,23 +103,9 @@ public class Profile {
if (!user.isAnonymous()) {
UriComponentsBuilder uri = UriComponentsBuilder.fromUriString(baseUri);
String personUri = uri.path(String.format("/u/%s", userName)).toUriString();
- String followersUri = uri.replacePath(String.format("/u/%s/followers/toc", 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(m -> {
- Note note = new Note();
- note.setId(uri.replacePath(String.format("/m/%d", m.getMid())).toUriString());
- note.setAttributedTo(personUri);
- note.setTo(Collections.singletonList("https://www.w3.org/ns/activitystreams#Public"));
- note.setCc(Collections.singletonList(followersUri));
- note.setPublished(m.getTimestamp());
- note.setContent(MessageUtils.formatMessage(m.getText()));
- if (StringUtils.isNotBlank(m.getAttachmentType())) {
- Link attachment = new Link();
- attachment.setHref(m.getAttachment().getMedium().getUrl());
- note.setAttachment(attachment);
- }
- return note;
- }).collect(Collectors.toList());
+ 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();
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/Note.java b/juick-server/src/main/java/com/juick/server/api/activity/model/Note.java
index ff64c4b9..c15cd8d3 100644
--- a/juick-server/src/main/java/com/juick/server/api/activity/model/Note.java
+++ b/juick-server/src/main/java/com/juick/server/api/activity/model/Note.java
@@ -1,5 +1,10 @@
package com.juick.server.api.activity.model;
+import com.juick.Message;
+import com.juick.util.MessageUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.Collections;
import java.util.List;
public class Note extends Context {