From 72aaf2417ecb10696538ab0e0762e732328c64ac Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 24 Aug 2021 18:24:33 +0300 Subject: ActivityPub: add DirectMessageEvent, fix Undo event --- .../java/com/juick/www/api/activity/Profile.java | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/main/java/com/juick/www') 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 cf5fb843..eb8909b5 100644 --- a/src/main/java/com/juick/www/api/activity/Profile.java +++ b/src/main/java/com/juick/www/api/activity/Profile.java @@ -48,6 +48,7 @@ import com.juick.www.WebApp; import com.juick.service.MessagesService; import com.juick.service.UserService; import com.juick.service.activities.AnnounceEvent; +import com.juick.service.activities.DirectMessageEvent; import com.juick.service.activities.FollowEvent; import com.juick.service.activities.UndoAnnounceEvent; import com.juick.service.activities.UndoFollowEvent; @@ -297,17 +298,15 @@ public class Profile { } if (activity instanceof Undo) { - Map object = (Map) activity.getObject(); - String objectType = (String) object.get("type"); - String objectObject = (String) object.get("object"); - if (objectType.equals("Follow")) { + Activity object = (Activity) activity.getObject(); + if (object instanceof Follow) { applicationEventPublisher - .publishEvent(new UndoFollowEvent(this, activity.getActor(), objectObject)); + .publishEvent(new UndoFollowEvent(this, activity.getActor(), object.getObject().getId())); return new ResponseEntity<>(CommandResult.fromString("Undo follow request accepted"), HttpStatus.OK); - } else if (objectType.equals("Like") || objectType.equals("Announce")) { + } else if (object instanceof Like || object instanceof Announce) { applicationEventPublisher - .publishEvent(new UndoAnnounceEvent(this, activity.getActor(), objectObject)); + .publishEvent(new UndoAnnounceEvent(this, activity.getActor(), object.getObject().getId())); return new ResponseEntity<>(CommandResult.fromString("Undo like/announce request accepted"), HttpStatus.OK); } @@ -364,10 +363,15 @@ public class Profile { if (result.getNewMessage().isPresent()) { messagesService.updateReplyUri(result.getNewMessage().get(), noteId); return new ResponseEntity<>(result, HttpStatus.OK); - } else { - return new ResponseEntity<>(result, HttpStatus.BAD_REQUEST); } } + return new ResponseEntity<>(CommandResult.fromString("Invalid recipient"), HttpStatus.BAD_REQUEST); + } + } 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); } } } -- cgit v1.2.3