diff options
Diffstat (limited to 'src/main/java/com/juick/www')
-rw-r--r-- | src/main/java/com/juick/www/WebApp.java | 24 | ||||
-rw-r--r-- | src/main/java/com/juick/www/rss/Feeds.java | 1 | ||||
-rw-r--r-- | src/main/java/com/juick/www/rss/MessagesView.java | 44 |
3 files changed, 46 insertions, 23 deletions
diff --git a/src/main/java/com/juick/www/WebApp.java b/src/main/java/com/juick/www/WebApp.java index 08f9fcd0..cebedb9b 100644 --- a/src/main/java/com/juick/www/WebApp.java +++ b/src/main/java/com/juick/www/WebApp.java @@ -16,26 +16,33 @@ */ package com.juick.www; +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Stream; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + 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; import org.springframework.web.servlet.resource.ResourceUrlProvider; import org.springframework.web.util.UriComponentsBuilder; -import javax.annotation.PostConstruct; -import javax.inject.Inject; -import java.io.IOException; -import java.io.StringWriter; -import java.io.Writer; -import java.util.*; -import java.util.stream.Stream; - /** * * @author Ugnich Anton @@ -97,6 +104,7 @@ 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<>(); diff --git a/src/main/java/com/juick/www/rss/Feeds.java b/src/main/java/com/juick/www/rss/Feeds.java index 8b396fd2..4423b263 100644 --- a/src/main/java/com/juick/www/rss/Feeds.java +++ b/src/main/java/com/juick/www/rss/Feeds.java @@ -55,6 +55,7 @@ public class Feeds { ModelAndView modelAndView = new ModelAndView(); modelAndView.setViewName("messagesView"); modelAndView.addObject("user", user); + modelAndView.addObject("feedType", feedType.name()); modelAndView.addObject("messages", messagesService.getMessages(visitor, mids)); return modelAndView; } diff --git a/src/main/java/com/juick/www/rss/MessagesView.java b/src/main/java/com/juick/www/rss/MessagesView.java index 06a42420..54983273 100644 --- a/src/main/java/com/juick/www/rss/MessagesView.java +++ b/src/main/java/com/juick/www/rss/MessagesView.java @@ -17,8 +17,10 @@ package com.juick.www.rss; +import com.juick.model.Attachment; import com.juick.model.Message; import com.juick.model.User; +import com.juick.service.ImagesService; import com.juick.www.rss.extension.JuickModule; import com.juick.www.rss.extension.JuickModuleImpl; import com.juick.www.WebApp; @@ -44,6 +46,8 @@ import javax.annotation.PostConstruct; import javax.inject.Inject; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + +import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.util.Collections; @@ -57,10 +61,12 @@ import java.util.stream.Collectors; */ public class MessagesView extends AbstractRssFeedView { - private static final Logger logger = LoggerFactory.getLogger(MessagesView.class); + private static final Logger logger = LoggerFactory.getLogger(Feeds.class); @Inject private WebApp webApp; + @Inject + private ImagesService imagesService; @PostConstruct public void init() { @@ -69,16 +75,16 @@ public class MessagesView extends AbstractRssFeedView { @SuppressWarnings("unchecked") @Override - protected List<Item> buildFeedItems(@Nonnull Map<String, Object> model, - @Nonnull HttpServletRequest request, - @Nonnull HttpServletResponse response) { - List<Message> msgs = (List<Message>)model.get("messages"); + protected List<Item> buildFeedItems(@Nonnull Map<String, Object> model, @Nonnull HttpServletRequest request, + @Nonnull HttpServletResponse response) { + List<Message> msgs = (List<Message>) model.get("messages"); return msgs.stream().map(this::createRssItem).collect(Collectors.toList()); } @Override protected void buildFeedMetadata(Map<String, Object> model, Channel feed, HttpServletRequest request) { Object userObj = model.get("user"); + String feedType = (String) model.get("feedType"); if (userObj != null) { User user = (User) userObj; feed.setDescription(String.format("The latest messages by @%s at Juick", user.getName())); @@ -86,12 +92,21 @@ public class MessagesView extends AbstractRssFeedView { feed.setTitle(title); String link = String.format("https://juick.com/%s/", user.getName()); feed.setLink(link); - Image rssImage = new Image(); - rssImage.setUrl(webApp.getAvatarUrl(user)); - rssImage.setTitle(title); - rssImage.setLink(link); - feed.setImage(rssImage); - String href = String.format("https://rss.juick.com/%s/blog", user.getName()); + try { + Image rssImage = new Image(); + rssImage.setUrl(webApp.getAvatarUrl(user)); + rssImage.setTitle(title); + rssImage.setLink(link); + Attachment avatar; + avatar = imagesService.getImageMetadata(rssImage.getUrl()); + rssImage.setHeight(avatar.getHeight()); + rssImage.setWidth(avatar.getWidth()); + feed.setImage(rssImage); + } catch (IOException e) { + logger.warn("Feed avatar not found for {}", user.getName()); + } + + String href = String.format("https://rss.juick.com/%s/%s", user.getName(), feedType); AtomLinkModule atomLinkModule = new AtomLinkModuleImpl(); Link atomLink = new Link(); atomLink.setHref(href); @@ -109,7 +124,6 @@ public class MessagesView extends AbstractRssFeedView { MediaModule mediaModule = new MediaModuleImpl(); feed.getModules().add(mediaModule); - } private Item createRssItem(Message msg) { @@ -120,7 +134,7 @@ public class MessagesView extends AbstractRssFeedView { String messageDescription = isCode ? MessageUtils.formatMessageCode(StringUtils.defaultString(msg.getText())) : MessageUtils.formatMessage(StringUtils.defaultString(msg.getText())); item.setLink(messageUrl); - //item.setGuid(messageUrl); + // item.setGuid(messageUrl); item.setTitle(messageTitle); Description description = new Description(); description.setType("text/html"); @@ -144,9 +158,9 @@ public class MessagesView extends AbstractRssFeedView { MediaContent mediaContent = new MediaContent(reference); mediaContent.setType(type); Metadata metadata = new Metadata(); - metadata.setThumbnail(new Thumbnail[]{new Thumbnail(new URI(msg.getPhoto().getThumbnail()))}); + metadata.setThumbnail(new Thumbnail[] { new Thumbnail(new URI(msg.getPhoto().getThumbnail())) }); module.setMetadata(metadata); - module.setMediaContents(new MediaContent[]{mediaContent}); + module.setMediaContents(new MediaContent[] { mediaContent }); item.getModules().add(module); } catch (URISyntaxException e) { logger.error("Invalid URI", e); |