From 4c39169bee102b2bfa82b55717a3a4aa75297946 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 28 Dec 2019 18:51:46 +0300 Subject: ActivityPub: fix formatting note with attachments --- src/main/java/com/juick/server/api/activity/Profile.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/main') diff --git a/src/main/java/com/juick/server/api/activity/Profile.java b/src/main/java/com/juick/server/api/activity/Profile.java index 8e735642..9aa9dc37 100644 --- a/src/main/java/com/juick/server/api/activity/Profile.java +++ b/src/main/java/com/juick/server/api/activity/Profile.java @@ -323,8 +323,7 @@ public class Profile { String attachmentUrl = attachment.get("url"); String attachmentName = attachment.get("name"); return PlainTextFormatter.markdownUrl(attachmentUrl, attachmentName); - }).reduce((source, url) -> String.format("%s\n%s", source, url)) - .orElse(markdown); + }).reduce(markdown, (currentUrl, nextUrl) -> String.format("%s\n%s", currentUrl, nextUrl)); CommandResult result = commandsManager.processCommand( user, String.format("#%s %s", postId, commandBody), @@ -342,14 +341,14 @@ public class Profile { User user = new User(); user.setUri(URI.create(activity.getActor())); String markdown = remarkConverter.convertFragment((String)note.get("content")); + // combine note text with attachment urls String commandBody = note.get("attachment") == null ? markdown : ((List) note.get("attachment")).stream().map(attachmentObj -> { Map attachment = (Map) attachmentObj; String attachmentUrl = attachment.get("url"); String attachmentName = attachment.get("name"); return PlainTextFormatter.markdownUrl(attachmentUrl, attachmentName); - }).reduce((source, url) -> String.format("%s\n%s", source, url)) - .orElse(markdown); + }).reduce(markdown, (currentUrl, nextUrl) -> String.format("%s\n%s", currentUrl, nextUrl)); CommandResult result = commandsManager.processCommand( user, String.format("#%d/%d %s", reply.getMid(), reply.getRid(), commandBody), -- cgit v1.2.3