aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server/src/main')
-rw-r--r--juick-server/src/main/java/com/juick/server/ActivityPubManager.java29
-rw-r--r--juick-server/src/main/java/com/juick/server/CommandsManager.java5
-rw-r--r--juick-server/src/main/java/com/juick/service/activities/ActivityListener.java2
-rw-r--r--juick-server/src/main/java/com/juick/service/activities/DeleteMessageEvent.java21
4 files changed, 52 insertions, 5 deletions
diff --git a/juick-server/src/main/java/com/juick/server/ActivityPubManager.java b/juick-server/src/main/java/com/juick/server/ActivityPubManager.java
index c05deb15..49895bc8 100644
--- a/juick-server/src/main/java/com/juick/server/ActivityPubManager.java
+++ b/juick-server/src/main/java/com/juick/server/ActivityPubManager.java
@@ -7,11 +7,9 @@ import com.juick.server.api.activity.model.Note;
import com.juick.server.api.activity.model.Person;
import com.juick.server.api.activity.model.activities.Accept;
import com.juick.server.api.activity.model.activities.Create;
+import com.juick.server.api.activity.model.activities.Delete;
import com.juick.service.SocialService;
-import com.juick.service.activities.ActivityListener;
-import com.juick.service.activities.DeleteUserEvent;
-import com.juick.service.activities.FollowEvent;
-import com.juick.service.activities.UndoFollowEvent;
+import com.juick.service.activities.*;
import com.juick.service.component.*;
import com.juick.util.MessageUtils;
import org.apache.commons.lang3.StringUtils;
@@ -88,6 +86,29 @@ public class ActivityPubManager implements ActivityListener, NotificationListene
}
@Override
+ public void deleteMessageEvent(DeleteMessageEvent event) {
+ Message msg = event.getMessage();
+ User user = msg.getUser();
+ String userUri = personUri(user);
+ Note note = makeNote(msg);
+ Person me = (Person) signatureManager.getContext(URI.create(userUri)).get();
+ socialService.getFollowers(user).forEach(acct -> {
+ Person follower = (Person) signatureManager.getContext(URI.create(acct)).get();
+ Delete delete = new Delete();
+ delete.setId(note.getId());
+ delete.setActor(me.getId());
+ delete.setPublished(note.getPublished());
+ delete.setObject(note);
+ try {
+ logger.info("Deletion to follower {}", follower.getId());
+ signatureManager.post(me, follower, delete);
+ } catch (IOException e) {
+ logger.warn("activitypub exception", e);
+ }
+ });
+ }
+
+ @Override
public void processMessageEvent(MessageEvent messageEvent) {
Message msg = messageEvent.getMessage();
User user = msg.getUser();
diff --git a/juick-server/src/main/java/com/juick/server/CommandsManager.java b/juick-server/src/main/java/com/juick/server/CommandsManager.java
index e9cf11de..297e986f 100644
--- a/juick-server/src/main/java/com/juick/server/CommandsManager.java
+++ b/juick-server/src/main/java/com/juick/server/CommandsManager.java
@@ -21,6 +21,7 @@ import com.juick.Message;
import com.juick.Tag;
import com.juick.User;
import com.juick.formatters.PlainTextFormatter;
+import com.juick.service.activities.DeleteMessageEvent;
import com.juick.service.component.*;
import com.juick.model.CommandResult;
import com.juick.model.TagStats;
@@ -446,7 +447,9 @@ public class CommandsManager {
@UserCommand(pattern = "^D #(\\d+)$", help = "D #1234 - Delete post", patternFlags = Pattern.CASE_INSENSITIVE)
public CommandResult commandDeletePost(User user, URI attachment, String... args) {
int mid = Integer.valueOf(args[0]);
- if (messagesService.deleteMessage(user.getUid(), mid)) {
+ Message message = messagesService.getMessage(mid);
+ if (message != null && messagesService.deleteMessage(user.getUid(), mid)) {
+ applicationEventPublisher.publishEvent(new DeleteMessageEvent(this, message));
return CommandResult.fromString("Message deleted");
}
return CommandResult.fromString("This is not your message");
diff --git a/juick-server/src/main/java/com/juick/service/activities/ActivityListener.java b/juick-server/src/main/java/com/juick/service/activities/ActivityListener.java
index 01baeea9..3174ff23 100644
--- a/juick-server/src/main/java/com/juick/service/activities/ActivityListener.java
+++ b/juick-server/src/main/java/com/juick/service/activities/ActivityListener.java
@@ -9,4 +9,6 @@ public interface ActivityListener {
void undoFollowEvent(UndoFollowEvent event);
@EventListener
void deleteUserEvent(DeleteUserEvent event);
+ @EventListener
+ void deleteMessageEvent(DeleteMessageEvent event);
}
diff --git a/juick-server/src/main/java/com/juick/service/activities/DeleteMessageEvent.java b/juick-server/src/main/java/com/juick/service/activities/DeleteMessageEvent.java
new file mode 100644
index 00000000..67e40f44
--- /dev/null
+++ b/juick-server/src/main/java/com/juick/service/activities/DeleteMessageEvent.java
@@ -0,0 +1,21 @@
+package com.juick.service.activities;
+
+import com.juick.Message;
+import org.springframework.context.ApplicationEvent;
+
+public class DeleteMessageEvent extends ApplicationEvent {
+ private Message message;
+ /**
+ * Create a new ApplicationEvent.
+ *
+ * @param source the object on which the event initially occurred (never {@code null})
+ */
+ public DeleteMessageEvent(Object source, Message message) {
+ super(source);
+ this.message = message;
+ }
+
+ public Message getMessage() {
+ return message;
+ }
+}