修改举报和UI

This commit is contained in:
2026-02-02 17:07:46 +08:00
parent 0ac9030f80
commit 2b75ad90fb
5 changed files with 228 additions and 11 deletions

View File

@@ -808,4 +808,100 @@ autoShowBusinessError:NO
}];
}
#pragma mark -
- (void)reportCompanionWithCompanionId:(NSInteger)companionId
reportTypes:(NSArray<NSNumber *> *)reportTypes
reportDesc:(nullable NSString *)reportDesc
chatContext:(nullable NSString *)chatContext
evidenceImageUrl:(nullable NSString *)evidenceImageUrl
completion:(void (^)(BOOL, NSError * _Nullable))completion {
if (companionId <= 0) {
NSError *error = [NSError errorWithDomain:@"AiVM"
code:-1
userInfo:@{NSLocalizedDescriptionKey : @"invalid companionId"}];
if (completion) {
completion(NO, error);
}
return;
}
NSMutableArray<NSNumber *> *typeList = [NSMutableArray array];
for (id item in reportTypes) {
if ([item isKindOfClass:[NSNumber class]]) {
[typeList addObject:(NSNumber *)item];
} else if ([item isKindOfClass:[NSString class]]) {
NSInteger value = [(NSString *)item integerValue];
[typeList addObject:@(value)];
}
}
if (typeList.count == 0) {
NSError *error = [NSError errorWithDomain:@"AiVM"
code:-1
userInfo:@{NSLocalizedDescriptionKey : @"reportTypes is empty"}];
if (completion) {
completion(NO, error);
}
return;
}
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"companionId"] = @(companionId);
params[@"reportTypes"] = [typeList copy];
if (reportDesc.length > 0) {
params[@"reportDesc"] = reportDesc;
}
if (chatContext.length > 0) {
params[@"chatContext"] = chatContext;
}
if (evidenceImageUrl.length > 0) {
params[@"evidenceImageUrl"] = evidenceImageUrl;
}
NSLog(@"[AiVM] /ai-companion/report request: %@", params);
[[KBNetworkManager shared]
POST:@"/ai-companion/report"
jsonBody:[params copy]
headers:nil
autoShowBusinessError:NO
completion:^(NSDictionary *_Nullable json,
NSURLResponse *_Nullable response,
NSError *_Nullable error) {
if (error) {
NSLog(@"[AiVM] /ai-companion/report failed: %@", error.localizedDescription ?: @"");
if (completion) {
completion(NO, error);
}
return;
}
NSLog(@"[AiVM] /ai-companion/report response: %@", json);
if (![json isKindOfClass:[NSDictionary class]]) {
NSError *parseError = [NSError errorWithDomain:@"AiVM"
code:-1
userInfo:@{NSLocalizedDescriptionKey : @"数据格式错误"}];
if (completion) {
completion(NO, parseError);
}
return;
}
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(NO, bizError);
}
return;
}
if (completion) {
completion(YES, nil);
}
}];
}
@end