aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2021-08-24 18:24:33 +0300
committerGravatar Vitaly Takmazov2021-08-24 18:51:29 +0300
commit72aaf2417ecb10696538ab0e0762e732328c64ac (patch)
tree63e093fe5880c94662dc994a9a0b3c8a1d378558 /src
parent8238713c2e37cf58656bb02aa05595ca0bcd87f2 (diff)
ActivityPub: add DirectMessageEvent, fix Undo event
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/juick/service/activities/DirectMessageEvent.java38
-rw-r--r--src/main/java/com/juick/www/api/activity/Profile.java22
2 files changed, 51 insertions, 9 deletions
diff --git a/src/main/java/com/juick/service/activities/DirectMessageEvent.java b/src/main/java/com/juick/service/activities/DirectMessageEvent.java
new file mode 100644
index 00000000..7c396c91
--- /dev/null
+++ b/src/main/java/com/juick/service/activities/DirectMessageEvent.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2008-2021, Juick
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.juick.service.activities;
+
+import com.juick.www.api.activity.model.objects.Note;
+import org.springframework.context.ApplicationEvent;
+
+public class DirectMessageEvent extends ApplicationEvent {
+ private final Note message;
+ /**
+ * Create a new ApplicationEvent.
+ *
+ * @param source the object on which the event initially occurred (never {@code null})
+ */
+ public DirectMessageEvent(Object source, Note message) {
+ super(source);
+ this.message = message;
+ }
+
+ public Note getMessage() {
+ return message;
+ }
+}
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);
}
}
}