aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/server/api/activity
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-11-29 13:08:02 +0300
committerGravatar Vitaly Takmazov2018-11-29 13:08:02 +0300
commita1058eeef3963634853f8470d1957ecf58c4481a (patch)
treea0d003f117516f5c9e6b7cbb49a355ff48150de5 /src/main/java/com/juick/server/api/activity
parent7647ea6728e9203787dff4f640acb4d6ce3a704f (diff)
ActivityPub likes refactoring
Diffstat (limited to 'src/main/java/com/juick/server/api/activity')
-rw-r--r--src/main/java/com/juick/server/api/activity/Profile.java28
1 files changed, 12 insertions, 16 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 5a2a766e..e8fb45ec 100644
--- a/src/main/java/com/juick/server/api/activity/Profile.java
+++ b/src/main/java/com/juick/server/api/activity/Profile.java
@@ -28,9 +28,7 @@ import com.juick.server.util.UserUtils;
import com.juick.server.www.WebApp;
import com.juick.service.MessagesService;
import com.juick.service.UserService;
-import com.juick.service.activities.DeleteUserEvent;
-import com.juick.service.activities.FollowEvent;
-import com.juick.service.activities.UndoFollowEvent;
+import com.juick.service.activities.*;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -283,9 +281,16 @@ public class Profile {
}
if (activity instanceof Undo) {
- String follower = (String) ((Map) activity.getObject()).get("object");
- applicationEventPublisher.publishEvent(new UndoFollowEvent(this, activity.getActor(), follower));
- return new ResponseEntity<>(HttpStatus.OK);
+ Map object = (Map) activity.getObject();
+ String objectType = (String) object.get("type");
+ String objectObject = (String) object.get("object");
+ if (objectType.equals("Follow")) {
+ applicationEventPublisher.publishEvent(new UndoFollowEvent(this, activity.getActor(), objectObject));
+ return new ResponseEntity<>(HttpStatus.OK);
+ } else if (objectType.equals("Like") || objectType.equals("Announce")) {
+ applicationEventPublisher.publishEvent(new UndoAnnounceEvent(this, activity.getActor(), objectObject));
+ return new ResponseEntity<>(HttpStatus.OK);
+ }
}
if (activity instanceof Delete) {
if (activity.getObject() instanceof String) {
@@ -356,16 +361,7 @@ public class Profile {
}
}
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));
- }
+ applicationEventPublisher.publishEvent(new AnnounceEvent(this, activity.getActor(), (String)((Map)activity.getObject()).get("object")));
return new ResponseEntity<>(HttpStatus.OK);
}
logger.warn("Unknown activity: {}", jsonMapper.writeValueAsString(activity));