aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/ActivityPubManager.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2023-01-04 16:24:47 +0300
committerGravatar Vitaly Takmazov2023-01-04 16:24:47 +0300
commit58359b1e45861fea725aa7accfe5879d2d7fbeb7 (patch)
tree5ca10dedef14cd1f79a3047b2a862dfaaa018ec4 /src/main/java/com/juick/ActivityPubManager.java
parent6d74934d18f345f2ffcbc219d13dd63a2f0b9810 (diff)
ActivityPub: fix actor to user conversion, handle Block activity
Diffstat (limited to 'src/main/java/com/juick/ActivityPubManager.java')
-rw-r--r--src/main/java/com/juick/ActivityPubManager.java26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/main/java/com/juick/ActivityPubManager.java b/src/main/java/com/juick/ActivityPubManager.java
index 1dd3b784..9dc6a4f0 100644
--- a/src/main/java/com/juick/ActivityPubManager.java
+++ b/src/main/java/com/juick/ActivityPubManager.java
@@ -17,6 +17,9 @@
package com.juick;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.json.JsonMapper;
import com.juick.model.Message;
import com.juick.model.Reaction;
import com.juick.model.User;
@@ -69,6 +72,8 @@ public class ActivityPubManager implements ActivityListener, NotificationListene
ProfileUriBuilder profileUriBuilder;
@Inject
ConversionService conversionService;
+ @Inject
+ ObjectMapper jsonMapper;
@Override
public void processFollowEvent(@Nonnull FollowEvent followEvent) {
@@ -365,14 +370,19 @@ public class ActivityPubManager implements ActivityListener, NotificationListene
logger.warn("Context not found: {}", announce.getActor());
});
}
- public User actorToUser(URI uri) throws HttpBadRequestException {
- Actor person = (Actor) signatureManager.getContext(uri).orElseThrow(HttpBadRequestException::new);
- User user = new User();
- user.setUri(URI.create(person.getId()));
- user.setName(person.getPreferredUsername());
- if (person.getIcon() != null) {
- user.setAvatar(person.getIcon().getUrl());
+ public User actorToUser(URI uri) throws HttpBadRequestException, JsonProcessingException {
+ var context = signatureManager.getContext(uri);
+ if (context.isPresent() && context.get() instanceof Actor actor) {
+ User user = new User();
+ user.setUri(URI.create(actor.getId()));
+ user.setName(actor.getPreferredUsername());
+ if (actor.getIcon() != null) {
+ user.setAvatar(actor.getIcon().getUrl());
+ }
+ return user;
+ } else {
+ logger.warn("Unhandled context: {}", jsonMapper.writeValueAsString(context));
+ throw new HttpBadRequestException();
}
- return user;
}
}