diff options
author | Vitaly Takmazov | 2018-10-08 15:37:48 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-11-29 12:07:00 +0300 |
commit | 7647ea6728e9203787dff4f640acb4d6ce3a704f (patch) | |
tree | 3afe9a6cb1f1cc16c6fea79c798567ed911bb8cd /src/main/java/com/juick/server/api/activity | |
parent | 55cf2dd357088d7bbe0efff6a483679301ab2c22 (diff) |
save ActivityPub likes
Diffstat (limited to 'src/main/java/com/juick/server/api/activity')
-rw-r--r-- | src/main/java/com/juick/server/api/activity/Profile.java | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/main/java/com/juick/server/api/activity/Profile.java b/src/main/java/com/juick/server/api/activity/Profile.java index d8a8fd90..5a2a766e 100644 --- a/src/main/java/com/juick/server/api/activity/Profile.java +++ b/src/main/java/com/juick/server/api/activity/Profile.java @@ -14,6 +14,7 @@ import com.juick.server.api.activity.model.activities.Announce; import com.juick.server.api.activity.model.activities.Create; import com.juick.server.api.activity.model.activities.Delete; import com.juick.server.api.activity.model.activities.Follow; +import com.juick.server.api.activity.model.activities.Like; import com.juick.server.api.activity.model.activities.Undo; import com.juick.server.api.activity.model.objects.Image; import com.juick.server.api.activity.model.objects.Key; @@ -304,8 +305,7 @@ public class Profile { String inReplyTo = (String) note.get("inReplyTo"); if (StringUtils.isNotBlank(inReplyTo)) { if (inReplyTo.startsWith(baseUri)) { - UriComponents uri = UriComponentsBuilder.fromUriString(inReplyTo).build(); - String postId = uri.getPath().substring(uri.getPath().lastIndexOf('/') + 1).replace("-", "/"); + String postId = activityPubManager.postId(inReplyTo); User user = new User(); user.setUri(URI.create(activity.getActor())); String attachment = StringUtils.EMPTY; @@ -355,8 +355,17 @@ public class Profile { return new ResponseEntity<>(HttpStatus.OK); } } - if (activity instanceof Announce) { - logger.info("Announce: {}", jsonMapper.writeValueAsString(activity)); + if (activity instanceof Like || activity instanceof Announce) { + String msgUri = (String)activity.getObject(); + User user = new User(); + user.setUri(URI.create(activity.getActor())); + Person person = (Person) signatureManager.getContext(user.getUri()).get(); + user.setName(person.getPreferredUsername()); + String[] ids = msgUri.split("\\/", 2); + if (ids.length == 1) { + // only messages + commandsManager.processCommand(user, String.format("! #%s", ids[0]), URI.create(StringUtils.EMPTY)); + } return new ResponseEntity<>(HttpStatus.OK); } logger.warn("Unknown activity: {}", jsonMapper.writeValueAsString(activity)); |