Package net.pterodactylus.sone.data

Examples of net.pterodactylus.sone.data.Post


    String text = request.getHttpRequest().getParam("text");
    if ((text == null) || (text.trim().length() == 0)) {
      return createErrorJsonObject("text-required");
    }
    text = TextFilter.filter(request.getHttpRequest().getHeader("host"), text);
    Post newPost = webInterface.getCore().createPost(sender, recipient, text);
    return createSuccessJsonObject().put("postId", newPost.getId()).put("sone", sender.getId()).put("recipient", newPost.getRecipientId().orNull());
  }
View Full Code Here


   * @param newPostFoundEvent
   *            The event
   */
  @Subscribe
  public void newPostFound(NewPostFoundEvent newPostFoundEvent) {
    Post post = newPostFoundEvent.post();
    boolean isLocal = post.getSone().isLocal();
    if (isLocal) {
      localPostNotification.add(post);
    } else {
      newPostNotification.add(post);
    }
    if (!hasFirstStartNotification()) {
      notificationManager.addNotification(isLocal ? localPostNotification : newPostNotification);
      if (!getMentionedSones(post.getText()).isEmpty() && !isLocal) {
        mentionNotification.add(post);
        notificationManager.addNotification(mentionNotification);
      }
    } else {
      getCore().markPostKnown(post);
View Full Code Here

   * {@inheritDocs}
   */
  @Override
  public Post build() throws IllegalStateException {
    validate();
    Post post = new MemoryPost(database, soneProvider, randomId ? UUID.randomUUID().toString() : id, senderId, recipientId, currentTime ? System.currentTimeMillis() : time, text);
    post.setKnown(database.isPostKnown(post));
    return post;
  }
View Full Code Here

      recipient = getSone(parameters, "Recipient", false);
    }
    if (sone.equals(recipient)) {
      return new ErrorResponse("Sone and Recipient must not be the same.");
    }
    Post post = getCore().createPost(sone, Optional.fromNullable(recipient), text);
    return new Response("PostCreated", new SimpleFieldSetBuilder().put("Post", post.getId()).get());
  }
View Full Code Here

   * {@inheritDoc}
   */
  @Override
  public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
    Sone sone = getSone(parameters, "Sone", true);
    Post post = getPost(parameters, "Post");
    String text = getString(parameters, "Text");
    PostReply reply = getCore().createReply(sone, post, text);
    return new Response("ReplyCreated", new SimpleFieldSetBuilder().put("Reply", reply.getId()).get());
  }
View Full Code Here

    PostBuilder postBuilder = database.newPostBuilder();
    postBuilder.from(sone.getId()).randomId().withTime(time).withText(text.trim());
    if (recipient.isPresent()) {
      postBuilder.to(recipient.get().getId());
    }
    final Post post = postBuilder.build();
    database.storePost(post);
    eventBus.post(new NewPostFoundEvent(post));
    sone.addPost(post);
    touchConfiguration();
    localElementTicker.schedule(new Runnable() {
View Full Code Here

  /**
   * {@inheritDoc}
   */
  @Override
  public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
    Post post = getPost(parameters, "Post");
    if (!post.getSone().isLocal()) {
      return new ErrorResponse(401, "Not allowed.");
    }
    return new Response("PostDeleted", new SimpleFieldSetBuilder().get());
  }
View Full Code Here

  /**
   * {@inheritDoc}
   */
  @Override
  public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
    Post post = getPost(parameters, "Post");
    boolean includeReplies = getBoolean(parameters, "IncludeReplies", true);

    return new Response("Post", encodePost(post, "Post.", includeReplies));
  }
View Full Code Here

  /**
   * {@inheritDoc}
   */
  @Override
  public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
    Post post = getPost(parameters, "Post");
    Sone sone = getSone(parameters, "Sone", true);
    sone.addLikedPostId(post.getId());
    return new Response("PostLiked", new SimpleFieldSetBuilder().put("LikeCount", getCore().getLikes(post).size()).get());
  }
View Full Code Here

  /**
   * {@inheritDoc}
   */
  @Override
  public Object get(TemplateContext templateContext, Object object, String member) {
    Post post = (Post) object;
    if ("replies".equals(member)) {
      return Collections2.filter(core.getReplies(post.getId()), Reply.FUTURE_REPLY_FILTER);
    } else if (member.equals("likes")) {
      return core.getLikes(post);
    } else if (member.equals("liked")) {
      Sone currentSone = (Sone) templateContext.get("currentSone");
      return (currentSone != null) && (currentSone.isLikedPostId(post.getId()));
    } else if (member.equals("new")) {
      return !post.isKnown();
    } else if (member.equals("bookmarked")) {
      return core.isBookmarked(post);
    } else if (member.equals("loaded")) {
      return post.getSone() != null;
    }
    return super.get(templateContext, object, member);
  }
View Full Code Here

TOP

Related Classes of net.pterodactylus.sone.data.Post

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.