diff options
author | 2018-10-04 17:06:15 +0300 | |
---|---|---|
committer | 2018-10-04 17:06:15 +0300 | |
commit | 9fd4ce97047f8c4ffd2bd3374b0288b53580f34b (patch) | |
tree | 8a84f6e42525a2f37032dd7c7ddcbe2b5a34c093 /juick-server/src/main/java/com/juick/server | |
parent | deec8829a53e5b75a837d31c5061d5ab4ecef420 (diff) |
ActivityPub: broadcast message deletion
Diffstat (limited to 'juick-server/src/main/java/com/juick/server')
-rw-r--r-- | juick-server/src/main/java/com/juick/server/ActivityPubManager.java | 29 | ||||
-rw-r--r-- | juick-server/src/main/java/com/juick/server/CommandsManager.java | 5 |
2 files changed, 29 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"); |