Package net.pterodactylus.sone.data

Examples of net.pterodactylus.sone.data.Sone


  protected JsonReturnObject createJsonObject(FreenetRequest request) {
    String soneId = request.getHttpRequest().getParam("sone");
    if (!webInterface.getCore().getSone(soneId).isPresent()) {
      return createErrorJsonObject("invalid-sone-id");
    }
    Sone currentSone = getCurrentSone(request.getToadletContext());
    if (currentSone == null) {
      return createErrorJsonObject("auth-required");
    }
    webInterface.getCore().unfollowSone(currentSone, soneId);
    return createSuccessJsonObject();
View Full Code Here


    String type = request.getHttpRequest().getParam("type", null);
    String id = request.getHttpRequest().getParam(type, null);
    if ((id == null) || (id.length() == 0)) {
      return createErrorJsonObject("invalid-" + type + "-id");
    }
    Sone currentSone = getCurrentSone(request.getToadletContext());
    if (currentSone == null) {
      return createErrorJsonObject("auth-required");
    }
    if ("post".equals(type)) {
      currentSone.addLikedPostId(id);
      webInterface.getCore().touchConfiguration();
    } else if ("reply".equals(type)) {
      currentSone.addLikedReplyId(id);
      webInterface.getCore().touchConfiguration();
    } else {
      return createErrorJsonObject("invalid-type");
    }
    return createSuccessJsonObject();
View Full Code Here

  /**
   * {@inheritDoc}
   */
  @Override
  public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
    Sone sone = getSone(parameters, "Sone", false);
    int startPost = getInt(parameters, "StartPost", 0);
    int maxPosts = getInt(parameters, "MaxPosts", -1);
    List<Post> posts = sone.getPosts();
    if (posts.size() < startPost) {
      return new Response("Posts", encodePosts(Collections.<Post> emptyList(), "Posts.", false));
    }
    return new Response("Posts", encodePosts(sone.getPosts().subList(startPost, (maxPosts == -1) ? posts.size() : Math.min(startPost + maxPosts, posts.size())), "Posts.", true));
  }
View Full Code Here

  /**
   * {@inheritDoc}
   */
  @Override
  public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
    Sone sone = getSone(parameters, "Sone", true);
    String text = getString(parameters, "Text");
    Sone recipient = null;
    if (parameters.get("Recipient") != null) {
      recipient = getSone(parameters, "Recipient", false);
    }
    if (sone.equals(recipient)) {
      return new ErrorResponse("Sone and Recipient must not be the same.");
View Full Code Here

  /**
   * {@inheritDoc}
   */
  @Override
  public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
    Sone sone = getSone(parameters, "Sone", false);
    Optional<Sone> localSone = getSone(parameters, "LocalSone", false, false);
    return new Response("Sone", encodeSone(sone, "", localSone));
  }
View Full Code Here

   * {@inheritDoc}
   */
  @Override
  public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
    PostReply reply = getReply(parameters, "Reply");
    Sone sone = getSone(parameters, "Sone", true);
    sone.addLikedReplyId(reply.getId());
    return new Response("ReplyLiked", new SimpleFieldSetBuilder().put("LikeCount", getCore().getLikes(reply).size()).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

  /**
   * {@inheritDoc}
   */
  @Override
  public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
    Sone sone = getSone(parameters, "Sone", true);
    int startPost = getInt(parameters, "StartPost", 0);
    int maxPosts = getInt(parameters, "MaxPosts", -1);

    Collection<Post> allPosts = new HashSet<Post>();
    allPosts.addAll(sone.getPosts());
    for (String friendSoneId : sone.getFriends()) {
      Optional<Sone> friendSone = getCore().getSone(friendSoneId);
      if (!friendSone.isPresent()) {
        continue;
      }
      allPosts.addAll(friendSone.get().getPosts());
    }
    allPosts.addAll(getCore().getDirectedPosts(sone.getId()));
    allPosts = Collections2.filter(allPosts, Post.FUTURE_POSTS_FILTER);

    List<Post> sortedPosts = new ArrayList<Post>(allPosts);
    Collections.sort(sortedPosts, Post.TIME_COMPARATOR);

View Full Code Here

   * @return {@code true} if the post is considered visible, {@code false}
   *         otherwise
   */
  public static boolean isPostVisible(Sone sone, Post post) {
    checkNotNull(post, "post must not be null");
    Sone postSone = post.getSone();
    if (postSone == null) {
      return false;
    }
    if (sone != null) {
      Trust trust = postSone.getIdentity().getTrust((OwnIdentity) sone.getIdentity());
      if (trust != null) {
        if ((trust.getExplicit() != null) && (trust.getExplicit() < 0)) {
          return false;
        }
        if ((trust.getExplicit() == null) && (trust.getImplicit() != null) && (trust.getImplicit() < 0)) {
          return false;
        }
      } else {
        /*
         * a null trust means that the trust updater has not yet
         * received a trust value for this relation. if we return false,
         * the post feed will stay empty until the trust updater has
         * received trust values. to prevent this we simply assume that
         * posts are visible if there is no trust.
         */
      }
      if ((!postSone.equals(sone)) && !sone.hasFriend(postSone.getId()) && !sone.getId().equals(post.getRecipientId().orNull())) {
        return false;
      }
    }
    if (post.getTime() > System.currentTimeMillis()) {
      return false;
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

TOP

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

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.