From d1569d9d2b6474fc7f6b3bb590d13ea04094b3fd Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 4 Jan 2023 07:32:19 +0300 Subject: ActivityPub: handle Note updates by Note id --- src/main/java/com/juick/www/api/activity/Profile.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/main/java/com') 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 2ba9b0a0..4dcd4910 100644 --- a/src/main/java/com/juick/www/api/activity/Profile.java +++ b/src/main/java/com/juick/www/api/activity/Profile.java @@ -385,15 +385,20 @@ public class Profile { } if (activity.getObject() instanceof Note) { Note note = (Note) activity.getObject(); + logger.info("Got update to {}", note.getId()); if (activity.getActor().equals(note.getAttributedTo())) { - Message reply = messagesService.getReplyByUri(activity.getObject().getUrl()); - if (messagesService.updateMessage(reply.getMid(), reply.getRid(), formatNote(note), true)) { - logger.info("{} update they message {}", activity.getActor(), note.getId()); - return new ResponseEntity<>(HttpStatus.ACCEPTED); + Message reply = messagesService.getReplyByUri(note.getId()); + if (reply != null) { + if (messagesService.updateMessage(reply.getMid(), reply.getRid(), formatNote(note), true)) { + logger.info("{} update they message {}", activity.getActor(), note.getId()); + return new ResponseEntity<>(HttpStatus.ACCEPTED); + } + logger.warn("Unable to update {}", note.getId()); + return new ResponseEntity<>(HttpStatus.SERVICE_UNAVAILABLE); + } else { + logger.warn("Update not found: {}", note.getId()); + return new ResponseEntity<>(HttpStatus.NOT_FOUND); } - ; - logger.warn("Unable to update {}", activity.getObject().getId()); - return new ResponseEntity<>(HttpStatus.SERVICE_UNAVAILABLE); } else { logger.warn("Invalid Update: {}", jsonMapper.writeValueAsString(activity)); return new ResponseEntity<>(HttpStatus.BAD_REQUEST); -- cgit v1.2.3