aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-10-04 13:59:28 +0300
committerGravatar Vitaly Takmazov2018-10-04 14:01:56 +0300
commit873fbbc8b7f59c68c6bf37ff9af79c8fb2aef8ed (patch)
tree86684ced187edc819acb6a8132047342553d3d76 /juick-server/src/main/java/com/juick/server
parentfdc329f367e5685cc9d4b0654f53eaa03818e905 (diff)
ActivityPub: handle Undo following requests
Diffstat (limited to 'juick-server/src/main/java/com/juick/server')
-rw-r--r--juick-server/src/main/java/com/juick/server/ActivityPubManager.java17
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/Profile.java3
2 files changed, 18 insertions, 2 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 223d28fd..17522423 100644
--- a/juick-server/src/main/java/com/juick/server/ActivityPubManager.java
+++ b/juick-server/src/main/java/com/juick/server/ActivityPubManager.java
@@ -8,7 +8,9 @@ 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.service.SocialService;
+import com.juick.service.activities.ActivityListener;
import com.juick.service.activities.FollowEvent;
+import com.juick.service.activities.UndoFollowEvent;
import com.juick.service.component.*;
import com.juick.util.MessageUtils;
import org.apache.commons.lang3.StringUtils;
@@ -27,7 +29,7 @@ import java.net.URI;
import java.util.Collections;
@Component
-public class ActivityPubManager implements ApplicationListener<FollowEvent>, NotificationListener {
+public class ActivityPubManager implements ActivityListener, NotificationListener {
private static final Logger logger = LoggerFactory.getLogger(ActivityPubManager.class);
@Inject
SignatureManager signatureManager;
@@ -46,7 +48,7 @@ public class ActivityPubManager implements ApplicationListener<FollowEvent>, Not
}
@Override
- public void onApplicationEvent(@Nonnull FollowEvent followEvent) {
+ public void processFollowEvent(@Nonnull FollowEvent followEvent) {
String acct = (String)followEvent.getRequest().getObject();
logger.info("received follower request to {}", acct);
User followedUser = socialService.getUserByAccountUri(acct);
@@ -68,6 +70,17 @@ public class ActivityPubManager implements ApplicationListener<FollowEvent>, Not
}
@Override
+ public void undoFollowEvent(UndoFollowEvent event) {
+ String actor = event.getActor();
+ String me = (String)event.getFollowRequest().getObject();
+ logger.info("{} stopping to follow {}", actor, me);
+ User followedUser = socialService.getUserByAccountUri(me);
+ if (!followedUser.isAnonymous()) {
+ socialService.removeFollower(followedUser, actor);
+ }
+ }
+
+ @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/api/activity/Profile.java b/juick-server/src/main/java/com/juick/server/api/activity/Profile.java
index 7b854d52..2e089330 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
@@ -13,6 +13,7 @@ import com.juick.server.util.UserUtils;
import com.juick.service.MessagesService;
import com.juick.service.UserService;
import com.juick.service.activities.FollowEvent;
+import com.juick.service.activities.UndoFollowEvent;
import com.juick.util.MessageUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
@@ -239,6 +240,8 @@ public class Profile {
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
if (activity instanceof Undo) {
+ Follow undoFollow = (Follow) ((Undo) activity).getObject();
+ applicationEventPublisher.publishEvent(new UndoFollowEvent(this, ((Undo) activity).getActor(), undoFollow));
return new ResponseEntity<>(HttpStatus.OK);
}
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);