Package net.pterodactylus.sone.data

Examples of net.pterodactylus.sone.data.Sone


   *            {@code false} to return null if none exists
   * @return The Sone with the given ID, or {@code null}
   */
  public Sone getLocalSone(String id, boolean create) {
    synchronized (sones) {
      Sone sone = sones.get(id);
      if ((sone == null) && create) {
        sone = new SoneImpl(id, true);
        sones.put(id, sone);
      }
      if ((sone != null) && !sone.isLocal()) {
        sone = new SoneImpl(id, true);
        sones.put(id, sone);
      }
      return sone;
    }
View Full Code Here


   *            {@code null} if no Sone with the given ID exists
   * @return The Sone with the given ID
   */
  public Sone getRemoteSone(String id, boolean create) {
    synchronized (sones) {
      Sone sone = sones.get(id);
      if ((sone == null) && create && (id != null) && (id.length() == 43)) {
        sone = new SoneImpl(id, false);
        sones.put(id, sone);
      }
      return sone;
View Full Code Here

      logger.log(Level.WARNING, "Given OwnIdentity is null!");
      return null;
    }
    logger.info(String.format("Adding Sone from OwnIdentity: %s", ownIdentity));
    synchronized (sones) {
      final Sone sone;
      try {
        sone = getLocalSone(ownIdentity.getId(), true).setIdentity(ownIdentity).setInsertUri(new FreenetURI(ownIdentity.getInsertUri())).setRequestUri(new FreenetURI(ownIdentity.getRequestUri()));
      } catch (MalformedURLException mue1) {
        logger.log(Level.SEVERE, String.format("Could not convert the Identity’s URIs to Freenet URIs: %s, %s", ownIdentity.getInsertUri(), ownIdentity.getRequestUri()), mue1);
        return null;
      }
      sone.setLatestEdition(Numbers.safeParseLong(ownIdentity.getProperty("Sone.LatestEdition"), (long) 0));
      sone.setClient(new Client("Sone", SonePlugin.VERSION.toString()));
      sone.setKnown(true);
      /* TODO - load posts ’n stuff */
      sones.put(ownIdentity.getId(), sone);
      final SoneInserter soneInserter = new SoneInserter(this, eventBus, freenetInterface, sone);
      soneInserters.put(sone, soneInserter);
      sone.setStatus(SoneStatus.idle);
      loadSone(sone);
      soneInserter.start();
      return sone;
    }
  }
View Full Code Here

  public Sone createSone(OwnIdentity ownIdentity) {
    if (!webOfTrustUpdater.addContextWait(ownIdentity, "Sone")) {
      logger.log(Level.SEVERE, String.format("Could not add “Sone” context to own identity: %s", ownIdentity));
      return null;
    }
    Sone sone = addLocalSone(ownIdentity);
    sone.getOptions().addBooleanOption("AutoFollow", new DefaultOption<Boolean>(false));
    sone.getOptions().addBooleanOption("EnableSoneInsertNotifications", new DefaultOption<Boolean>(false));
    sone.getOptions().addBooleanOption("ShowNotification/NewSones", new DefaultOption<Boolean>(true));
    sone.getOptions().addBooleanOption("ShowNotification/NewPosts", new DefaultOption<Boolean>(true));
    sone.getOptions().addBooleanOption("ShowNotification/NewReplies", new DefaultOption<Boolean>(true));
    sone.getOptions().addEnumOption("ShowCustomAvatars", new DefaultOption<ShowCustomAvatars>(ShowCustomAvatars.NEVER));

    followSone(sone, "nwa8lHa271k2QvJ8aa0Ov7IHAV-DFOCFgmDt3X6BpCI");
    touchConfiguration();
    return sone;
  }
View Full Code Here

    if (identity == null) {
      logger.log(Level.WARNING, "Given Identity is null!");
      return null;
    }
    synchronized (sones) {
      final Sone sone = getRemoteSone(identity.getId(), true);
      if (sone.isLocal()) {
        return sone;
      }
      sone.setIdentity(identity);
      boolean newSone = sone.getRequestUri() == null;
      sone.setRequestUri(SoneUri.create(identity.getRequestUri()));
      sone.setLatestEdition(Numbers.safeParseLong(identity.getProperty("Sone.LatestEdition"), (long) 0));
      if (newSone) {
        synchronized (knownSones) {
          newSone = !knownSones.contains(sone.getId());
        }
        sone.setKnown(!newSone);
        if (newSone) {
          eventBus.post(new NewSoneFoundEvent(sone));
          for (Sone localSone : getLocalSones()) {
            if (localSone.getOptions().getBooleanOption("AutoFollow").get()) {
              followSone(localSone, sone.getId());
            }
          }
        }
      }
      soneDownloader.addSone(sone);
      soneDownloaders.execute(new Runnable() {

        @Override
        @SuppressWarnings("synthetic-access")
        public void run() {
          soneDownloader.fetchSone(sone, sone.getRequestUri());
        }

      });
      return sone;
    }
View Full Code Here

   *
   * @param reply
   *            The reply to delete
   */
  public void deleteReply(PostReply reply) {
    Sone sone = reply.getSone();
    if (!sone.isLocal()) {
      logger.log(Level.FINE, String.format("Tried to delete non-local reply: %s", reply));
      return;
    }
    database.removePostReply(reply);
    markReplyKnown(reply);
    sone.removeReply(reply);
    touchConfiguration();
  }
View Full Code Here

    soneDownloaders.execute(new Runnable() {

      @Override
      @SuppressWarnings("synthetic-access")
      public void run() {
        Sone sone = getRemoteSone(identity.getId(), false);
        if (sone.isLocal()) {
          return;
        }
        sone.setIdentity(identity);
        sone.setLatestEdition(Numbers.safeParseLong(identity.getProperty("Sone.LatestEdition"), sone.getLatestEdition()));
        soneDownloader.addSone(sone);
        soneDownloader.fetchSone(sone);
      }
    });
  }
