diff options
author | Vitaly Takmazov | 2018-10-04 17:29:17 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-10-04 17:43:44 +0300 |
commit | e2b09858835ca0a956b83a2eb78a621693640389 (patch) | |
tree | b429ca4b32cf696d0eadef53473a9b0c4ec24e82 /juick-server/src/main/java/com/juick | |
parent | 57526badc0913195fa7996e49da9cd4e54b6c1ca (diff) |
ActivityPub: fix uri fragments in posts
Diffstat (limited to 'juick-server/src/main/java/com/juick')
-rw-r--r-- | juick-server/src/main/java/com/juick/server/ActivityPubManager.java | 33 |
1 files changed, 23 insertions, 10 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 49895bc8..e590f4f9 100644 --- a/juick-server/src/main/java/com/juick/server/ActivityPubManager.java +++ b/juick-server/src/main/java/com/juick/server/ActivityPubManager.java @@ -38,13 +38,6 @@ public class ActivityPubManager implements ActivityListener, NotificationListene @Value("${ap_base_uri:http://localhost:8080/}") private String baseUri; - private UriComponentsBuilder uri; - - @PostConstruct - public void init() { - uri = UriComponentsBuilder.fromUriString(baseUri); - } - @Override public void processFollowEvent(@Nonnull FollowEvent followEvent) { String acct = (String)followEvent.getRequest().getObject(); @@ -132,32 +125,52 @@ public class ActivityPubManager implements ActivityListener, NotificationListene } public String inboxUri() { + UriComponentsBuilder uri = UriComponentsBuilder.fromUriString(baseUri); return uri.replacePath("/api/inbox").toUriString(); } public String outboxUri(User user) { + UriComponentsBuilder uri = UriComponentsBuilder.fromUriString(baseUri); return uri.replacePath(String.format("/u/%s/blog/toc", user.getName())).toUriString(); } public String personUri(User user) { + UriComponentsBuilder uri = UriComponentsBuilder.fromUriString(baseUri); return uri.replacePath(String.format("/u/%s", user.getName())).toUriString(); } public String followersUri(User user) { + UriComponentsBuilder uri = UriComponentsBuilder.fromUriString(baseUri); return uri.replacePath(String.format("/u/%s/followers/toc", user.getName())).toUriString(); } public String followingUri(User user) { + UriComponentsBuilder uri = UriComponentsBuilder.fromUriString(baseUri); return uri.replacePath(String.format("/u/%s/following/toc", user.getName())).toUriString(); } + public String messageUri(Message msg) { + UriComponentsBuilder uri = UriComponentsBuilder.fromUriString(baseUri); + uri.replacePath(String.format("/m/%d", msg.getMid())); + if (MessageUtils.isReply(msg)) { + uri.fragment(String.valueOf(msg.getRid())); + } + return uri.toUriString(); + } + public String messageUri(int mid, int rid) { + UriComponentsBuilder uri = UriComponentsBuilder.fromUriString(baseUri); + uri.replacePath(String.format("/m/%d", mid)); + if (rid > 0) { + uri.fragment(String.valueOf(rid)); + } + return uri.toUriString(); + } public Note makeNote(Message msg) { Note note = new Note(); - note.setId(uri.replacePath(String.format("/m/%d", msg.getMid())).toUriString()); + note.setId(messageUri(msg)); note.setAttributedTo(personUri(msg.getUser())); if (MessageUtils.isReply(msg)) { - uri.replacePath(String.format("/m/%d#%d", msg.getMid(), msg.getRid())).toUriString(); - note.setInReplyTo(uri.replacePath(String.format("/m/%d#%d", msg.getMid(), msg.getReplyto())).toUriString()); + note.setInReplyTo(messageUri(msg.getMid(), msg.getReplyto())); } if (MessageUtils.isPM(msg)) { note.setTo(Collections.singletonList(activityPubManager.personUri(msg.getTo()))); |