From e0f560c662d20b1956cb706b6423596efd33e8fb Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 27 Aug 2021 16:39:46 +0300 Subject: ActivityPub: fix Application activites, use Actor where possible --- src/main/java/com/juick/ActivityPubManager.java | 23 ++++++++++++----------- src/main/java/com/juick/SignatureManager.java | 3 +-- 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'src/main/java/com/juick') diff --git a/src/main/java/com/juick/ActivityPubManager.java b/src/main/java/com/juick/ActivityPubManager.java index 1e97a54e..5b0e8d59 100644 --- a/src/main/java/com/juick/ActivityPubManager.java +++ b/src/main/java/com/juick/ActivityPubManager.java @@ -25,6 +25,7 @@ import com.juick.model.Tag; import com.juick.www.api.SystemActivity.ActivityType; import com.juick.www.api.activity.model.Context; import com.juick.www.api.activity.model.activities.*; +import com.juick.www.api.activity.model.objects.Actor; import com.juick.www.api.activity.model.objects.Hashtag; import com.juick.www.api.activity.model.objects.Image; import com.juick.www.api.activity.model.objects.Mention; @@ -97,8 +98,8 @@ public class ActivityPubManager implements ActivityListener, NotificationListene User followedUser = socialService.getUserByAccountUri(acct); if (!followedUser.isAnonymous()) { // automatically accept follower requests - Person me = (Person) signatureManager.getContext(URI.create(acct)).get(); - Person follower = (Person) signatureManager.getContext(URI.create(followEvent.getRequest().getActor())).get(); + Actor me = (Actor) signatureManager.getContext(URI.create(acct)).get(); + Actor follower = (Actor) signatureManager.getContext(URI.create(followEvent.getRequest().getActor())).get(); Accept accept = new Accept(); accept.setActor(me.getId()); accept.setObject(followEvent.getRequest()); @@ -136,10 +137,10 @@ public class ActivityPubManager implements ActivityListener, NotificationListene User user = msg.getUser(); String userUri = personUri(user); Note note = makeNote(msg); - Person me = (Person) signatureManager.getContext(URI.create(userUri)).get(); + Actor me = (Actor) signatureManager.getContext(URI.create(userUri)).get(); socialService.getFollowers(user).forEach(acct -> { try { - Person follower = (Person) signatureManager.getContext(URI.create(acct)).orElseThrow(); + Actor follower = (Actor) signatureManager.getContext(URI.create(acct)).orElseThrow(); Delete delete = new Delete(); delete.setId(note.getId()); delete.setActor(me.getId()); @@ -188,10 +189,10 @@ public class ActivityPubManager implements ActivityListener, NotificationListene String objectUri = event.getMessageUri(); User user = event.getUser(); String userUri = personUri(user); - Person me = (Person) signatureManager.getContext(URI.create(userUri)).get(); + Actor me = (Actor) signatureManager.getContext(URI.create(userUri)).get(); socialService.getFollowers(user).forEach(acct -> { try { - Person follower = (Person) signatureManager.getContext(URI.create(acct)).orElseThrow(); + Actor follower = (Actor) signatureManager.getContext(URI.create(acct)).orElseThrow(); Update update = new Update(); update.setId(objectUri + "#update"); update.setActor(me.getId()); @@ -222,10 +223,10 @@ public class ActivityPubManager implements ActivityListener, NotificationListene public void processUpdateUserEvent(UpdateUserEvent event) { User user = event.getUser(); String userUri = personUri(user); - Person me = (Person) signatureManager.getContext(URI.create(userUri)).get(); + Actor me = (Actor) signatureManager.getContext(URI.create(userUri)).get(); socialService.getFollowers(user).forEach(acct -> { try { - Person follower = (Person) signatureManager.getContext(URI.create(acct)).orElseThrow(); + Actor follower = (Actor) signatureManager.getContext(URI.create(acct)).orElseThrow(); Update update = new Update(); update.setId(userUri + "#update"); update.setActor(me.getId()); @@ -260,7 +261,7 @@ public class ActivityPubManager implements ActivityListener, NotificationListene subscribers.forEach(acct -> { Optional context = signatureManager.getContext(URI.create(acct)); if (context.isPresent() && context.get() instanceof Person) { - Person follower = (Person)context.get(); + Actor follower = (Actor)context.get(); Create create = new Create(); create.setId(note.getId()); create.setActor(me.getId()); @@ -409,13 +410,13 @@ public class ActivityPubManager implements ActivityListener, NotificationListene announce.setActor(personUri(serviceUser)); announce.setTo(Collections.singletonList(Context.ACTIVITYSTREAMS_PUBLIC)); announce.setObject(note); - Person me = (Person) signatureManager.getContext(URI.create(announce.getActor())).get(); + Actor me = (Actor) signatureManager.getContext(URI.create(announce.getActor())).get(); socialService.getFollowers(serviceUser).forEach(acct -> { var follower = signatureManager.getContext(URI.create(acct)); follower.ifPresentOrElse((person) -> { try { logger.info("Announcing top: {}", message.getMid()); - signatureManager.post(me, (Person)person, announce); + signatureManager.post(me, (Actor)person, announce); } catch (IOException | NoSuchAlgorithmException e) { logger.warn("activitypub exception", e); } diff --git a/src/main/java/com/juick/SignatureManager.java b/src/main/java/com/juick/SignatureManager.java index e9cb4f6a..bccc46be 100644 --- a/src/main/java/com/juick/SignatureManager.java +++ b/src/main/java/com/juick/SignatureManager.java @@ -24,7 +24,6 @@ import com.juick.service.UserService; import com.juick.service.activities.DeleteUserEvent; import com.juick.util.DateFormattersHolder; import com.juick.www.api.activity.model.Context; -import com.juick.www.api.activity.model.objects.Person; import com.juick.www.api.activity.model.objects.Actor; import com.juick.www.api.webfinger.model.Account; import com.juick.www.api.webfinger.model.Link; @@ -74,7 +73,7 @@ public class SignatureManager { @Inject private ApplicationEventPublisher applicationEventPublisher; - public void post(Person from, Person to, Context data) throws IOException, NoSuchAlgorithmException { + public void post(Actor from, Actor to, Context data) throws IOException, NoSuchAlgorithmException { UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(to.getInbox()); URI inbox = uriComponentsBuilder.build().toUri(); Instant now = Instant.now(); -- cgit v1.2.3