diff options
author | Vitaly Takmazov | 2022-04-13 15:43:19 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2022-04-13 15:43:19 +0300 |
commit | cde193ed381f8734701649fa6af6b77560c2682f (patch) | |
tree | 9ece86de875207df2b9b14392dd6cb75cae82e6d /src/main | |
parent | 5627cc16cc8059e09a844ff5c9609051c2961847 (diff) |
ActivityPub: handle like exceptions
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/juick/ActivityPubManager.java | 29 |
1 files changed, 18 insertions, 11 deletions
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 { |