目录

评论回复

场景介绍

华为云空间服务支持用户对云端文件的评论进行回复,并对回复进行查看、更新和删除操作。

开发前提

1、请确认您已完成开发准备。

2、在进行开发之前,您可以下载华为云空间客户端示例代码进行快速体验。

构造Drive对象

调用Drive.Builder.build接口构造Drive对象。
private Drive buildDrive() {  
    Drive service = new Drive.Builder(CredentialManager.getInstance().getCredential(), context).build();  
    return service;  
}

创建评论回复

调用Replies.Create接口创建评论回复:

/**
 * 创建文件评论回复
 *
 * @param fileId 文件id
 * @param commentId 文件评论id
 */
private Reply createReplies(String fileId, String commentId) {
    Reply replyResponse = null;
    Drive drive = buildDrive();
    try {
        Reply reply = new Reply();
        reply.setDescription("interface test reply");
        reply.setOperate("resolve");
        replyResponse = drive.replies().create(fileId, commentId, reply).setFields("*").execute();
    } catch (Exception ex) {
        Log.e(TAG, "createReplies error: " + ex.toString());
    }
    return replyResponse;
}

获取评论回复列表

调用Replies.List接口获取评论回复列表:

/**
 * 获取评论回复列表
 *
 * @param fileId 文件id
 * @param commentId 评论id
 */
private List<Reply> listReplies(String fileId, String commentId) {
    Drive drive = buildDrive();
    List<Reply> replyResponse = new ArrayList<>();
    String nextCursor = null;
    try {
        Drive.Replies.List listReq = drive.replies().list(fileId, commentId);
        do {
            if (nextCursor != null) {
                listReq.setCursor(nextCursor);
            }
            ReplyList replyList = listReq.setFields("*").execute();
            List<Reply> replies = replyList.getReplies();
            if (replies == null) {
                break;
            }
            replyResponse.addAll(replies);
            nextCursor = replyList.getNextCursor();
        } while (StringUtils.isNullOrEmpty(nextCursor));
    } catch (Exception ex) {
        Log.e(TAG, "listReplies error: " + ex.toString());
    }
    return replyResponse;
}

获取评论回复详情

调用Replies.Get接口获取评论回复详情:

/**
 * 获取评论回复详情
 *
 * @param fileId 文件id
 * @param commentId 评论id
 * @param replyId 回复id
 */
private Reply getReplies(String fileId, String commentId, String replyId) {
    Reply reply = null;
    Drive drive = buildDrive();
    try {
        reply = drive.replies().get(fileId, commentId, replyId).setFields("*").execute();
    } catch (Exception ex) {
        Log.e(TAG, "getReplies error: " + ex.toString());
    }
    return reply;
}

更新评论回复

调用Replies.Update接口更新评论回复:

/**    
 * 更新评论回复 
 *     
 * @param fileId 文件id    
 * @param commentId 评论id
 * @param replyId 回复id 
 */  
private void updateReplies(String fileId, String commentId, String replyId) {
    Drive drive = buildDrive();
    try {
        Reply reply = new Reply();
        reply.setDescription("interface test reply");
        reply.setOperate("reopen");
        drive.replies().update(fileId, commentId, replyId, reply).execute();
    } catch (Exception ex) {
        Log.e(TAG, "updateReplies error: " + ex.toString());
    }
}

删除评论回复

调用Replies.Delete接口删除评论回复:

/**    
 * 删除评论回复
 *     
 * @param fileId 文件id    
 * @param commentId 评论id
 * @param replyId 回复id 
 */  
private void deleteReplies(String fileId, String commentId, String replyId) {
    Drive drive = buildDrive();
    try {
        drive.replies().delete(fileId, commentId, replyId).execute();
    } catch (Exception ex) {
        Log.e(TAG, "deleteReplies error: " + ex.toString());
    }
}

回复评论接口是联网耗时接口,需要放在子线程中调用。