Package net.pterodactylus.sone.freenet

Examples of net.pterodactylus.sone.freenet.SimpleFieldSetBuilder


  public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
    PostReply reply = getReply(parameters, "Reply");
    if (!reply.getSone().isLocal()) {
      return new ErrorResponse(401, "Not allowed.");
    }
    return new Response("ReplyDeleted", new SimpleFieldSetBuilder().get());
  }
View Full Code Here


    }
    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

  @Override
  public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
    Optional<Sone> sone = getSone(parameters, "Sone", true, true);
    getCore().unlockSone(sone.get());
    return new Response("SoneUnlocked", new SimpleFieldSetBuilder().put("Sone", sone.get().getId()).get());
  }
View Full Code Here

  @Override
  public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
    Optional<Sone> sone = getSone(parameters, "Sone", true, true);
    getCore().lockSone(sone.get());
    return new Response("SoneLocked", new SimpleFieldSetBuilder().put("Sone", sone.get().getId()).get());
  }
View Full Code Here

  @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) {
    return new Response("Version", new SimpleFieldSetBuilder().put("Version", SonePlugin.VERSION.toString()).put("ProtocolVersion", 1).get());
  }
View Full Code Here

  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

  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

   *            An optional local Sone that is used for Sone-specific data,
   *            such as if the Sone is followed by the local Sone
   * @return The simple field set containing the given Sone
   */
  protected static SimpleFieldSet encodeSone(Sone sone, String prefix, Optional<Sone> localSone) {
    SimpleFieldSetBuilder soneBuilder = new SimpleFieldSetBuilder();

    soneBuilder.put(prefix + "Name", sone.getName());
    soneBuilder.put(prefix + "NiceName", SoneAccessor.getNiceName(sone));
    soneBuilder.put(prefix + "LastUpdated", sone.getTime());
    if (localSone.isPresent()) {
      soneBuilder.put(prefix + "Followed", String.valueOf(localSone.get().hasFriend(sone.getId())));
    }
    Profile profile = sone.getProfile();
    soneBuilder.put(prefix + "Field.Count", profile.getFields().size());
    int fieldIndex = 0;
    for (Field field : profile.getFields()) {
      soneBuilder.put(prefix + "Field." + fieldIndex + ".Name", field.getName());
      soneBuilder.put(prefix + "Field." + fieldIndex + ".Value", field.getValue());
      ++fieldIndex;
    }

    return soneBuilder.get();
  }
View Full Code Here

   *            The prefix for the field names (may be empty but not
   *            {@code null})
   * @return The simple field set containing the given Sones
   */
  protected static SimpleFieldSet encodeSones(Collection<? extends Sone> sones, String prefix) {
    SimpleFieldSetBuilder soneBuilder = new SimpleFieldSetBuilder();

    int soneIndex = 0;
    soneBuilder.put(prefix + "Count", sones.size());
    for (Sone sone : sones) {
      String sonePrefix = prefix + soneIndex++ + ".";
      soneBuilder.put(sonePrefix + "ID", sone.getId());
      soneBuilder.put(sonePrefix + "Name", sone.getName());
      soneBuilder.put(sonePrefix + "NiceName", SoneAccessor.getNiceName(sone));
      soneBuilder.put(sonePrefix + "Time", sone.getTime());
    }

    return soneBuilder.get();
  }
View Full Code Here

TOP

Related Classes of net.pterodactylus.sone.freenet.SimpleFieldSetBuilder

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.