This commit is contained in:
2026-01-27 21:32:52 +08:00
parent db869552e4
commit 3fd7d2af2e
6 changed files with 433 additions and 7 deletions

View File

@@ -8,6 +8,7 @@
#import <Foundation/Foundation.h>
#import "KBPersonaPageModel.h"
#import "KBChatHistoryPageModel.h"
#import "KBCommentModel.h"
NS_ASSUME_NONNULL_BEGIN
@@ -105,6 +106,42 @@ typedef void (^AiVMSpeechTranscribeCompletion)(KBAiSpeechTranscribeResponse *_Nu
pageSize:(NSInteger)pageSize
completion:(void(^)(KBChatHistoryPageModel * _Nullable pageModel, NSError * _Nullable error))completion;
#pragma mark - 评论相关接口
/// 发表评论
/// @param companionId AI 陪聊角色 ID
/// @param content 评论内容
/// @param parentId 父评论 ID一级评论传 NULL
/// @param rootId 根评论 ID用于标识一级评论
/// @param completion 完成回调(返回 code 200 表示成功)
- (void)addCommentWithCompanionId:(NSInteger)companionId
content:(NSString *)content
parentId:(nullable NSNumber *)parentId
rootId:(NSInteger)rootId
completion:(void(^)(NSInteger code, NSError * _Nullable error))completion;
/// 分页查询评论列表
/// @param companionId AI 陪聊角色 ID
/// @param pageNum 页码(从 1 开始,默认 1
/// @param pageSize 每页大小(默认 20
/// @param completion 完成回调(返回评论分页模型)
- (void)fetchCommentsWithCompanionId:(NSInteger)companionId
pageNum:(NSInteger)pageNum
pageSize:(NSInteger)pageSize
completion:(void(^)(KBCommentPageModel * _Nullable pageModel, NSError * _Nullable error))completion;
/// 点赞/取消点赞评论
/// @param commentId 评论 ID
/// @param completion 完成回调(返回点赞响应模型)
- (void)likeCommentWithCommentId:(NSInteger)commentId
completion:(void(^)(KBCommentLikeResponse * _Nullable response, NSError * _Nullable error))completion;
/// 点赞/取消点赞 AI 角色
/// @param companionId AI 角色 ID
/// @param completion 完成回调(返回点赞响应模型)
- (void)likeCompanionWithCompanionId:(NSInteger)companionId
completion:(void(^)(KBCommentLikeResponse * _Nullable response, NSError * _Nullable error))completion;
@end
NS_ASSUME_NONNULL_END

View File

@@ -8,6 +8,7 @@
#import "AiVM.h"
#import "KBAPI.h"
#import "KBNetworkManager.h"
#import "KBCommentModel.h"
#import <MJExtension/MJExtension.h>
@implementation KBAiSyncData
@@ -426,4 +427,176 @@ autoShowBusinessError:NO
}];
}
#pragma mark -
- (void)addCommentWithCompanionId:(NSInteger)companionId
content:(NSString *)content
parentId:(nullable NSNumber *)parentId
rootId:(NSInteger)rootId
completion:(void (^)(NSInteger, NSError * _Nullable))completion {
if (content.length == 0) {
NSError *error = [NSError errorWithDomain:@"AiVM"
code:-1
userInfo:@{NSLocalizedDescriptionKey: @"评论内容不能为空"}];
if (completion) {
completion(-1, error);
}
return;
}
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"companionId"] = @(companionId);
params[@"content"] = content;
params[@"rootId"] = @(rootId);
if (parentId) {
params[@"parentId"] = parentId;
}
NSLog(@"[AiVM] /ai-companion/comment/add request: %@", params);
[[KBNetworkManager shared]
POST:@"/ai-companion/comment/add"
jsonBody:[params copy]
headers:nil
autoShowBusinessError:NO
completion:^(NSDictionary *_Nullable json,
NSURLResponse *_Nullable response,
NSError *_Nullable error) {
if (error) {
NSLog(@"[AiVM] /ai-companion/comment/add failed: %@", error.localizedDescription ?: @"");
if (completion) {
completion(-1, error);
}
return;
}
NSLog(@"[AiVM] /ai-companion/comment/add response: %@", json);
NSInteger code = [json[@"code"] integerValue];
if (completion) {
completion(code, nil);
}
}];
}
- (void)fetchCommentsWithCompanionId:(NSInteger)companionId
pageNum:(NSInteger)pageNum
pageSize:(NSInteger)pageSize
completion:(void (^)(KBCommentPageModel * _Nullable, NSError * _Nullable))completion {
NSDictionary *params = @{
@"companionId": @(companionId),
@"pageNum": @(pageNum > 0 ? pageNum : 1),
@"pageSize": @(pageSize > 0 ? pageSize : 20)
};
NSLog(@"[AiVM] /ai-companion/comment/page request: %@", params);
[[KBNetworkManager shared]
POST:@"/ai-companion/comment/page"
jsonBody:params
headers:nil
autoShowBusinessError:NO
completion:^(NSDictionary *_Nullable json,
NSURLResponse *_Nullable response,
NSError *_Nullable error) {
if (error) {
NSLog(@"[AiVM] /ai-companion/comment/page failed: %@", error.localizedDescription ?: @"");
if (completion) {
completion(nil, error);
}
return;
}
NSLog(@"[AiVM] /ai-companion/comment/page response: %@", json);
NSInteger code = [json[@"code"] integerValue];
if (code != 0) {
NSString *message = json[@"message"] ?: @"请求失败";
NSError *bizError = [NSError errorWithDomain:@"AiVM"
code:code
userInfo:@{NSLocalizedDescriptionKey: message}];
if (completion) {
completion(nil, bizError);
}
return;
}
id dataObj = json[@"data"];
if ([dataObj isKindOfClass:[NSDictionary class]]) {
KBCommentPageModel *pageModel = [KBCommentPageModel mj_objectWithKeyValues:dataObj];
if (completion) {
completion(pageModel, nil);
}
} else {
NSError *parseError = [NSError errorWithDomain:@"AiVM"
code:-1
userInfo:@{NSLocalizedDescriptionKey: @"数据格式错误"}];
if (completion) {
completion(nil, parseError);
}
}
}];
}
- (void)likeCommentWithCommentId:(NSInteger)commentId
completion:(void (^)(KBCommentLikeResponse * _Nullable, NSError * _Nullable))completion {
NSDictionary *params = @{
@"commentId": @(commentId)
};
NSLog(@"[AiVM] /ai-companion/comment/like request: %@", params);
[[KBNetworkManager shared]
POST:@"/ai-companion/comment/like"
jsonBody:params
headers:nil
autoShowBusinessError:NO
completion:^(NSDictionary *_Nullable json,
NSURLResponse *_Nullable response,
NSError *_Nullable error) {
if (error) {
NSLog(@"[AiVM] /ai-companion/comment/like failed: %@", error.localizedDescription ?: @"");
if (completion) {
completion(nil, error);
}
return;
}
NSLog(@"[AiVM] /ai-companion/comment/like response: %@", json);
KBCommentLikeResponse *likeResponse = [KBCommentLikeResponse mj_objectWithKeyValues:json];
if (completion) {
completion(likeResponse, nil);
}
}];
}
- (void)likeCompanionWithCompanionId:(NSInteger)companionId
completion:(void (^)(KBCommentLikeResponse * _Nullable, NSError * _Nullable))completion {
NSDictionary *params = @{
@"companionId": @(companionId)
};
NSLog(@"[AiVM] /ai-companion/like request: %@", params);
[[KBNetworkManager shared]
POST:@"/ai-companion/like"
jsonBody:params
headers:nil
autoShowBusinessError:NO
completion:^(NSDictionary *_Nullable json,
NSURLResponse *_Nullable response,
NSError *_Nullable error) {
if (error) {
NSLog(@"[AiVM] /ai-companion/like failed: %@", error.localizedDescription ?: @"");
if (completion) {
completion(nil, error);
}
return;
}
NSLog(@"[AiVM] /ai-companion/like response: %@", json);
KBCommentLikeResponse *likeResponse = [KBCommentLikeResponse mj_objectWithKeyValues:json];
if (completion) {
completion(likeResponse, nil);
}
}];
}
@end