aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/server/www
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2020-03-07 16:01:52 +0300
committerGravatar Vitaly Takmazov2020-03-07 16:01:52 +0300
commitafb897034311fe7e0e981ec44100d3b3fd3ef39d (patch)
tree6104cab72b5eaae4b499e35b7bbc93be875e4336 /src/main/java/com/juick/server/www
parentc9d67837cbcaae84a03b7bd14e508ca62880f87f (diff)
Load EmailManager conditionally
Diffstat (limited to 'src/main/java/com/juick/server/www')
-rw-r--r--src/main/java/com/juick/server/www/WebApp.java41
1 files changed, 38 insertions, 3 deletions
diff --git a/src/main/java/com/juick/server/www/WebApp.java b/src/main/java/com/juick/server/www/WebApp.java
index 8476224d..bf013c3b 100644
--- a/src/main/java/com/juick/server/www/WebApp.java
+++ b/src/main/java/com/juick/server/www/WebApp.java
@@ -16,9 +16,12 @@
*/
package com.juick.server.www;
+import com.juick.model.Message;
import com.juick.model.Tag;
import com.juick.model.User;
import com.juick.service.TagService;
+import com.mitchellbosecke.pebble.PebbleEngine;
+import com.mitchellbosecke.pebble.template.PebbleTemplate;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@@ -27,9 +30,10 @@ import org.springframework.web.util.UriComponentsBuilder;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.*;
import java.util.stream.Stream;
/**
@@ -42,6 +46,8 @@ public class WebApp {
private TagService tagService;
@Inject
private ResourceUrlProvider resourceUrlProvider;
+ @Inject
+ private PebbleEngine pebbleEngine;
@Value("${img_url:http://localhost:8080/i/}")
private String baseImagesUri;
UriComponentsBuilder avatarBuilder;
@@ -91,4 +97,33 @@ public class WebApp {
avatarBuilder.replacePath(getAvatarWebPath(user));
return avatarBuilder.build().toUriString();
}
+ public Optional<String> renderPlaintext(String body, String messageUrl) {
+ PebbleTemplate noteTemplate = pebbleEngine.getTemplate("email/plaintext");
+ Map<String, Object> 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<String> renderHtml(String body, String messageUrl, Message msg, String hash) {
+ PebbleTemplate noteTemplate = pebbleEngine.getTemplate("email/html");
+ Map<String, Object> 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();
+ }
+ }
}