From c172469d601220c3a3b3c35e0de3409b7e23e78c Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 29 Mar 2024 21:50:19 +0300 Subject: Disable caching in development mode --- .../com/juick/service/MessagesServiceImpl.java | 39 +++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'src/main/java/com/juick/service/MessagesServiceImpl.java') diff --git a/src/main/java/com/juick/service/MessagesServiceImpl.java b/src/main/java/com/juick/service/MessagesServiceImpl.java index 91a257ef..940cdaba 100644 --- a/src/main/java/com/juick/service/MessagesServiceImpl.java +++ b/src/main/java/com/juick/service/MessagesServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2021, Juick + * Copyright (C) 2008-2024, Juick * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -23,6 +23,8 @@ import com.juick.www.WebApp; import com.juick.util.MessageUtils; import com.juick.util.TagUtils; +import io.pebbletemplates.pebble.PebbleEngine; +import io.pebbletemplates.pebble.template.PebbleTemplate; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; @@ -43,6 +45,9 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import javax.inject.Inject; +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; import java.net.URI; import java.sql.*; import java.time.Instant; @@ -71,6 +76,8 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ private String baseImagesUrl; @Inject private User archiveUser; + @Inject + private PebbleEngine pebbleEngine; private class MessageMapper implements RowMapper { @Override @@ -1208,4 +1215,34 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ int privacy = friendsOnly ? -1 : 1; jdbcTemplate.update("UPDATE messages SET privacy=? WHERE message_id=?", privacy, mid); } + + public Optional renderPlaintext(String body, String messageUrl) { + PebbleTemplate noteTemplate = pebbleEngine.getTemplate("email/plaintext"); + Map context = new HashMap<>(); + context.put("messageBody", body); + context.put("messageUrl", messageUrl); + try { + Writer writer = new StringWriter(); + noteTemplate.evaluate(writer, context); + return Optional.of(writer.toString()); + } catch (IOException e) { + return Optional.empty(); + } + } + + public Optional renderHtml(String body, String messageUrl, Message msg, String hash) { + PebbleTemplate noteTemplate = pebbleEngine.getTemplate("email/html"); + Map context = new HashMap<>(); + context.put("messageBody", body); + context.put("messageUrl", messageUrl); + context.put("msg", msg); + context.put("hash", hash); + try { + Writer writer = new StringWriter(); + noteTemplate.evaluate(writer, context); + return Optional.of(writer.toString()); + } catch (IOException e) { + return Optional.empty(); + } + } } -- cgit v1.2.3