aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/www/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/www/api')
-rw-r--r--src/main/java/com/juick/www/api/activity/Profile.java19
1 files changed, 12 insertions, 7 deletions
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 c2b36cbe..618ae387 100644
--- a/src/main/java/com/juick/www/api/activity/Profile.java
+++ b/src/main/java/com/juick/www/api/activity/Profile.java
@@ -77,6 +77,7 @@ import java.io.InputStream;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.List;
+import java.util.NoSuchElementException;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -274,12 +275,15 @@ public class Profile {
@GetMapping(value = "/n/{mid}-{rid}", produces = { Context.LD_JSON_MEDIA_TYPE,
Context.ACTIVITYSTREAMS_PROFILE_MEDIA_TYPE })
public Context showNote(@PathVariable int mid, @PathVariable int rid) {
- if (rid > 0) {
- // reply
- return Context.build(activityPubManager.makeNote(messagesService.getReply(mid, 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();
}
- return Context.build(
- activityPubManager.makeNote(messagesService.getMessage(mid).orElseThrow(IllegalStateException::new)));
+ throw new HttpNotFoundException();
}
@PostMapping(value = "/api/inbox", consumes = { Context.LD_JSON_MEDIA_TYPE,
@@ -362,13 +366,14 @@ public class Profile {
messagesService.updateReplyUri(result.getNewMessage().get(), noteId);
return new ResponseEntity<>(result, HttpStatus.OK);
}
- }
+ }
}
} else {
if (note.getTo().stream().anyMatch(recipient -> recipient.startsWith(baseUri))) {
logger.warn("Possible direct message from {}", note.getAttributedTo());
applicationEventPublisher.publishEvent(new DirectMessageEvent(this, note));
- return new ResponseEntity<>(CommandResult.fromString("Message accepted"), HttpStatus.ACCEPTED);
+ return new ResponseEntity<>(CommandResult.fromString("Message accepted"),
+ HttpStatus.ACCEPTED);
}
}
logger.warn("Request with invalid recipient from {}", activity.getActor());