aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-10-06 23:02:14 +0300
committerGravatar Vitaly Takmazov2018-10-06 23:02:14 +0300
commit0b065e1e0547885294d03df54d178587d801a15a (patch)
treecde84364a49e507be61a785e0596489385a511ff /juick-server/src
parent4b7702d846c281459433cf51dab5669fb3466b12 (diff)
store external reply uri
Diffstat (limited to 'juick-server/src')
-rw-r--r--juick-server/src/main/java/com/juick/server/ActivityPubManager.java6
-rw-r--r--juick-server/src/main/java/com/juick/server/api/activity/Profile.java1
-rw-r--r--juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java21
-rw-r--r--juick-server/src/main/resources/db/migration/V1.7__reply_uri.sql1
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java2
5 files changed, 23 insertions, 8 deletions
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 3d296d8f..4adfafea 100644
--- a/juick-server/src/main/java/com/juick/server/ActivityPubManager.java
+++ b/juick-server/src/main/java/com/juick/server/ActivityPubManager.java
@@ -183,7 +183,11 @@ public class ActivityPubManager implements ActivityListener, NotificationListene
note.setUrl(PlainTextFormatter.formatUrl(msg));
note.setAttributedTo(personUri(msg.getUser()));
if (MessageUtils.isReply(msg)) {
- note.setInReplyTo(messageUri(msg.getMid(), msg.getReplyto()));
+ if (msg.getReplyUri().toASCIIString().length() > 0) {
+ note.setInReplyTo(msg.getReplyUri().toASCIIString());
+ } else {
+ note.setInReplyTo(messageUri(msg.getMid(), msg.getReplyto()));
+ }
}
if (MessageUtils.isPM(msg)) {
note.setTo(Collections.singletonList(personUri(msg.getTo())));
diff --git a/juick-server/src/main/java/com/juick/server/api/activity/Profile.java b/juick-server/src/main/java/com/juick/server/api/activity/Profile.java
index b016afc9..261552d7 100644
--- a/juick-server/src/main/java/com/juick/server/api/activity/Profile.java
+++ b/juick-server/src/main/java/com/juick/server/api/activity/Profile.java
@@ -295,6 +295,7 @@ public class Profile {
CommandResult result = commandsManager.processCommand(user, String.format("#%s %s", postId, note.get("content")), URI.create(attachment));
logger.info(jsonMapper.writeValueAsString(result));
if (result.getNewMessage().isPresent()) {
+ messagesService.updateReplyUri(result.getNewMessage().get(), URI.create((String)note.get("id")));
return new ResponseEntity<>(HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
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 d556865d..a6a38e2b 100644
--- a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -99,6 +99,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
}
msg.setTo(quoteUser);
msg.setUpdatedAt(rs.getTimestamp(21).toInstant());
+ msg.setReplyUri(URI.create(Optional.ofNullable(rs.getString(24)).orElse(StringUtils.EMPTY)));
if (StringUtils.isNotEmpty(msg.getAttachmentType())) {
try {
imagesService.setAttachmentMetadata(baseImagesUrl, msg);
@@ -336,7 +337,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
+ "messages.readonly, messages.privacy, messages.replies,"
+ "messages.attach, COUNT(DISTINCT favorites.user_id) as likes, messages.hidden,"
+ "txt.tags, txt.repliesby, txt.txt, '' as q, messages.updated as updated, 0 as to_uid, "
- + "NULL as to_name, txt.updated_at, '' as uri, '' as to_uri FROM messages "
+ + "NULL as to_name, txt.updated_at, '' as user_uri, '' as to_uri, '' as reply_uri FROM messages "
+ "INNER JOIN users ON messages.user_id = users.id "
+ "INNER JOIN messages_txt AS txt "
+ "ON messages.message_id = txt.message_id "
@@ -344,7 +345,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
+ "ON messages.message_id = favorites.message_id AND favorites.like_id=1 "
+ "WHERE messages.message_id = ? "
+ "GROUP BY mid, rid, replyto, uid, nick, banned, messages.ts, readonly, "
- + "privacy, replies, attach, tags, repliesby, q, updated_at, uri",
+ + "privacy, replies, attach, tags, repliesby, q, updated_at, user_uri, to_uri, reply_uri",
new MessageMapper(),
mid);
if (!list.isEmpty()) {
@@ -365,7 +366,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 "
+ + "q.user_uri AS to_uri, replies.reply_uri AS 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 "
@@ -402,6 +403,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
quoteUser.setUri(URI.create(Optional.ofNullable(rs.getString(11)).orElse(StringUtils.EMPTY)));
msg.setTo(quoteUser);
msg.setUpdatedAt(rs.getTimestamp(10).toInstant());
+ msg.setReplyUri(URI.create(Optional.ofNullable(rs.getString(12)).orElse(StringUtils.EMPTY)));
if (StringUtils.isNotEmpty(msg.getAttachmentType())) {
try {
imagesService.setAttachmentMetadata(baseImagesUrl, msg);
@@ -831,7 +833,8 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
+ "messages.readonly,messages.privacy, messages.replies-COUNT(DISTINCT banned.reply_id) as replies,"
+ "messages.attach,COUNT(DISTINCT favorites.user_id) AS likes,messages.hidden,"
+ "messages_txt.tags,messages_txt.repliesby, messages_txt.txt, '' as q, "
- + "messages.updated, 0 as to_uid, NULL as to_name, messages_txt.updated_at, '' as uri, '' as to_uri "
+ + "messages.updated, 0 as to_uid, NULL as to_name, messages_txt.updated_at, '' as user_uri, "
+ + "'' as to_uri, '' as reply_uri "
+ "FROM (messages INNER JOIN messages_txt "
+ "ON messages.message_id=messages_txt.message_id) "
+ "INNER JOIN users ON messages.user_id=users.id "
@@ -840,7 +843,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
+ "LEFT JOIN banned "
+ "ON messages.message_id = banned.message_id "
+ "WHERE messages.message_id IN (:ids) GROUP BY "
- + "messages.message_id, rid, replyto, messages.user_id, users.nick, banned, messages.ts, messages.readonly, messages.privacy, messages.attach, messages.hidden, messages_txt.tags, messages_txt.repliesby, messages_txt.txt, q, messages.updated, to_uid, to_name, updated_at, uri",
+ + "messages.message_id, rid, replyto, messages.user_id, users.nick, banned, messages.ts, messages.readonly, messages.privacy, messages.attach, messages.hidden, messages_txt.tags, messages_txt.repliesby, messages_txt.txt, q, messages.updated, to_uid, to_name, updated_at, user_uri, reply_uri",
new MapSqlParameterSource("ids", mids)
.addValue("uid", visitor.getUid()),
new MessageMapper());
@@ -909,7 +912,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
"NOW(), " +
"COALESCE(qw.user_id, m.user_id) as to_uid, COALESCE(qu.nick, mu.nick) as to_name, " +
"replies.updated_at, replies.user_uri as uri, " +
- "qw.user_uri as to_uri " +
+ "qw.user_uri as to_uri, replies.reply_uri " +
"FROM replies LEFT JOIN users " +
"ON replies.user_id = users.id " +
"LEFT JOIN replies qw ON replies.message_id = qw.message_id and replies.replyto = qw.reply_id " +
@@ -1091,4 +1094,10 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
body, Timestamp.from(now), mid, rid) > 0;
}
}
+
+ @Override
+ public boolean updateReplyUri(Message reply, URI replyUri) {
+ return jdbcTemplate.update("UPDATE replies SET reply_uri=? WHERE message_id=? AND reply_id=?",
+ replyUri.toASCIIString(), reply.getMid(), reply.getRid()) > 0;
+ }
}
diff --git a/juick-server/src/main/resources/db/migration/V1.7__reply_uri.sql b/juick-server/src/main/resources/db/migration/V1.7__reply_uri.sql
new file mode 100644
index 00000000..9ec35485
--- /dev/null
+++ b/juick-server/src/main/resources/db/migration/V1.7__reply_uri.sql
@@ -0,0 +1 @@
+ALTER TABLE replies ADD COLUMN reply_uri char(255) DEFAULT NULL; \ No newline at end of file
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 c1132a99..682b5084 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
@@ -312,7 +312,7 @@ public class ServerTests {
User ugnich = userService.getUserByUID(ugnich_id).orElse(AnonymousUser.INSTANCE);
int rid = messagesService.createReply(msg2.getMid(), 0, ugnich, "bla-bla", null);
assertEquals(1, rid);
- assertThat(msg2.getTo(), equalTo(null));
+ assertThat(msg2.getTo(), equalTo(AnonymousUser.INSTANCE));
Message reply = messagesService.getReply(msg2.getMid(), rid);
assertThat(reply.getTo().getName(), equalTo(user.getName()));
List<Message> replies = messagesService.getReplies(user, msg2.getMid());