aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2021-08-27 13:27:05 +0300
committerGravatar Vitaly Takmazov2021-08-27 13:27:05 +0300
commit174c1af0738a3839586aa3b932540ad9c0c9537b (patch)
treeb4ef03446920a385a3ce1d817c7040c0c05182b5 /src/main/java
parent41ed7f3739d89ac1f5f77c36aaca36ea4c261601 (diff)
ActivityPub: respond with NOT_FOUND when message is not found
Diffstat (limited to 'src/main/java')
-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());