From 9b7d2f44f705830602d1ff4612cc8780c8188aa7 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 5 Sep 2018 15:22:02 +0300 Subject: ActivityStreams: partOf, activity and note id, formatted note content --- .../src/main/java/com/juick/server/api/activity/Profile.java | 12 ++++++++---- .../server/api/activity/model/OrderedCollectionPage.java | 10 ++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) (limited to 'juick-server/src/main') 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 ef55edf1..8072e0d3 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 @@ -6,6 +6,7 @@ import com.juick.server.util.HttpNotFoundException; import com.juick.server.util.UserUtils; import com.juick.service.MessagesService; import com.juick.service.UserService; +import com.juick.util.MessageUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.GetMapping; @@ -79,13 +80,14 @@ public class Profile { User visitor = UserUtils.getCurrentUser(); User user = userService.getUserByName(userName); if (!user.isAnonymous()) { - UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(baseUri); - uriComponentsBuilder.path(String.format("/u/%s/blog", userName)); + UriComponentsBuilder uri = UriComponentsBuilder.fromUriString(baseUri); + uri.path(String.format("/u/%s/blog", userName)); 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.setPublished(m.getTimestamp()); - note.setContent(m.getText()); + note.setContent(MessageUtils.formatMessage(m.getText())); if (StringUtils.isNotBlank(m.getAttachmentType())) { Link attachment = new Link(); attachment.setHref(m.getAttachment().getMedium().getUrl()); @@ -96,9 +98,11 @@ public class Profile { Person person = new Person(); person.setName(user.getName()); OrderedCollectionPage page = new OrderedCollectionPage(); + page.setPartOf(uri.replacePath(String.format("/u/%s/blog", userName)).toUriString()); page.setId(ServletUriComponentsBuilder.fromCurrentRequestUri().toUriString()); page.setOrderedItems(notes.stream().map(a -> { Create create = new Create(); + create.setId(a.getId() + "#Create"); create.setActor(person); create.setObject(a); create.setPublished(a.getPublished()); @@ -107,7 +111,7 @@ public class Profile { int beforeNext = mids.stream().reduce((fst, second) -> second).orElse(0); if (beforeNext > 0) { Link next = new Link(); - next.setHref(uriComponentsBuilder.queryParam("before", beforeNext).toUriString()); + next.setHref(uri.queryParam("before", beforeNext).toUriString()); page.setNext(next); } return page; diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/OrderedCollectionPage.java b/juick-server/src/main/java/com/juick/server/api/activity/model/OrderedCollectionPage.java index 9e03cb79..a36c6c11 100644 --- a/juick-server/src/main/java/com/juick/server/api/activity/model/OrderedCollectionPage.java +++ b/juick-server/src/main/java/com/juick/server/api/activity/model/OrderedCollectionPage.java @@ -4,6 +4,8 @@ import java.util.List; public class OrderedCollectionPage extends ActivityObject { + private String partOf; + private Link next; private List orderedItems; @@ -23,4 +25,12 @@ public class OrderedCollectionPage extends ActivityObject { public void setOrderedItems(List orderedItems) { this.orderedItems = orderedItems; } + + public String getPartOf() { + return partOf; + } + + public void setPartOf(String partOf) { + this.partOf = partOf; + } } -- cgit v1.2.3