From 051fd4608ebd30e94eb847906571f5f221d3e952 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 4 Oct 2018 14:18:53 +0300 Subject: Undo object deserialized as Map --- .../src/main/java/com/juick/server/ActivityPubManager.java | 3 +-- .../src/main/java/com/juick/server/api/activity/Profile.java | 4 ++-- .../java/com/juick/service/activities/UndoFollowEvent.java | 11 +++++------ .../src/test/java/com/juick/server/tests/ServerTests.java | 4 ++++ 4 files changed, 12 insertions(+), 10 deletions(-) (limited to 'juick-server/src') 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 17522423..e0bbdb85 100644 --- a/juick-server/src/main/java/com/juick/server/ActivityPubManager.java +++ b/juick-server/src/main/java/com/juick/server/ActivityPubManager.java @@ -17,7 +17,6 @@ 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.ApplicationListener; import org.springframework.stereotype.Component; import org.springframework.web.util.UriComponentsBuilder; @@ -72,7 +71,7 @@ public class ActivityPubManager implements ActivityListener, NotificationListene @Override public void undoFollowEvent(UndoFollowEvent event) { String actor = event.getActor(); - String me = (String)event.getFollowRequest().getObject(); + String me = event.getObject(); logger.info("{} stopping to follow {}", actor, me); User followedUser = socialService.getUserByAccountUri(me); if (!followedUser.isAnonymous()) { 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 2e089330..23cd74ce 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 @@ -240,8 +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)); + String follower = (String)((Map) ((Undo) activity).getObject()).get("object"); + applicationEventPublisher.publishEvent(new UndoFollowEvent(this, ((Undo) activity).getActor(), follower)); return new ResponseEntity<>(HttpStatus.OK); } return new ResponseEntity<>(HttpStatus.BAD_REQUEST); diff --git a/juick-server/src/main/java/com/juick/service/activities/UndoFollowEvent.java b/juick-server/src/main/java/com/juick/service/activities/UndoFollowEvent.java index fa162b2e..2b48e6f6 100644 --- a/juick-server/src/main/java/com/juick/service/activities/UndoFollowEvent.java +++ b/juick-server/src/main/java/com/juick/service/activities/UndoFollowEvent.java @@ -1,27 +1,26 @@ package com.juick.service.activities; -import com.juick.server.api.activity.model.activities.Follow; import org.springframework.context.ApplicationEvent; public class UndoFollowEvent extends ApplicationEvent { private String actor; - private Follow followRequest; + private String object; /** * Create a new ApplicationEvent. * * @param source the object on which the event initially occurred (never {@code null}) */ - public UndoFollowEvent(Object source, String actor, Follow object) { + public UndoFollowEvent(Object source, String actor, String object) { super(source); this.actor = actor; - this.followRequest = object; + this.object = object; } public String getActor() { return actor; } - public Follow getFollowRequest() { - return followRequest; + public String getObject() { + return object; } } diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java index fa93ee64..4046a798 100644 --- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java +++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java @@ -35,6 +35,7 @@ import com.juick.server.api.activity.model.Context; import com.juick.server.api.activity.model.Key; import com.juick.server.api.activity.model.Person; import com.juick.server.api.activity.model.activities.Follow; +import com.juick.server.api.activity.model.activities.Undo; import com.juick.server.util.HttpUtils; import com.juick.server.util.ImageUtils; import com.juick.server.xmpp.helpers.XMPPStatus; @@ -1684,6 +1685,9 @@ public class ServerTests { Follow follow = (Follow)jsonMapper.readValue(followJsonStr, Context.class); String personJsonStr = IOUtils.toString(URI.create("classpath:person.json"), StandardCharsets.UTF_8); Person person = (Person)jsonMapper.readValue(personJsonStr, Context.class); + String undoJsonStr = IOUtils.toString(URI.create("classpath:undo.json"), StandardCharsets.UTF_8); + Undo undo = jsonMapper.readValue(undoJsonStr, Undo.class); + String undoFollower = (String)((Map)undo.getObject()).get("object"); } @Test public void signingSpec() throws IOException { -- cgit v1.2.3