This commit is contained in:
2026-01-29 15:53:26 +08:00
parent 07a77149fc
commit 766c62f3c0
10 changed files with 890 additions and 18 deletions

View File

@@ -435,14 +435,14 @@ autoShowBusinessError:NO
- (void)addCommentWithCompanionId:(NSInteger)companionId
content:(NSString *)content
parentId:(nullable NSNumber *)parentId
rootId:(NSInteger)rootId
completion:(void (^)(NSInteger, NSError * _Nullable))completion {
rootId:(nullable NSNumber *)rootId
completion:(void (^)(KBCommentItem * _Nullable, NSInteger, NSError * _Nullable))completion {
if (content.length == 0) {
NSError *error = [NSError errorWithDomain:@"AiVM"
code:-1
userInfo:@{NSLocalizedDescriptionKey: @"评论内容不能为空"}];
code:-1
userInfo:@{NSLocalizedDescriptionKey: @"评论内容不能为空"}];
if (completion) {
completion(-1, error);
completion(nil, -1, error);
}
return;
}
@@ -450,7 +450,9 @@ autoShowBusinessError:NO
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"companionId"] = @(companionId);
params[@"content"] = content;
params[@"rootId"] = @(rootId);
if (rootId) {
params[@"rootId"] = rootId;
}
if (parentId) {
params[@"parentId"] = parentId;
}
@@ -467,17 +469,42 @@ autoShowBusinessError:NO
if (error) {
NSLog(@"[AiVM] /ai-companion/comment/add failed: %@", error.localizedDescription ?: @"");
if (completion) {
completion(-1, error);
completion(nil, -1, error);
}
return;
}
NSLog(@"[AiVM] /ai-companion/comment/add response: %@", json);
NSInteger code = [json[@"code"] integerValue];
if (completion) {
completion(code, nil);
if (code != 0) {
NSString *message = json[@"message"] ?: @"请求失败";
NSError *bizError = [NSError errorWithDomain:@"AiVM"
code:code
userInfo:@{NSLocalizedDescriptionKey: message}];
if (completion) {
completion(nil, code, bizError);
}
return;
}
}];
KBCommentItem *newItem = nil;
id dataObj = json[@"data"];
if ([dataObj isKindOfClass:[NSDictionary class]]) {
newItem = [KBCommentItem mj_objectWithKeyValues:(NSDictionary *)dataObj];
} else if ([dataObj isKindOfClass:[NSNumber class]]) {
KBCommentItem *tmp = [[KBCommentItem alloc] init];
tmp.commentId = [(NSNumber *)dataObj integerValue];
tmp.companionId = companionId;
tmp.content = content;
tmp.parentId = parentId;
tmp.rootId = rootId;
newItem = tmp;
}
if (completion) {
completion(newItem, code, nil);
}
}];
}
- (void)fetchCommentsWithCompanionId:(NSInteger)companionId