aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/www
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/www')
-rw-r--r--src/main/java/com/juick/www/api/Mastodon.java31
-rw-r--r--src/main/java/com/juick/www/api/activity/Profile.java10
-rw-r--r--src/main/java/com/juick/www/api/activity/helpers/ProfileUriBuilder.java9
3 files changed, 38 insertions, 12 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);
+ }
}
diff --git a/src/main/java/com/juick/www/api/activity/Profile.java b/src/main/java/com/juick/www/api/activity/Profile.java
index b0a39a76..bf4bda25 100644
--- a/src/main/java/com/juick/www/api/activity/Profile.java
+++ b/src/main/java/com/juick/www/api/activity/Profile.java
@@ -256,13 +256,9 @@ public class Profile {
@GetMapping(value = "/n/{mid}-{rid}", produces = { Context.LD_JSON_MEDIA_TYPE, Context.ACTIVITY_MEDIA_TYPE,
Context.ACTIVITYSTREAMS_PROFILE_MEDIA_TYPE, MediaType.APPLICATION_JSON_VALUE })
public Context showNote(@PathVariable int mid, @PathVariable int rid) {
- try {
- Message message = rid > 0 ? messagesService.getReply(mid, rid) : messagesService.getMessage(mid).get();
- if (message != null) {
- return Context.build(activityPubManager.makeNote(message));
- }
- } catch (NoSuchElementException e) {
- throw new HttpNotFoundException();
+ var message = activityPubManager.findMessage(mid, rid);
+ if (message != null) {
+ return Context.build(activityPubManager.makeNote(message));
}
throw new HttpNotFoundException();
}
diff --git a/src/main/java/com/juick/www/api/activity/helpers/ProfileUriBuilder.java b/src/main/java/com/juick/www/api/activity/helpers/ProfileUriBuilder.java
index e10c3078..3f48502b 100644
--- a/src/main/java/com/juick/www/api/activity/helpers/ProfileUriBuilder.java
+++ b/src/main/java/com/juick/www/api/activity/helpers/ProfileUriBuilder.java
@@ -61,9 +61,16 @@ public record ProfileUriBuilder(String baseUri) {
return messageUri(msg.getMid(), msg.getRid());
}
+ public static String messageId(Message msg) {
+ return messageId(msg.getMid(), msg.getRid());
+ }
+ public static String messageId(int mid, int rid) {
+ return String.format("%d-%d", mid, rid);
+ }
+
public String messageUri(int mid, int rid) {
UriComponentsBuilder uri = UriComponentsBuilder.fromUriString(baseUri);
- uri.replacePath(String.format("/n/%d-%d", mid, rid));
+ uri.replacePath("/n/" + messageId(mid, rid));
return uri.toUriString();
}