use of org.moera.node.global.RequestContext in project moera-node by MoeraOrg.
the class TitleBuilder method build.
public CharSequence build(String title) {
StringBuilder buf = new StringBuilder();
if (!ObjectUtils.isEmpty(title)) {
buf.append(title);
buf.append(' ');
String name = "";
try {
RequestContext rcp = requestContext.getPublic();
name = rcp.fullName() != null ? rcp.fullName() : rcp.nodeName();
} catch (Exception e) {
}
if (!ObjectUtils.isEmpty(name)) {
buf.append("@ ");
buf.append(NodeName.shorten(name));
buf.append(' ');
}
}
if (buf.length() > 0) {
buf.append("| ");
}
buf.append("Moera");
return buf;
}
use of org.moera.node.global.RequestContext in project moera-node by MoeraOrg.
the class RssController method rss.
@GetMapping("/rss")
@Transactional
@ResponseBody
public SyndFeed rss() {
RequestContext rcp = requestContext.getPublic();
PublicPage publicPage = publicPageRepository.findContaining(rcp.nodeId(), Long.MAX_VALUE);
List<Story> stories = Collections.emptyList();
if (publicPage != null) {
stories = storyRepository.findInRange(rcp.nodeId(), Feed.TIMELINE, publicPage.getAfterMoment(), publicPage.getBeforeMoment()).stream().filter(t -> t.getEntry().isMessage()).sorted(Collections.reverseOrder(Comparator.comparingLong(Story::getMoment))).collect(Collectors.toList());
}
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType("rss_2.0");
String name = rcp.fullName() != null ? rcp.fullName() : rcp.nodeName();
String title = !ObjectUtils.isEmpty(name) ? name + " - Moera" : "Moera";
feed.setTitle(title);
feed.setLink(rcp.getSiteUrl() + "/");
if (rcp.avatarId() != null) {
SyndImage image = new SyndImageImpl();
image.setTitle(title);
image.setUrl(rcp.getSiteUrl() + "/moera/media/" + new AvatarImage(rcp.getAvatar()).getPath());
image.setLink(rcp.getSiteUrl() + "/");
feed.setImage(image);
}
feed.setDescription(title);
feed.setLanguage("en-us");
feed.setPublishedDate(!stories.isEmpty() ? stories.get(0).getCreatedAt() : Util.now());
feed.setGenerator("moera-node");
feed.setWebMaster(buildWebmaster());
feed.setEntries(stories.stream().map(this::buildEntry).collect(Collectors.toList()));
return feed;
}
Aggregations