From cde193ed381f8734701649fa6af6b77560c2682f Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 13 Apr 2022 15:43:19 +0300 Subject: ActivityPub: handle like exceptions --- src/main/java/com/juick/ActivityPubManager.java | 29 +++++++++++++++---------- 1 file changed, 18 insertions(+), 11 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 621a89c2..b0e77c63 100644 --- a/src/main/java/com/juick/ActivityPubManager.java +++ b/src/main/java/com/juick/ActivityPubManager.java @@ -411,17 +411,24 @@ public class ActivityPubManager implements ActivityListener, NotificationListene announce.setActor(personUri(user)); announce.setTo(Collections.singletonList(Context.ACTIVITYSTREAMS_PUBLIC)); announce.setObject(note); - Actor me = (Actor) signatureManager.getContext(URI.create(announce.getActor())).get(); - socialService.getFollowers(user).forEach(acct -> { - var follower = signatureManager.getContext(URI.create(acct)); - follower.ifPresentOrElse((person) -> { - try { - logger.info("{} announcing {} to {}", user.getName(), message.getMid(), acct); - signatureManager.post(me, (Actor)person, announce); - } catch (IOException | NoSuchAlgorithmException e) { - logger.warn("activitypub exception", e); - } - }, () -> logger.warn("Follower not found: {}", acct)); + signatureManager.getContext(URI.create(announce.getActor())).ifPresentOrElse((ctx) -> { + if (ctx instanceof Actor) { + socialService.getFollowers(user).forEach(acct -> { + var follower = signatureManager.getContext(URI.create(acct)); + follower.ifPresentOrElse((person) -> { + try { + logger.info("{} announcing {} to {}", user.getName(), message.getMid(), acct); + signatureManager.post((Actor)ctx, (Actor) person, announce); + } catch (IOException | NoSuchAlgorithmException e) { + logger.warn("activitypub exception", e); + } + }, () -> logger.warn("Follower not found: {}", acct)); + }); + } else { + logger.warn("Unhandled context: {}", announce.getActor()); + } + }, () -> { + logger.warn("Context not found: {}", announce.getActor()); }); } public User actorToUser(URI uri) throws HttpBadRequestException { -- cgit v1.2.3