From 2f972edbba5e37499982b017e51d1d7c471f2307 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 5 Sep 2018 15:41:25 +0300 Subject: ActivityStreams: to, attributedTo --- .../src/main/java/com/juick/server/api/activity/Profile.java | 8 +++++++- .../main/java/com/juick/server/api/activity/model/Create.java | 11 +++++++++++ .../main/java/com/juick/server/api/activity/model/Note.java | 11 +++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) (limited to 'juick-server/src/main/java/com/juick/server') 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 8072e0d3..a0804d2c 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 @@ -17,6 +17,7 @@ import org.springframework.web.servlet.support.ServletUriComponentsBuilder; import org.springframework.web.util.UriComponentsBuilder; import javax.inject.Inject; +import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -81,11 +82,15 @@ public class Profile { User user = userService.getUserByName(userName); if (!user.isAnonymous()) { UriComponentsBuilder uri = UriComponentsBuilder.fromUriString(baseUri); - uri.path(String.format("/u/%s/blog", userName)); + String blogUri = uri.path(String.format("/u/%s/blog/toc", userName)).toUriString(); + String followersUri = uri.path(String.format("/u/%s/followers/toc", userName)).toUriString(); List mids = messagesService.getUserBlog(user.getUid(), 0, before); List 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(blogUri); + note.setTo(Arrays.asList(followersUri, + "https://www.w3.org/ns/activitystreams#Public")); note.setPublished(m.getTimestamp()); note.setContent(MessageUtils.formatMessage(m.getText())); if (StringUtils.isNotBlank(m.getAttachmentType())) { @@ -103,6 +108,7 @@ public class Profile { page.setOrderedItems(notes.stream().map(a -> { Create create = new Create(); create.setId(a.getId() + "#Create"); + create.setTo(a.getTo()); create.setActor(person); create.setObject(a); create.setPublished(a.getPublished()); diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/Create.java b/juick-server/src/main/java/com/juick/server/api/activity/model/Create.java index 8d81b26b..60ad4ae3 100644 --- a/juick-server/src/main/java/com/juick/server/api/activity/model/Create.java +++ b/juick-server/src/main/java/com/juick/server/api/activity/model/Create.java @@ -1,9 +1,12 @@ package com.juick.server.api.activity.model; +import java.util.List; + public class Create extends ActivityObject { private Person actor; private Note object; + private List to; public Person getActor() { return actor; @@ -20,4 +23,12 @@ public class Create extends ActivityObject { public void setObject(Note object) { this.object = object; } + + public List getTo() { + return to; + } + + public void setTo(List to) { + this.to = to; + } } 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 ae799f5e..8a34c926 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,9 +1,12 @@ package com.juick.server.api.activity.model; +import java.util.List; + public class Note extends ActivityObject { private String content; private String attributedTo; private Link attachment; + private List to; public String getContent() { return content; @@ -28,4 +31,12 @@ public class Note extends ActivityObject { public void setAttachment(Link attachment) { this.attachment = attachment; } + + public List getTo() { + return to; + } + + public void setTo(List to) { + this.to = to; + } } -- cgit v1.2.3