aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/juick/www/api/activity/Profile.java19
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java3
2 files changed, 15 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());
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java
index 3ba5d7e3..8583642f 100644
--- a/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/src/test/java/com/juick/server/tests/ServerTests.java
@@ -1849,6 +1849,9 @@ public class ServerTests {
.get();
json = jsonMapper.writeValueAsString(Context.build(
activityPubManager.makeNote(messagesService.getReply(replyToExt.getMid(), replyToExt.getRid()))));
+ mockMvc.perform(get("/n/2-0")).andExpect(status().isOk());
+ mockMvc.perform(get("/n/2222-0")).andExpect(status().isNotFound());
+ mockMvc.perform(get("/n/2-14")).andExpect(status().isNotFound());
}
@Test