/**
   * reply to an individual comment that came from a notification - this differs from
   * submitReplyToComment() in that it enables responding to a reply to a comment this user made on
   * someone else's blog
   */
  static void submitReplyToCommentNote(
      final Note note, final String replyText, final CommentActionListener actionListener) {
    if (note == null || TextUtils.isEmpty(replyText)) {
      if (actionListener != null) actionListener.onActionResult(false);
      return;
    }

    RestRequest.Listener listener =
        new RestRequest.Listener() {
          @Override
          public void onResponse(JSONObject jsonObject) {
            if (actionListener != null) actionListener.onActionResult(true);
          }
        };
    RestRequest.ErrorListener errorListener =
        new RestRequest.ErrorListener() {
          @Override
          public void onErrorResponse(VolleyError volleyError) {
            if (volleyError != null) AppLog.e(T.COMMENTS, volleyError.getMessage(), volleyError);
            if (actionListener != null) actionListener.onActionResult(false);
          }
        };

    Note.Reply reply = note.buildReply(replyText);
    WordPress.getRestClientUtils().replyToComment(reply, listener, errorListener);
  }
  /*
   * add a comment for the passed post
   */
  public static void addComment(
      final int accountId,
      final String postID,
      final String commentText,
      final CommentActionListener actionListener) {
    final Blog blog = WordPress.getBlog(accountId);
    if (blog == null || TextUtils.isEmpty(commentText)) {
      if (actionListener != null) actionListener.onActionResult(false);
      return;
    }

    final Handler handler = new Handler();

    new Thread() {
      @Override
      public void run() {
        XMLRPCClientInterface client =
            XMLRPCFactory.instantiate(blog.getUri(), blog.getHttpuser(), blog.getHttppassword());

        Map<String, Object> commentHash = new HashMap<String, Object>();
        commentHash.put("content", commentText);
        commentHash.put("author", "");
        commentHash.put("author_url", "");
        commentHash.put("author_email", "");

        Object[] params = {
          blog.getRemoteBlogId(), blog.getUsername(), blog.getPassword(), postID, commentHash
        };

        int newCommentID;
        try {
          newCommentID = (Integer) client.call("wp.newComment", params);
        } catch (XMLRPCException e) {
          AppLog.e(T.COMMENTS, "Error while sending new comment", e);
          newCommentID = -1;
        } catch (IOException e) {
          AppLog.e(T.COMMENTS, "Error while sending new comment", e);
          newCommentID = -1;
        } catch (XmlPullParserException e) {
          AppLog.e(T.COMMENTS, "Error while sending new comment", e);
          newCommentID = -1;
        }

        final boolean succeeded = (newCommentID >= 0);

        if (actionListener != null) {
          handler.post(
              new Runnable() {
                @Override
                public void run() {
                  actionListener.onActionResult(succeeded);
                }
              });
        }
      }
    }.start();
  }
Exemplo n.º 3
0
  private boolean doVote(CommentEntry entry, Vote vote) {
    if (commentActionListener == null) return false;

    boolean performVote = commentActionListener.onCommentVoteClicked(entry.comment, vote);
    if (performVote) {
      entry.vote = vote;
    }

    return performVote;
  }
  /** delete (trash) a single comment */
  private static void deleteComment(
      final int accountId, final Comment comment, final CommentActionListener actionListener) {
    final Blog blog = WordPress.getBlog(accountId);
    if (blog == null || comment == null) {
      if (actionListener != null) actionListener.onActionResult(false);
      return;
    }

    final Handler handler = new Handler();

    new Thread() {
      @Override
      public void run() {
        XMLRPCClientInterface client =
            XMLRPCFactory.instantiate(blog.getUri(), blog.getHttpuser(), blog.getHttppassword());

        Object[] params = {
          blog.getRemoteBlogId(), blog.getUsername(), blog.getPassword(), comment.commentID
        };

        Object result;
        try {
          result = client.call("wp.deleteComment", params);
        } catch (final XMLRPCException e) {
          AppLog.e(T.COMMENTS, "Error while deleting comment", e);
          result = null;
        } catch (IOException e) {
          AppLog.e(T.COMMENTS, "Error while deleting comment", e);
          result = null;
        } catch (XmlPullParserException e) {
          AppLog.e(T.COMMENTS, "Error while deleting comment", e);
          result = null;
        }

        final boolean success = (result != null && Boolean.parseBoolean(result.toString()));
        if (success) CommentTable.deleteComment(accountId, comment.commentID);

        if (actionListener != null) {
          handler.post(
              new Runnable() {
                @Override
                public void run() {
                  actionListener.onActionResult(success);
                }
              });
        }
      }
    }.start();
  }
