Search in sources :

Example 11 with AvatarImage

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();
}
Also used : StoryAddedEvent(org.moera.node.model.event.StoryAddedEvent) AvatarImage(org.moera.node.model.AvatarImage) Story(org.moera.node.data.Story)

Example 12 with AvatarImage

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();
}
Also used : StoryAddedEvent(org.moera.node.model.event.StoryAddedEvent) AvatarImage(org.moera.node.model.AvatarImage) Story(org.moera.node.data.Story)

Example 13 with AvatarImage

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));
}
Also used : Comment(org.moera.node.data.Comment) Posting(org.moera.node.data.Posting) PostingCommentsChangedEvent(org.moera.node.model.event.PostingCommentsChangedEvent) PostingCommentDeletedNotification(org.moera.node.model.notification.PostingCommentDeletedNotification) AvatarImage(org.moera.node.model.AvatarImage) PostingCommentsUpdatedNotification(org.moera.node.model.notification.PostingCommentsUpdatedNotification) CommentDeletedEvent(org.moera.node.model.event.CommentDeletedEvent) LiberinMapping(org.moera.node.liberin.LiberinMapping)

Example 14 with AvatarImage

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;
}
Also used : SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) Util(org.moera.node.util.Util) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl) Inject(javax.inject.Inject) Story(org.moera.node.data.Story) StoryRepository(org.moera.node.data.StoryRepository) SyndImage(com.rometools.rome.feed.synd.SyndImage) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) GetMapping(org.springframework.web.bind.annotation.GetMapping) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) Transactional(javax.transaction.Transactional) Feed(org.moera.node.data.Feed) EntryRevision(org.moera.node.data.EntryRevision) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) ObjectUtils(org.springframework.util.ObjectUtils) PublicPageRepository(org.moera.node.data.PublicPageRepository) SyndContent(com.rometools.rome.feed.synd.SyndContent) Entry(org.moera.node.data.Entry) RequestContext(org.moera.node.global.RequestContext) SyndImageImpl(com.rometools.rome.feed.synd.SyndImageImpl) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) AvatarImage(org.moera.node.model.AvatarImage) List(java.util.List) PublicPage(org.moera.node.data.PublicPage) Comparator(java.util.Comparator) Collections(java.util.Collections) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndImageImpl(com.rometools.rome.feed.synd.SyndImageImpl) SyndImage(com.rometools.rome.feed.synd.SyndImage) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl) RequestContext(org.moera.node.global.RequestContext) PublicPage(org.moera.node.data.PublicPage) AvatarImage(org.moera.node.model.AvatarImage) Story(org.moera.node.data.Story) GetMapping(org.springframework.web.bind.annotation.GetMapping) Transactional(javax.transaction.Transactional) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 15 with AvatarImage

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";
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) PageNotFoundException(org.moera.node.global.PageNotFoundException) RequestParam(org.springframework.web.bind.annotation.RequestParam) StoryInfo(org.moera.node.model.StoryInfo) PostingInfo(org.moera.node.model.PostingInfo) CommentPublicPageOperations(org.moera.node.operations.CommentPublicPageOperations) Posting(org.moera.node.data.Posting) Inject(javax.inject.Inject) Story(org.moera.node.data.Story) StoryRepository(org.moera.node.data.StoryRepository) Model(org.springframework.ui.Model) TimelinePublicPageOperations(org.moera.node.operations.TimelinePublicPageOperations) GetMapping(org.springframework.web.bind.annotation.GetMapping) Body(org.moera.node.model.body.Body) Comment(org.moera.node.data.Comment) CommentInfo(org.moera.node.model.CommentInfo) Transactional(javax.transaction.Transactional) Feed(org.moera.node.data.Feed) NamingCache(org.moera.node.naming.NamingCache) ObjectUtils(org.springframework.util.ObjectUtils) HttpServletResponse(javax.servlet.http.HttpServletResponse) UiController(org.moera.node.global.UiController) PublicPageRepository(org.moera.node.data.PublicPageRepository) Entry(org.moera.node.data.Entry) UUID(java.util.UUID) RequestContext(org.moera.node.global.RequestContext) Collectors(java.util.stream.Collectors) PostingRepository(org.moera.node.data.PostingRepository) VirtualPage(org.moera.node.global.VirtualPage) AvatarImage(org.moera.node.model.AvatarImage) Objects(java.util.Objects) List(java.util.List) CommentRepository(org.moera.node.data.CommentRepository) EntryAttachment(org.moera.node.data.EntryAttachment) VirtualPageHeader(org.moera.node.util.VirtualPageHeader) PrivateMediaFileInfo(org.moera.node.model.PrivateMediaFileInfo) PublicPage(org.moera.node.data.PublicPage) Comparator(java.util.Comparator) Collections(java.util.Collections) Comment(org.moera.node.data.Comment) Posting(org.moera.node.data.Posting) CommentInfo(org.moera.node.model.CommentInfo) PublicPage(org.moera.node.data.PublicPage) PrivateMediaFileInfo(org.moera.node.model.PrivateMediaFileInfo) PageNotFoundException(org.moera.node.global.PageNotFoundException) Entry(org.moera.node.data.Entry) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) EntryAttachment(org.moera.node.data.EntryAttachment) AvatarImage(org.moera.node.model.AvatarImage) Story(org.moera.node.data.Story) Body(org.moera.node.model.body.Body) GetMapping(org.springframework.web.bind.annotation.GetMapping) Transactional(javax.transaction.Transactional)

Aggregations

AvatarImage (org.moera.node.model.AvatarImage)21 Story (org.moera.node.data.Story)11 StoryAddedEvent (org.moera.node.model.event.StoryAddedEvent)9 Comment (org.moera.node.data.Comment)5 UUID (java.util.UUID)4 Posting (org.moera.node.data.Posting)4 Entry (org.moera.node.data.Entry)3 Collections (java.util.Collections)2 Comparator (java.util.Comparator)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 Transactional (javax.transaction.Transactional)2 Feed (org.moera.node.data.Feed)2 MediaFile (org.moera.node.data.MediaFile)2 PublicPage (org.moera.node.data.PublicPage)2 PublicPageRepository (org.moera.node.data.PublicPageRepository)2 StoryRepository (org.moera.node.data.StoryRepository)2 RequestContext (org.moera.node.global.RequestContext)2 LiberinMapping (org.moera.node.liberin.LiberinMapping)2