View Full Code Here

   * {@inheritDoc}
   */
  @Override
  protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
    super.processTemplate(request, templateContext);
    Sone currentSone = getCurrentSone(request.getToadletContext());
    Profile profile = currentSone.getProfile();

    /* get parameters from request. */
    String fieldId = request.getHttpRequest().getParam("field");
    Field field = profile.getFieldById(fieldId);
    if (field == null) {
      throw new RedirectException("invalid.html");
    }

    /* process the POST request. */
    if (request.getMethod() == Method.POST) {
      if (request.getHttpRequest().getPartAsStringFailsafe("cancel", 4).equals("true")) {
        throw new RedirectException("editProfile.html#profile-fields");
      }
      fieldId = request.getHttpRequest().getPartAsStringFailsafe("field", 36);
      field = profile.getFieldById(fieldId);
      if (field == null) {
        throw new RedirectException("invalid.html");
      }
      String name = request.getHttpRequest().getPartAsStringFailsafe("name", 256);
      Field existingField = profile.getFieldByName(name);
      if ((existingField == null) || (existingField.equals(field))) {
        field.setName(name);
        currentSone.setProfile(profile);
        throw new RedirectException("editProfile.html#profile-fields");
      }
      templateContext.set("duplicateFieldName", true);
    }

View Full Code Here

  public Object get(TemplateContext templateContext, Object object, String member) {
    PostReply reply = (PostReply) object;
    if ("likes".equals(member)) {
      return core.getLikes(reply);
    } else if (member.equals("liked")) {
      Sone currentSone = (Sone) templateContext.get("currentSone");
      return (currentSone != null) && (currentSone.isLikedReplyId(reply.getId()));
    } else if (member.equals("new")) {
      return !reply.isKnown();
    } else if (member.equals("loaded")) {
      return reply.getSone() != null;
    }
View Full Code Here

    super.processTemplate(request, templateContext);
    if (request.getMethod() == Method.POST) {
      String type = request.getHttpRequest().getPartAsStringFailsafe("type", 16);
      String id = request.getHttpRequest().getPartAsStringFailsafe(type, 36);
      String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
      Sone currentSone = getCurrentSone(request.getToadletContext());
      if ("post".equals(type)) {
        currentSone.addLikedPostId(id);
      } else if ("reply".equals(type)) {
        currentSone.addLikedReplyId(id);
      }
      throw new RedirectException(returnPage);
    }
  }
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.