aboutsummaryrefslogtreecommitdiff
path: root/juick-server
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-10-06 21:47:21 +0300
committerGravatar Vitaly Takmazov2018-10-06 21:47:21 +0300
commit2cf0e365e7dc4a670fbf8f2fd1045209a5cc5c3f (patch)
tree2a35d5aca930556173e8ad1bff92c0cea8d95760 /juick-server
parent312b2408d72d11caf4d88cfbf07157ead220347f (diff)
ActivityPub: handle replies
Diffstat (limited to 'juick-server')
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/Profile.java22
1 files changed, 21 insertions, 1 deletions
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/Profile.java b/juick-server/src/main/java/com/juick/server/api/activity/Profile.java
index 80a2851c..392acfe6 100644
--- a/juick-server/src/main/java/com/juick/server/api/activity/Profile.java
+++ b/juick-server/src/main/java/com/juick/server/api/activity/Profile.java
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.juick.User;
import com.juick.server.ActivityPubManager;
+import com.juick.server.CommandsManager;
import com.juick.server.KeystoreManager;
import com.juick.server.SignatureManager;
import com.juick.server.api.activity.model.*;
@@ -19,6 +20,7 @@ import com.juick.service.UserService;
import com.juick.service.activities.DeleteUserEvent;
import com.juick.service.activities.FollowEvent;
import com.juick.service.activities.UndoFollowEvent;
+import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
@@ -54,6 +56,8 @@ public class Profile {
private ActivityPubManager activityPubManager;
@Inject
private ApplicationEventPublisher applicationEventPublisher;
+ @Inject
+ private CommandsManager commandsManager;
@Value("${web_domain:localhost}")
private String domain;
@Value("${ap_base_uri:http://localhost:8080/}")
@@ -242,7 +246,7 @@ public class Profile {
@RequestHeader(name = "Content-Type") String contentType,
@RequestHeader(name = "User-Agent", required = false) String userAgent,
@RequestHeader(name = "Accept-Encoding", required = false) String acceptEncoding,
- @RequestHeader(name = "Signature", required = false) String signature) throws JsonProcessingException {
+ @RequestHeader(name = "Signature", required = false) String signature) throws Exception {
UriComponents componentsBuilder = ServletUriComponentsBuilder.fromCurrentRequestUri().build();
Map<String, String> headers = new HashMap<>();
headers.put("host", host.split(":", 2)[0]);
@@ -271,6 +275,22 @@ public class Profile {
applicationEventPublisher.publishEvent(new DeleteUserEvent(this, (String)activity.getObject()));
}
}
+ if (activity instanceof Create) {
+ if (activity.getObject() instanceof Note) {
+ Note note = (Note) activity.getObject();
+ String inReplyTo = note.getInReplyTo();
+ if (StringUtils.isNotBlank(inReplyTo)) {
+ if (inReplyTo.startsWith(baseUri)) {
+ UriComponents uri = UriComponentsBuilder.fromUriString(inReplyTo).build();
+ String postId = uri.getPath().substring(uri.getPath().lastIndexOf('/') + 1).replace("-", "/");
+ User user = new User();
+ user.setUri(URI.create(activity.getActor()));
+ commandsManager.processCommand(user, String.format("#%s %s", postId, note.getContent()), URI.create(note.getAttachment().getUrl()));
+ }
+ }
+
+ }
+ }
logger.warn("Unknown activity: {}", jsonMapper.writeValueAsString(activity));
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}