diff options
author | Vitaly Takmazov | 2022-04-19 18:48:42 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2022-04-19 18:48:42 +0300 |
commit | 189b4e5a432e51802929ea0528830bfe594b350e (patch) | |
tree | 22e3e0b4378e9ca53ccd4c205809698fa947f290 /src/main | |
parent | 2c5790acee6553e9e15848180c8c743f9f2f60ff (diff) |
ActivityPub: handle context issues when processing messages
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/juick/ActivityPubManager.java | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/src/main/java/com/juick/ActivityPubManager.java b/src/main/java/com/juick/ActivityPubManager.java index a86fc301..52343d9c 100644 --- a/src/main/java/com/juick/ActivityPubManager.java +++ b/src/main/java/com/juick/ActivityPubManager.java @@ -249,31 +249,34 @@ public class ActivityPubManager implements ActivityListener, NotificationListene User user = msg.getUser(); String userUri = personUri(user); Note note = makeNote(msg); - Actor me = (Actor) signatureManager.getContext(URI.create(userUri)).get(); - Set<String> subscribers = new HashSet<>(socialService.getFollowers(user)); - if (MessageUtils.isReply(msg) && msg.getTo().getUri().toASCIIString().length() > 0) { - String replier = msg.getTo().getUri().toASCIIString(); - subscribers.add(replier); - List<String> cc = new ArrayList<>(note.getCc()); - cc.add(replier); - note.setCc(cc); - } - subscribers.addAll(note.getCc()); - subscribers.forEach(acct -> { - Optional<Context> context = signatureManager.getContext(URI.create(acct)); - if (context.isPresent() && context.get() instanceof Actor) { - Actor follower = (Actor)context.get(); - Create create = new Create(); - create.setId(note.getId()); - create.setActor(me.getId()); - create.setPublished(note.getPublished()); - create.setObject(note); - try { - signatureManager.post(me, follower, create); - } catch (IOException | NoSuchAlgorithmException e) { - logger.warn("activitypub exception", e); - } + signatureManager.getContext(URI.create(userUri)).ifPresentOrElse((me) -> { + Set<String> subscribers = new HashSet<>(socialService.getFollowers(user)); + if (MessageUtils.isReply(msg) && msg.getTo().getUri().toASCIIString().length() > 0) { + String replier = msg.getTo().getUri().toASCIIString(); + subscribers.add(replier); + List<String> cc = new ArrayList<>(note.getCc()); + cc.add(replier); + note.setCc(cc); } + subscribers.addAll(note.getCc()); + subscribers.forEach(acct -> { + Optional<Context> context = signatureManager.getContext(URI.create(acct)); + if (context.isPresent() && context.get() instanceof Actor) { + Actor follower = (Actor) context.get(); + Create create = new Create(); + create.setId(note.getId()); + create.setActor(me.getId()); + create.setPublished(note.getPublished()); + create.setObject(note); + try { + signatureManager.post((Actor)me, follower, create); + } catch (IOException | NoSuchAlgorithmException e) { + logger.warn("activitypub exception", e); + } + } + }); + }, () -> { + logger.warn("Context not found: {}", userUri); }); } |