aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2022-12-24 08:15:43 +0300
committerGravatar Vitaly Takmazov2022-12-24 08:15:43 +0300
commitb6a76493f1711ad42cc8543bc73ae70b3d75868e (patch)
tree61ff105aecb0bb240b8d44949f4828b1e345ae21
parent0ab02be35b4f83a10c1d586c7e069b9e1dc4c075 (diff)
ActivityPub: compatibility with Honk server
-rw-r--r--src/main/java/com/juick/SignatureManager.java9
-rw-r--r--src/main/java/com/juick/www/api/activity/model/Context.java1
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java7
-rw-r--r--src/test/resources/to_as_string.json1
4 files changed, 16 insertions, 2 deletions
diff --git a/src/main/java/com/juick/SignatureManager.java b/src/main/java/com/juick/SignatureManager.java
index 8032a6fa..9d6b68f7 100644
--- a/src/main/java/com/juick/SignatureManager.java
+++ b/src/main/java/com/juick/SignatureManager.java
@@ -23,6 +23,7 @@ import com.juick.model.User;
import com.juick.service.UserService;
import com.juick.service.activities.DeleteUserEvent;
import com.juick.util.DateFormattersHolder;
+import com.juick.www.api.activity.model.Activity;
import com.juick.www.api.activity.model.Context;
import com.juick.www.api.activity.model.objects.Actor;
import com.juick.www.api.webfinger.model.Account;
@@ -35,6 +36,7 @@ import org.springframework.context.ApplicationEventPublisher;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
+import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
@@ -55,6 +57,7 @@ import java.security.NoSuchAlgorithmException;
import java.security.SignatureException;
import java.time.Instant;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -164,7 +167,10 @@ public class SignatureManager {
@Cacheable("profiles")
public Optional<Context> getContext(URI contextUri) {
try {
- Context context = apClient.getForEntity(contextUri, Context.class).getBody();
+ HttpHeaders headers = new HttpHeaders();
+ headers.setAccept(Collections.singletonList(MediaType.valueOf(ACTIVITY_MEDIA_TYPE)));
+ HttpEntity<Void> activityRequest = new HttpEntity<>(headers);
+ Context context = apClient.exchange(contextUri, HttpMethod.GET, activityRequest, Context.class).getBody();
if (context == null) {
logger.warn("Cannot identify {}", contextUri);
return Optional.empty();
@@ -181,6 +187,7 @@ public class SignatureManager {
URI resourceUri = UriComponentsBuilder.fromPath("/.well-known/webfinger").host(acctId.getDomain())
.scheme("https").queryParam("resource", "acct:" + acct).build().toUri();
HttpHeaders headers = new HttpHeaders();
+ headers.setAccept(Collections.singletonList(MediaType.valueOf("application/jrd+json")));
HttpEntity<Void> webfingerRequest = new HttpEntity<>(headers);
try {
ResponseEntity<Account> response = apClient.exchange(resourceUri, HttpMethod.GET, webfingerRequest,
diff --git a/src/main/java/com/juick/www/api/activity/model/Context.java b/src/main/java/com/juick/www/api/activity/model/Context.java
index 1eb057a6..5a66b3b3 100644
--- a/src/main/java/com/juick/www/api/activity/model/Context.java
+++ b/src/main/java/com/juick/www/api/activity/model/Context.java
@@ -110,6 +110,7 @@ public class Context implements Serializable {
this.published = published;
}
+ @JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
public List<String> getTo() {
return to;
}
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java
index 290e07fe..7d0aa019 100644
--- a/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/src/test/java/com/juick/server/tests/ServerTests.java
@@ -324,6 +324,8 @@ public class ServerTests {
private Resource hubzillaActivity;
@Value("classpath:hubzilla_follow.json")
private Resource hubzillaFollow;
+ @Value("classpath:to_as_string.json")
+ private Resource honkFollow;
@Value("classpath:announce.json")
private Resource noteWithDocument;
@Value("classpath:note_with_attachment.json")
@@ -2528,12 +2530,15 @@ public class ServerTests {
}
@Test
- public void hubzillaActor() throws Exception {
+ public void hubzillaAndHonkActor() throws Exception {
String activity = IOUtils.toString(hubzillaActivity.getInputStream(), StandardCharsets.UTF_8);
Create create = jsonMapper.readValue(activity, Create.class);
String followData = IOUtils.toString(hubzillaFollow.getInputStream(), StandardCharsets.UTF_8);
Follow follow = jsonMapper.readValue(followData, Follow.class);
assertThat(follow.getActor(), is("https://ussr.win/channel/zlax"));
+ String honkData = IOUtils.toString(honkFollow.getInputStream(), StandardCharsets.UTF_8);
+ Follow hfollow = jsonMapper.readValue(honkData, Follow.class);
+ assertThat(hfollow.getTo().get(0), is("https://juick.com/u/vt"));
}
@Test
diff --git a/src/test/resources/to_as_string.json b/src/test/resources/to_as_string.json
new file mode 100644
index 00000000..cb48336c
--- /dev/null
+++ b/src/test/resources/to_as_string.json
@@ -0,0 +1 @@
+{ "@context": "https://www.w3.org/ns/activitystreams", "actor": "https://me.spectrum.im/u/vt", "id": "https://me.spectrum.im/u/vt/sub/944HVdt81833mx32sy", "object": "https://juick.com/u/vt", "published": "2022-12-24T04:59:08Z", "to": "https://juick.com/u/vt", "type": "Follow" } \ No newline at end of file