Exemplo n.º 5
0
 private void doAnswer(Comment comment) {
   if (commentActionListener != null) commentActionListener.onAnswerClicked(comment);
 }
Exemplo n.º 6
0
 private void doOnAuthorClicked(Comment comment) {
   if (commentActionListener != null) commentActionListener.onCommentAuthorClicked(comment);
 }
Exemplo n.º 7
0
  @Override
  public void onBindViewHolder(CommentView view, int position) {
    CommentEntry entry = comments.get(position);
    Comment comment = entry.comment;

    view.setCommentDepth(entry.depth);
    view.senderInfo.setSenderName(comment.getName(), comment.getMark());
    view.senderInfo.setOnSenderClickedListener(v -> doOnAuthorClicked(comment));

    AndroidUtility.linkify(view.comment, comment.getContent());

    // show the points
    if (equalsIgnoreCase(comment.getName(), selfName)
        || comment.getCreated().isBefore(scoreVisibleThreshold)) {

      view.senderInfo.setPoints(getCommentScore(entry));
    } else {
      view.senderInfo.setPointsUnknown();
    }

    // and the date of the post
    view.senderInfo.setDate(comment.getCreated());

    // enable or disable the badge
    boolean badge = op.transform(op -> op.equalsIgnoreCase(comment.getName())).or(false);
    view.senderInfo.setBadgeOpVisible(badge);

    // and register a vote handler
    view.vote.setVote(entry.vote, true);
    view.vote.setOnVoteListener(
        v -> {
          boolean changed = doVote(entry, v);
          notifyItemChanged(position);
          return changed;
        });

    // set alpha for the sub views. sadly, setting alpha on view.itemView is not working
    view.comment.setAlpha(entry.vote == Vote.DOWN ? 0.5f : 1f);
    view.senderInfo.setAlpha(entry.vote == Vote.DOWN ? 0.5f : 1f);

    view.senderInfo.setOnAnswerClickedListener(v -> doAnswer(comment));

    Context context = view.itemView.getContext();
    view.itemView.setBackgroundColor(
        ContextCompat.getColor(
            context,
            comment.getId() == selectedCommentId
                ? R.color.selected_comment_background
                : R.color.feed_background));

    if (view.kFav != null) {
      if (showFavCommentButton) {
        boolean isFavorite = favedComments.contains(comment.getId());

        view.kFav.setTextColor(
            isFavorite
                ? ContextCompat.getColor(context, R.color.primary)
                : ContextCompat.getColor(context, R.color.grey_700));

        view.kFav.setVisibility(View.VISIBLE);
        view.kFav.setOnClickListener(
            v -> {
              commentActionListener.onCommentMarkAsFavoriteClicked(comment, !isFavorite);
            });
      } else {
        view.kFav.setVisibility(View.GONE);
      }
    }
  }
  /** change the status of a single comment */
  static void moderateComment(
      final int accountId,
      final Comment comment,
      final CommentStatus newStatus,
      final CommentActionListener actionListener) {

    // deletion is handled separately
    if (newStatus != null && newStatus.equals(CommentStatus.TRASH)) {
      deleteComment(accountId, comment, actionListener);
      return;
    }

    final Blog blog = WordPress.getBlog(accountId);

    if (blog == null
        || comment == null
        || newStatus == null
        || newStatus == CommentStatus.UNKNOWN) {
      if (actionListener != null) actionListener.onActionResult(false);
      return;
    }

    final Handler handler = new Handler();

    new Thread() {
      @Override
      public void run() {
        XMLRPCClientInterface client =
            XMLRPCFactory.instantiate(blog.getUri(), blog.getHttpuser(), blog.getHttppassword());

        Map<String, String> postHash = new HashMap<String, String>();
        postHash.put("status", CommentStatus.toString(newStatus));
        postHash.put("content", comment.getCommentText());
        postHash.put("author", comment.getAuthorName());
        postHash.put("author_url", comment.getAuthorUrl());
        postHash.put("author_email", comment.getAuthorEmail());

        Object[] params = {
          blog.getRemoteBlogId(),
          blog.getUsername(),
          blog.getPassword(),
          Long.toString(comment.commentID),
          postHash
        };

        Object result;
        try {
          result = client.call("wp.editComment", params);
        } catch (XMLRPCException e) {
          AppLog.e(T.COMMENTS, "Error while editing comment", e);
          result = null;
        } catch (IOException e) {
          AppLog.e(T.COMMENTS, "Error while editing comment", e);
          result = null;
        } catch (XmlPullParserException e) {
          AppLog.e(T.COMMENTS, "Error while editing comment", e);
          result = null;
        }

        final boolean success = (result != null && Boolean.parseBoolean(result.toString()));
        if (success)
          CommentTable.updateCommentStatus(
              blog.getLocalTableBlogId(), comment.commentID, CommentStatus.toString(newStatus));

        if (actionListener != null) {
          handler.post(
              new Runnable() {
                @Override
                public void run() {
                  actionListener.onActionResult(success);
                }
              });
        }
      }
    }.start();
  }
  /** reply to an individual comment */
  static void submitReplyToComment(
      final int accountId,
      final Comment comment,
      final String replyText,
      final CommentActionListener actionListener) {

    final Blog blog = WordPress.getBlog(accountId);
    if (blog == null || comment == null || TextUtils.isEmpty(replyText)) {
      if (actionListener != null) actionListener.onActionResult(false);
      return;
    }

    final Handler handler = new Handler();

    new Thread() {
      @Override
      public void run() {
        XMLRPCClientInterface client =
            XMLRPCFactory.instantiate(blog.getUri(), blog.getHttpuser(), blog.getHttppassword());

        Map<String, Object> replyHash = new HashMap<String, Object>();
        replyHash.put("comment_parent", Long.toString(comment.commentID));
        replyHash.put("content", replyText);
        replyHash.put("author", "");
        replyHash.put("author_url", "");
        replyHash.put("author_email", "");

        Object[] params = {
          blog.getRemoteBlogId(),
          blog.getUsername(),
          blog.getPassword(),
          Long.toString(comment.postID),
          replyHash
        };

        long newCommentID;
        try {
          Object newCommentIDObject = client.call("wp.newComment", params);
          if (newCommentIDObject instanceof Integer) {
            newCommentID = ((Integer) newCommentIDObject).longValue();
          } else if (newCommentIDObject instanceof Long) {
            newCommentID = (Long) newCommentIDObject;
          } else {
            AppLog.e(T.COMMENTS, "wp.newComment returned the wrong data type");
            newCommentID = -1;
          }
        } catch (XMLRPCException e) {
          AppLog.e(T.COMMENTS, "Error while sending the new comment", e);
          newCommentID = -1;
        } catch (IOException e) {
          AppLog.e(T.COMMENTS, "Error while sending the new comment", e);
          newCommentID = -1;
        } catch (XmlPullParserException e) {
          AppLog.e(T.COMMENTS, "Error while sending the new comment", e);
          newCommentID = -1;
        }

        final boolean succeeded = (newCommentID >= 0);

        if (actionListener != null) {
          handler.post(
              new Runnable() {
                @Override
                public void run() {
                  actionListener.onActionResult(succeeded);
                }
              });
        }
      }
    }.start();
  }