diff options
author | Vitaly Takmazov | 2019-12-19 13:21:40 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2019-12-19 13:21:40 +0300 |
commit | 3ab17252a7d9f6c5834d85d050a19fa41be0c07d (patch) | |
tree | d6eb45b174281abfcee6e280eab7bb0f5bf15987 /src/main/java/com/juick/server/api/Post.java | |
parent | 7b2bad85004179e7898e90e26c8afe34f221dde0 (diff) |
Send Update activites on message updates
Diffstat (limited to 'src/main/java/com/juick/server/api/Post.java')
-rw-r--r-- | src/main/java/com/juick/server/api/Post.java | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/main/java/com/juick/server/api/Post.java b/src/main/java/com/juick/server/api/Post.java index 72a9c383..37b40b2d 100644 --- a/src/main/java/com/juick/server/api/Post.java +++ b/src/main/java/com/juick/server/api/Post.java @@ -22,6 +22,7 @@ import com.juick.Reaction; import com.juick.Status; import com.juick.User; import com.juick.model.CommandResult; +import com.juick.server.ActivityPubManager; import com.juick.server.CommandsManager; import com.juick.server.util.HttpBadRequestException; import com.juick.server.util.HttpForbiddenException; @@ -29,11 +30,13 @@ import com.juick.server.util.HttpNotFoundException; import com.juick.server.util.HttpUtils; import com.juick.service.MessagesService; import com.juick.service.UserService; +import com.juick.service.activities.UpdateEvent; import com.juick.service.security.annotation.Visitor; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.ApplicationEventPublisher; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; @@ -61,6 +64,10 @@ public class Post { private String tmpDir; @Inject CommandsManager commandsManager; + @Inject + ApplicationEventPublisher applicationEventPublisher; + @Inject + ActivityPubManager activityPubManager; @RequestMapping(value = "/api/post", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(value = HttpStatus.OK) @@ -217,7 +224,11 @@ public class Post { User author = rid == 0 ? messagesService.getMessageAuthor(mid) : messagesService.getReply(mid, rid).getUser(); if (visitor.equals(author)) { if (messagesService.updateMessage(mid, rid, body)) { - Message result = rid == 0 ? messagesService.getMessage(mid).orElseThrow(IllegalStateException::new) : messagesService.getReply(mid, rid); + Message result = rid == 0 ? + messagesService.getMessage(mid).orElseThrow(IllegalStateException::new) + : messagesService.getReply(mid, rid); + applicationEventPublisher.publishEvent( + new UpdateEvent(this, author, activityPubManager.messageUri(mid, rid))); return CommandResult.build(result, "Message updated", StringUtils.EMPTY); } throw new HttpBadRequestException(); |