aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/www/api/Mastodon.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2023-01-09 09:45:12 +0300
committerGravatar Vitaly Takmazov2023-01-09 09:45:12 +0300
commitf6b78c029a1e9e4f09b600131e99bbc13c65f30a (patch)
tree33511c92dd418d1eced2b4755fc16a583c135d06 /src/main/java/com/juick/www/api/Mastodon.java
parent6b08c391d27a682ffece9e9c471986160e2f94af (diff)
Mastodon API: statuses
Diffstat (limited to 'src/main/java/com/juick/www/api/Mastodon.java')
-rw-r--r--src/main/java/com/juick/www/api/Mastodon.java31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/main/java/com/juick/www/api/Mastodon.java b/src/main/java/com/juick/www/api/Mastodon.java
index af1c5ef7..5982209e 100644
--- a/src/main/java/com/juick/www/api/Mastodon.java
+++ b/src/main/java/com/juick/www/api/Mastodon.java
@@ -17,6 +17,7 @@
package com.juick.www.api;
+import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
@@ -298,11 +299,11 @@ public class Mastodon {
))
: List.of();
return new Status(
- String.valueOf(message.getMid()),
+ ProfileUriBuilder.messageId(message),
message.getCreated(),
toAccount(message.getUser()),
- null,
- null,
+ message.getReplyto() > 0 ? ProfileUriBuilder.messageId(message.getMid(), message.getReplyto()) : null,
+ message.getTo().getUid() > 0 ? String.valueOf(message.getTo().getUid()) : null,
MessageUtils.isSensitive(message),
"",
"public",
@@ -314,9 +315,16 @@ public class Mastodon {
@GetMapping("/api/v1/timelines/{timeline}")
public List<Status> publicTimeline(@ModelAttribute User visitor,
@PathVariable String timeline,
- @RequestParam(value = "max_id", required = false, defaultValue = "0") int before,
+ @RequestParam(value = "max_id", required = false) String maxId,
@RequestParam(value = "only_media", required = false, defaultValue = "false") Boolean media) {
List<Integer> mids = List.of();
+ int before = 0;
+ if (maxId != null) {
+ var lastMessage = activityPubManager.findMessage(maxId);
+ if (lastMessage != null) {
+ before = lastMessage.getMid();
+ }
+ }
if (timeline.equals("public")) {
if (media) {
mids = messagesService.getPhotos(visitor.getUid(), before);
@@ -333,4 +341,19 @@ public class Mastodon {
})
.collect(Collectors.toList());
}
+ @GetMapping("/api/v1/statuses/{mid}-{rid}")
+ public Status status(@PathVariable int mid, @PathVariable int rid) {
+ return toStatus(activityPubManager.findMessage(mid, rid));
+ }
+ public record Context(@JsonInclude List<Status> ancestors, @JsonInclude List<Status> descendants) {
+
+ }
+ @GetMapping("/api/v1/statuses/{mid}-{rid}/context")
+ public Context thread(@ModelAttribute User visitor, @PathVariable int mid, @PathVariable int rid) {
+ var thread = messagesService.getReplies(visitor, mid).stream()
+ .filter(m -> m.getRid() > rid)
+ .peek(msg -> msg.getUser().setAvatar(webApp.getAvatarUrl(msg.getUser())))
+ .map(this::toStatus).toList();
+ return new Context(List.of(), thread);
+ }
}