aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/Profile.java42
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/ActivityObject.java12
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/model/OrderedCollection.java6
3 files changed, 44 insertions, 16 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 4a44db3b..0b8db1fc 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
@@ -55,40 +55,56 @@ public class Profile {
}
throw new HttpNotFoundException();
}
- @GetMapping(value = "/u/{userName}/blog", produces = ActivityObject.CONTENT_TYPE)
- public OrderedCollection getOutbox(
- @PathVariable String userName,
- @RequestParam(required = false, defaultValue = "0") int before) {
+ @GetMapping(value = "/u/{userName}/blog/toc", produces = ActivityObject.CONTENT_TYPE)
+ public OrderedCollection getOutbox(@PathVariable String userName) {
User visitor = UserUtils.getCurrentUser();
User user = userService.getUserByName(userName);
if (!user.isAnonymous()) {
ServletUriComponentsBuilder uriComponentsBuilder = ServletUriComponentsBuilder.fromCurrentRequestUri();
OrderedCollection blog = new OrderedCollection();
blog.setId(uriComponentsBuilder.toUriString());
+ blog.setTotalItems(userService.getStatsMessages(user.getUid()));
+ Link first = new Link();
+ uriComponentsBuilder.path(String.format("/u/%s/blog", userName));
+ first.setHref(uriComponentsBuilder.toUriString());
+ blog.setFirst(first);
+ return blog;
+ }
+ throw new HttpNotFoundException();
+ }
+ @GetMapping(value = "/u/{userName}/blog", produces = ActivityObject.CONTENT_TYPE)
+ public OrderedCollectionPage getOutboxPage(@PathVariable String userName,
+ @RequestParam(required = false, defaultValue = "0") int before) {
+ User visitor = UserUtils.getCurrentUser();
+ User user = userService.getUserByName(userName);
+ if (!user.isAnonymous()) {
+ ServletUriComponentsBuilder uriComponentsBuilder = ServletUriComponentsBuilder.fromCurrentRequestUri();
List<Integer> mids = messagesService.getUserBlog(user.getUid(), 0, before);
List<Article> articles = messagesService.getMessages(visitor, mids).stream().map(m -> {
- Article article = new Article();
- article.setContent(m.getText());
- return article;
+ Article article = new Article();
+ article.setPublished(m.getTimestamp());
+ article.setContent(m.getText());
+ return article;
}).collect(Collectors.toList());
- OrderedCollectionPage first = new OrderedCollectionPage();
- first.setId(uriComponentsBuilder.toUriString());
Person person = new Person();
person.setName(user.getName());
- first.setOrderedItems(articles.stream().map(a -> {
+ OrderedCollectionPage page = new OrderedCollectionPage();
+ page.setOrderedItems(articles.stream().map(a -> {
Create create = new Create();
create.setActor(person);
create.setObject(a);
+ create.setPublished(a.getPublished());
return create;
}).collect(Collectors.toList()));
int beforeNext = mids.stream().reduce((fst, second) -> second).orElse(0);
if (beforeNext > 0) {
Link next = new Link();
next.setHref(uriComponentsBuilder.queryParam("before", beforeNext).toUriString());
- first.setNext(next);
+ page.setNext(next);
}
- blog.setFirst(first);
- return blog;
+
+ page.setId(uriComponentsBuilder.toUriString());
+ return page;
}
throw new HttpNotFoundException();
}
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/ActivityObject.java b/juick-server/src/main/java/com/juick/server/api/activity/model/ActivityObject.java
index 981079f8..c4672936 100644
--- a/juick-server/src/main/java/com/juick/server/api/activity/model/ActivityObject.java
+++ b/juick-server/src/main/java/com/juick/server/api/activity/model/ActivityObject.java
@@ -2,10 +2,14 @@ package com.juick.server.api.activity.model;
import com.fasterxml.jackson.annotation.JsonProperty;
+import java.time.Instant;
+
public abstract class ActivityObject {
private String id;
+ private Instant published;
+
public String getId() {
return id;
}
@@ -25,4 +29,12 @@ public abstract class ActivityObject {
public final static String CONTEXT_URI = "https://www.w3.org/ns/activitystreams";
public final static String CONTENT_TYPE = "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"";
+
+ public Instant getPublished() {
+ return published;
+ }
+
+ public void setPublished(Instant published) {
+ this.published = published;
+ }
}
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/model/OrderedCollection.java b/juick-server/src/main/java/com/juick/server/api/activity/model/OrderedCollection.java
index 84654b19..d4f6b7c5 100644
--- a/juick-server/src/main/java/com/juick/server/api/activity/model/OrderedCollection.java
+++ b/juick-server/src/main/java/com/juick/server/api/activity/model/OrderedCollection.java
@@ -11,13 +11,13 @@ public class OrderedCollection extends ActivityObject {
public void setTotalItems(int totalItems) {
this.totalItems = totalItems;
}
- private OrderedCollectionPage first;
+ private Link first;
- public OrderedCollectionPage getFirst() {
+ public Link getFirst() {
return first;
}
- public void setFirst(OrderedCollectionPage first) {
+ public void setFirst(Link first) {
this.first = first;
}
}