diff options
author | Vitaly Takmazov | 2023-01-09 05:56:57 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-01-09 06:54:38 +0300 |
commit | d899fdeb4596759b2e22e20e407d7b65797b7123 (patch) | |
tree | 35be66ca4c4fd1b49d4cd530ad3f5d2e086a26c9 /src/main/java/com/juick/ActivityPubManager.java | |
parent | 68832dc5c36d970e297a84cb8f205cfcb7a01ce2 (diff) |
Mastodon API: improve status layout, avatars, attachments
Diffstat (limited to 'src/main/java/com/juick/ActivityPubManager.java')
-rw-r--r-- | src/main/java/com/juick/ActivityPubManager.java | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/main/java/com/juick/ActivityPubManager.java b/src/main/java/com/juick/ActivityPubManager.java index db8a1acb..b62be93a 100644 --- a/src/main/java/com/juick/ActivityPubManager.java +++ b/src/main/java/com/juick/ActivityPubManager.java @@ -283,6 +283,21 @@ public class ActivityPubManager implements ActivityListener, NotificationListene }); } + public String htmlLayout(Message msg, String baseUri) { + PebbleTemplate noteTemplate = pebbleEngine.getTemplate("layouts/note"); + Map<String, Object> context = new HashMap<>(); + context.put("msg", msg); + context.put("baseUri", profileUriBuilder.baseUri()); + try { + Writer writer = new StringWriter(); + noteTemplate.evaluate(writer, context); + return writer.toString(); + } catch (IOException e) { + logger.warn("template not rendered, falling back"); + return MessageUtils.formatMessage(StringUtils.defaultString(msg.getText())); + } + } + public Note makeNote(Message msg) { Note note = new Note(); note.setId(profileUriBuilder.messageUri(msg)); @@ -345,18 +360,7 @@ public class ActivityPubManager implements ActivityListener, NotificationListene if (msg.isHtml()) { note.setContent(msg.getText()); } else { - PebbleTemplate noteTemplate = pebbleEngine.getTemplate("layouts/note"); - Map<String, Object> context = new HashMap<>(); - context.put("msg", msg); - context.put("baseUri", profileUriBuilder.baseUri()); - try { - Writer writer = new StringWriter(); - noteTemplate.evaluate(writer, context); - note.setContent(writer.toString()); - } catch (IOException e) { - logger.warn("template not rendered, falling back"); - note.setContent(MessageUtils.formatMessage(StringUtils.defaultString(msg.getText()))); - } + note.setContent(htmlLayout(msg, profileUriBuilder.baseUri())); } return note; } |