/** delete multiple comments */
  private static void deleteComments(
      final int accountId,
      final CommentList comments,
      final OnCommentsModeratedListener actionListener) {

    final Blog blog = WordPress.getBlog(accountId);

    if (blog == null || comments == null || comments.size() == 0) {
      if (actionListener != null) actionListener.onCommentsModerated(new CommentList());
      return;
    }

    final CommentList deletedComments = new CommentList();
    final int localBlogId = blog.getLocalTableBlogId();
    final int remoteBlogId = blog.getRemoteBlogId();

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

        for (Comment comment : comments) {
          Object[] params = {
            remoteBlogId, blog.getUsername(), blog.getPassword(), comment.commentID
          };

          Object result;
          try {
            result = client.call("wp.deleteComment", params);
            boolean success = (result != null && Boolean.parseBoolean(result.toString()));
            if (success) deletedComments.add(comment);
          } catch (XMLRPCException e) {
            AppLog.e(T.COMMENTS, "Error while deleting comment", e);
          } catch (IOException e) {
            AppLog.e(T.COMMENTS, "Error while deleting comment", e);
          } catch (XmlPullParserException e) {
            AppLog.e(T.COMMENTS, "Error while deleting comment", e);
          }
        }

        // remove successfully deleted comments from SQLite
        CommentTable.deleteComments(localBlogId, deletedComments);

        if (actionListener != null) {
          handler.post(
              new Runnable() {
                @Override
                public void run() {
                  actionListener.onCommentsModerated(deletedComments);
                }
              });
        }
      }
    }.start();
  }
  /**
   * change the status of multiple comments TODO: investigate using system.multiCall to perform a
   * single call to moderate the list
   */
  static void moderateComments(
      final int accountId,
      final CommentList comments,
      final CommentStatus newStatus,
      final OnCommentsModeratedListener actionListener) {

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

    final Blog blog = WordPress.getBlog(accountId);

    if (blog == null
        || comments == null
        || comments.size() == 0
        || newStatus == null
        || newStatus == CommentStatus.UNKNOWN) {
      if (actionListener != null) actionListener.onCommentsModerated(new CommentList());
      return;
    }

    final CommentList moderatedComments = new CommentList();
    final String newStatusStr = CommentStatus.toString(newStatus);
    final int localBlogId = blog.getLocalTableBlogId();
    final int remoteBlogId = blog.getRemoteBlogId();

    final Handler handler = new Handler();
    new Thread() {
      @Override
      public void run() {
        XMLRPCClientInterface client =
            XMLRPCFactory.instantiate(blog.getUri(), blog.getHttpuser(), blog.getHttppassword());
        for (Comment comment : comments) {
          Map<String, String> postHash = new HashMap<String, String>();
          postHash.put("status", newStatusStr);
          postHash.put("content", comment.getCommentText());
          postHash.put("author", comment.getAuthorName());
          postHash.put("author_url", comment.getAuthorUrl());
          postHash.put("author_email", comment.getAuthorEmail());

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

          Object result;
          try {
            result = client.call("wp.editComment", params);
            boolean success = (result != null && Boolean.parseBoolean(result.toString()));
            if (success) {
              comment.setStatus(newStatusStr);
              moderatedComments.add(comment);
            }
          } catch (XMLRPCException e) {
            AppLog.e(T.COMMENTS, "Error while editing comment", e);
          } catch (IOException e) {
            AppLog.e(T.COMMENTS, "Error while editing comment", e);
          } catch (XmlPullParserException e) {
            AppLog.e(T.COMMENTS, "Error while editing comment", e);
          }
        }

        // update status in SQLite of successfully moderated comments
        CommentTable.updateCommentsStatus(localBlogId, moderatedComments, newStatusStr);

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