From 6de0c5eb668f8c435dc121cf4a85465612e0ee6b Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 23 Oct 2018 11:56:56 +0300 Subject: ActivityPub: create replies for nested external replies --- .../src/main/java/com/juick/service/MessagesService.java | 2 ++ .../main/java/com/juick/server/api/activity/Profile.java | 14 ++++++++++++++ .../main/java/com/juick/service/MessagesServiceImpl.java | 6 ++++++ 3 files changed, 22 insertions(+) diff --git a/juick-common/src/main/java/com/juick/service/MessagesService.java b/juick-common/src/main/java/com/juick/service/MessagesService.java index 1bbd62f8..362501b5 100644 --- a/juick-common/src/main/java/com/juick/service/MessagesService.java +++ b/juick-common/src/main/java/com/juick/service/MessagesService.java @@ -67,6 +67,8 @@ public interface MessagesService { com.juick.Message getReply(int mid, int rid); + com.juick.Message getReplyByUri(String replyUri); + User getMessageAuthor(int mid); List getMessageRecommendations(int mid); 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 357ca29c..393b001b 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 @@ -1,6 +1,7 @@ package com.juick.server.api.activity; import com.fasterxml.jackson.databind.ObjectMapper; +import com.juick.Message; import com.juick.User; import com.juick.model.CommandResult; import com.juick.server.ActivityPubManager; @@ -321,6 +322,19 @@ public class Profile { } else { return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } + } else { + Message reply = messagesService.getReplyByUri(inReplyTo); + if (reply != null) { + User user = new User(); + user.setUri(URI.create(activity.getActor())); + String attachment = StringUtils.EMPTY; + if (note.get("attachment") != null && ((List) note.get("attachment")).size() > 0) { + Map attachmentObj = (Map) ((List) note.get("attachment")).get(0); + attachment = (String) attachmentObj.get("url"); + } + CommandResult result = commandsManager.processCommand(user, String.format("#%d/%d %s", reply.getMid(), reply.getRid(), note.get("content")), URI.create(attachment)); + logger.info(jsonMapper.writeValueAsString(result)); + } } } } 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 1d52e48a..65a4f116 100644 --- a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java +++ b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java @@ -436,6 +436,12 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ return list.isEmpty() ? null : list.get(0); } + @Override + public Message getReplyByUri(String replyUri) { + List replies = getJdbcTemplate().query("SELECT message_id, reply_id from replies WHERE reply_uri=?", (rs, rowNum) -> getReply(rs.getInt(1), rs.getInt(2)), replyUri); + return replies.isEmpty() ? null : replies.get(0); + } + @Transactional(readOnly = true) @Override public User getMessageAuthor(final int mid) { -- cgit v1.2.3