use of org.moera.node.model.AvatarImage in project moera-node by MoeraOrg.
the class PostingMediaReactionInstants method addingFailed.
public void addingFailed(String postingId, String parentPostingId, String parentMediaId, PostingInfo parentPostingInfo) {
String parentOwnerName = parentPostingInfo != null ? parentPostingInfo.getOwnerName() : "";
String parentOwnerFullName = parentPostingInfo != null ? parentPostingInfo.getOwnerFullName() : null;
AvatarImage parentOwnerAvatar = parentPostingInfo != null ? parentPostingInfo.getOwnerAvatar() : null;
String parentHeading = parentPostingInfo != null ? parentPostingInfo.getHeading() : "";
Story story = new Story(UUID.randomUUID(), nodeId(), StoryType.POSTING_MEDIA_REACTION_FAILED);
story.setFeedName(Feed.INSTANT);
story.setRemoteNodeName(parentOwnerName);
story.setRemoteFullName(parentOwnerFullName);
if (parentOwnerAvatar != null) {
story.setRemoteAvatarMediaFile(parentOwnerAvatar.getMediaFile());
story.setRemoteAvatarShape(parentOwnerAvatar.getShape());
}
story.setRemotePostingId(postingId);
story.setRemoteParentPostingId(parentPostingId);
story.setRemoteParentMediaId(parentMediaId);
story.setSummary(buildAddingFailedSummary(parentOwnerName, parentOwnerFullName, parentHeading));
story.setPublishedAt(Util.now());
updateMoment(story);
story = storyRepository.save(story);
send(new StoryAddedEvent(story, true));
sendPush(story);
feedStatusUpdated();
}
use of org.moera.node.model.AvatarImage in project moera-node by MoeraOrg.
the class PostingReactionInstants method addingFailed.
public void addingFailed(String postingId, PostingInfo postingInfo) {
String postingOwnerName = postingInfo != null ? postingInfo.getOwnerName() : "";
String postingOwnerFullName = postingInfo != null ? postingInfo.getOwnerFullName() : null;
AvatarImage postingOwnerAvatar = postingInfo != null ? postingInfo.getOwnerAvatar() : null;
String postingHeading = postingInfo != null ? postingInfo.getHeading() : "";
Story story = new Story(UUID.randomUUID(), nodeId(), StoryType.POSTING_REACTION_TASK_FAILED);
story.setFeedName(Feed.INSTANT);
story.setRemoteNodeName(postingOwnerName);
story.setRemoteFullName(postingOwnerFullName);
if (postingOwnerAvatar != null) {
story.setRemoteOwnerAvatarMediaFile(postingOwnerAvatar.getMediaFile());
story.setRemoteOwnerAvatarShape(postingOwnerAvatar.getShape());
}
story.setRemotePostingId(postingId);
story.setSummary(buildAddingFailedSummary(postingOwnerName, postingOwnerFullName, postingHeading));
story.setPublishedAt(Util.now());
updateMoment(story);
story = storyRepository.save(story);
send(new StoryAddedEvent(story, true));
sendPush(story);
feedStatusUpdated();
}
use of org.moera.node.model.AvatarImage in project moera-node by MoeraOrg.
the class CommentReceptor method deleted.
@LiberinMapping
public void deleted(CommentDeletedLiberin liberin) {
Comment comment = liberin.getComment();
Posting posting = comment.getPosting();
notifyReplyDeleted(posting, comment);
notifyMentioned(posting, comment.getId(), comment.getOwnerName(), comment.getOwnerFullName(), new AvatarImage(comment.getOwnerAvatarMediaFile(), comment.getOwnerAvatarShape()), null, liberin.getLatestRevision());
send(Directions.postingSubscribers(comment.getNodeId(), posting.getId()), new PostingCommentsUpdatedNotification(posting.getId(), posting.getTotalChildren()));
send(Directions.postingCommentsSubscribers(comment.getNodeId(), posting.getId()), new PostingCommentDeletedNotification(posting.getId(), comment.getId(), comment.getOwnerName(), comment.getOwnerFullName(), new AvatarImage(comment.getOwnerAvatarMediaFile(), comment.getOwnerAvatarShape())));
send(liberin, new CommentDeletedEvent(comment));
send(liberin, new PostingCommentsChangedEvent(posting));
}
use of org.moera.node.model.AvatarImage 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;
}
use of org.moera.node.model.AvatarImage in project moera-node by MoeraOrg.
the class TimelineUiController method posting.
@GetMapping("/post/{id}")
@Transactional
public String posting(@PathVariable UUID id, @RequestParam(required = false) Long before, @RequestParam(name = "comment", required = false) UUID commentId, @RequestParam(name = "media", required = false) UUID mediaId, HttpServletResponse response, Model model) {
UriComponentsBuilder builder = UriComponentsBuilder.fromPath("/post/" + id);
if (commentId != null) {
builder = builder.queryParam("comment", commentId);
}
String canonicalUrl = builder.build().toUriString();
if (mediaId != null) {
builder = builder.queryParam("media", mediaId);
}
VirtualPageHeader.put(response, builder.build().toUriString());
if (requestContext.isBrowserExtension()) {
return null;
}
Posting posting = postingRepository.findFullByNodeIdAndId(requestContext.nodeId(), id).orElse(null);
if (posting == null || !posting.isMessage() || posting.getParentMedia() != null) {
throw new PageNotFoundException();
}
List<Story> stories = storyRepository.findByEntryId(requestContext.nodeId(), id);
model.addAttribute("pageTitle", titleBuilder.build(posting.getCurrentRevision().getHeading()));
model.addAttribute("menuIndex", "timeline");
model.addAttribute("posting", PostingInfo.forUi(posting, stories));
model.addAttribute("canonicalUrl", canonicalUrl);
model.addAttribute("openComments", commentId != null || before != null);
model.addAttribute("openMediaPostingId", id.toString());
model.addAttribute("openMediaCommentId", commentId != null ? commentId.toString() : null);
model.addAttribute("openMediaId", Objects.toString(mediaId, null));
Comment comment = commentId != null && posting.isOriginal() ? commentRepository.findFullByNodeIdAndId(requestContext.nodeId(), commentId).orElse(null) : null;
if (posting.isOriginal()) {
before = comment != null ? comment.getMoment() : before;
before = before != null ? before : Long.MIN_VALUE + 1;
List<CommentInfo> comments = Collections.emptyList();
PublicPage publicPage = publicPageRepository.findContainingForEntry(requestContext.nodeId(), id, before);
if (publicPage != null) {
comments = commentRepository.findInRange(requestContext.nodeId(), id, publicPage.getAfterMoment(), publicPage.getBeforeMoment()).stream().filter(Comment::isMessage).map(CommentInfo::forUi).sorted(Comparator.comparing(CommentInfo::getMoment)).collect(Collectors.toList());
}
if (commentId != null) {
model.addAttribute("anchor", "comment-" + commentId);
}
model.addAttribute("comments", comments);
model.addAttribute("commentId", Objects.toString(commentId, null));
model.addAttribute("pagination", commentPublicPageOperations.createPagination(publicPage));
} else {
model.addAttribute("originalHref", NamingCache.getRedirector(posting.getReceiverName(), entryLocation(posting.getReceiverEntryId(), null)));
model.addAttribute("commentsHref", NamingCache.getRedirector(posting.getReceiverName(), entryLocation(posting.getReceiverEntryId(), commentId)));
}
model.addAttribute("ogUrl", requestContext.getSiteUrl() + entryLocation(posting.getId(), commentId));
model.addAttribute("ogType", "article");
Entry entry = comment != null ? comment : posting;
String subject = new Body(entry.getCurrentRevision().getBody()).getSubject();
model.addAttribute("ogTitle", !ObjectUtils.isEmpty(subject) ? subject : "(no title)");
EntryAttachment attachment = entry.getCurrentRevision().getAttachments().stream().sorted(Comparator.comparingInt(EntryAttachment::getOrdinal)).filter(ea -> mediaId == null || ea.getMediaFileOwner().getId().equals(mediaId)).filter(// an image
ea -> ea.getMediaFileOwner().getMediaFile().getSizeX() != null).findFirst().orElse(null);
if (attachment != null) {
PrivateMediaFileInfo image = new PrivateMediaFileInfo(attachment.getMediaFileOwner(), posting.getReceiverName());
model.addAttribute("ogImage", requestContext.getSiteUrl() + "/moera/media/" + image.getPath());
model.addAttribute("ogImageType", attachment.getMediaFileOwner().getMediaFile().getMimeType());
model.addAttribute("ogImageWidth", image.getWidth());
model.addAttribute("ogImageHeight", image.getHeight());
} else if (entry.getOwnerAvatarMediaFile() != null) {
AvatarImage avatarImage = new AvatarImage(entry.getOwnerAvatarMediaFile(), entry.getOwnerAvatarShape());
model.addAttribute("ogImage", requestContext.getSiteUrl() + "/moera/media/" + avatarImage.getPath());
model.addAttribute("ogImageType", avatarImage.getMediaFile().getMimeType());
model.addAttribute("ogImageWidth", avatarImage.getWidth());
model.addAttribute("ogImageHeight", avatarImage.getHeight());
}
String description = entry.getCurrentRevision().getDescription();
description = !ObjectUtils.isEmpty(description) ? description : entry.getCurrentRevision().getHeading();
model.addAttribute("ogDescription", description);
var createdAt = entry.getReceiverCreatedAt() != null ? entry.getReceiverCreatedAt() : entry.getCreatedAt();
model.addAttribute("ogArticlePublishedTime", createdAt.toInstant().toString());
if (entry.getEditedAt() != null) {
var editedAt = entry.getReceiverEditedAt() != null ? entry.getReceiverEditedAt() : entry.getEditedAt();
model.addAttribute("ogArticleModifiedTime", editedAt.toInstant().toString());
}
return "posting";
}
Aggregations