aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-10-07 13:14:33 +0300
committerGravatar Vitaly Takmazov2018-10-07 13:14:33 +0300
commitae2b7552bda919e7eb505139eb417656ae2568a1 (patch)
treef484dda786eda1acbf1a99836fb2a5dd54d9bcbe
parent1dbaac46c7205c184ff2365031d918083b2dce57 (diff)
ActivityPub: fix inReplyTo serialization
-rw-r--r--juick-common/src/main/java/com/juick/Message.java9
-rw-r--r--juick-server/src/main/java/com/juick/server/ActivityPubManager.java4
-rw-r--r--juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java9
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java16
4 files changed, 31 insertions, 7 deletions
diff --git a/juick-common/src/main/java/com/juick/Message.java b/juick-common/src/main/java/com/juick/Message.java
index a5efb05c..bd2c91b5 100644
--- a/juick-common/src/main/java/com/juick/Message.java
+++ b/juick-common/src/main/java/com/juick/Message.java
@@ -77,6 +77,7 @@ public class Message implements Comparable {
private Set<Reaction> reactions;
private boolean service;
private URI replyUri;
+ private URI replyToUri;
private boolean html;
private Set<String> recommendations;
@@ -366,4 +367,12 @@ public class Message implements Comparable {
public void setHtml(boolean html) {
this.html = html;
}
+
+ public URI getReplyToUri() {
+ return replyToUri;
+ }
+
+ public void setReplyToUri(URI replyToUri) {
+ this.replyToUri = replyToUri;
+ }
}
diff --git a/juick-server/src/main/java/com/juick/server/ActivityPubManager.java b/juick-server/src/main/java/com/juick/server/ActivityPubManager.java
index c1790deb..10ca9951 100644
--- a/juick-server/src/main/java/com/juick/server/ActivityPubManager.java
+++ b/juick-server/src/main/java/com/juick/server/ActivityPubManager.java
@@ -183,8 +183,8 @@ public class ActivityPubManager implements ActivityListener, NotificationListene
note.setUrl(PlainTextFormatter.formatUrl(msg));
note.setAttributedTo(personUri(msg.getUser()));
if (MessageUtils.isReply(msg)) {
- if (msg.getReplyUri().toASCIIString().length() > 0) {
- note.setInReplyTo(msg.getReplyUri().toASCIIString());
+ if (msg.getReplyToUri().toASCIIString().length() > 0) {
+ note.setInReplyTo(msg.getReplyToUri().toASCIIString());
} else {
note.setInReplyTo(messageUri(msg.getMid(), msg.getReplyto()));
}
diff --git a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
index bb8e43f1..62cdff0c 100644
--- a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -367,7 +367,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
+ "replies.attach, replies.txt, IFNULL(q.txt,t.txt) as quote, "
+ "COALESCE(q.user_id, m.user_id) AS to_uid, COALESCE(qu.nick, mu.nick) AS to_name, "
+ "replies.updated_at, replies.user_uri as uri, "
- + "q.user_uri AS to_uri, replies.reply_uri AS reply_uri, replies.html "
+ + "q.user_uri AS to_uri, replies.reply_uri AS reply_uri, replies.html, q.reply_uri "
+ "FROM replies LEFT JOIN users ON replies.user_id = users.id "
+ "LEFT JOIN replies q ON replies.message_id = q.message_id and replies.replyto = q.reply_id "
+ "LEFT JOIN messages_txt t ON replies.message_id = t.message_id "
@@ -401,11 +401,12 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
User quoteUser = new User();
quoteUser.setUid(quoteUid);
quoteUser.setName(Optional.ofNullable(rs.getString(9)).orElse(AnonymousUser.INSTANCE.getName()));
- quoteUser.setUri(URI.create(Optional.ofNullable(rs.getString(11)).orElse(StringUtils.EMPTY)));
+ quoteUser.setUri(URI.create(Optional.ofNullable(rs.getString(12)).orElse(StringUtils.EMPTY)));
msg.setTo(quoteUser);
msg.setUpdatedAt(rs.getTimestamp(10).toInstant());
- msg.setReplyUri(URI.create(Optional.ofNullable(rs.getString(12)).orElse(StringUtils.EMPTY)));
- msg.setHtml(rs.getBoolean(13));
+ msg.setReplyUri(URI.create(Optional.ofNullable(rs.getString(13)).orElse(StringUtils.EMPTY)));
+ msg.setHtml(rs.getBoolean(14));
+ msg.setReplyToUri(URI.create(Optional.ofNullable(rs.getString(15)).orElse(StringUtils.EMPTY)));
if (StringUtils.isNotEmpty(msg.getAttachmentType())) {
try {
imagesService.setAttachmentMetadata(baseImagesUrl, msg);
diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
index 49988097..4d93470d 100644
--- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
@@ -33,6 +33,7 @@ import com.juick.model.TagStats;
import com.juick.server.*;
import com.juick.server.api.activity.model.Context;
import com.juick.server.api.activity.model.Key;
+import com.juick.server.api.activity.model.Note;
import com.juick.server.api.activity.model.Person;
import com.juick.server.api.activity.model.activities.Create;
import com.juick.server.api.activity.model.activities.Delete;
@@ -198,6 +199,8 @@ public class ServerTests {
private String appId;
@Inject
private SignatureManager signatureManager;
+ @Inject
+ private ActivityPubManager activityPubManager;
private static User ugnich, freefd, juick;
static String ugnichName, ugnichPassword, freefdName, freefdPassword, juickName, juickPassword;
@@ -1699,7 +1702,18 @@ public class ServerTests {
String attachment = attachmentObj != null ? (String)attachmentObj.get("url") : StringUtils.EMPTY;
String deleteJsonStr = IOUtils.toString(URI.create("classpath:delete.json"), StandardCharsets.UTF_8);
Delete delete = jsonMapper.readValue(deleteJsonStr, Delete.class);
-
+ int mid = messagesService.createMessage(ugnich.getUid(), "YO", "", null);
+ User extUser = new User();
+ extUser.setUri(URI.create("https://ext.social/users/xwatt"));
+ int rid = messagesService.createReply(mid, 0, extUser, "PEOPLE", null);
+ Message replyFromExt = messagesService.getReply(mid, rid);
+ String extMessageUri = "https://ext.social/statuses/12345";
+ messagesService.updateReplyUri(replyFromExt, URI.create(extMessageUri));
+ int rid2 = messagesService.createReply(mid, rid, ugnich, "HI", null);
+
+ Message replyToExt = messagesService.getReply(mid, rid2);
+ Note replyNote = activityPubManager.makeNote(replyToExt);
+ assertThat(replyNote.getInReplyTo(), equalTo(extMessageUri));
}
@Test
public void signingSpec() throws IOException {