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

@@ -11,8 +11,10 @@
#import "KBChatHistoryPageModel.h"
#import "AiVM.h"
#import "KBImagePositionButton.h"
#import "KBAICommentView.h"
#import <Masonry/Masonry.h>
#import <SDWebImage/SDWebImage.h>
#import <LSTPopView/LSTPopView.h>
@interface KBPersonaChatCell () <KBChatTableViewDelegate>
@@ -55,6 +57,9 @@
///
@property (nonatomic, strong) KBImagePositionButton *likeButton;
///
@property (nonatomic, weak) LSTPopView *popView;
@end
@implementation KBPersonaChatCell
@@ -159,7 +164,6 @@
self.currentPage = 1;
self.hasMoreHistory = YES;
self.messages = [NSMutableArray array];
self.aiVM = [[AiVM alloc] init];
// UI
[self.backgroundImageView sd_setImageWithURL:[NSURL URLWithString:persona.coverImageUrl]
@@ -452,17 +456,106 @@
#pragma mark - Button Actions
- (void)commentButtonTapped:(KBImagePositionButton *)sender {
sender.selected = !sender.selected;
NSLog(@"[KBPersonaChatCell] 评论按钮点击,选中状态:%d", sender.selected);
NSLog(@"[KBPersonaChatCell] 评论按钮点击");
// TODO:
//
[self showComment];
}
- (void)likeButtonTapped:(KBImagePositionButton *)sender {
sender.selected = !sender.selected;
NSLog(@"[KBPersonaChatCell] 喜欢按钮点击,选中状态:%d", sender.selected);
NSLog(@"[KBPersonaChatCell] 喜欢按钮点击");
// TODO:
NSInteger personaId = self.persona.personaId;
//
sender.enabled = NO;
__weak typeof(self) weakSelf = self;
[self.aiVM likeCompanionWithCompanionId:personaId completion:^(KBCommentLikeResponse * _Nullable response, NSError * _Nullable error) {
__strong typeof(weakSelf) strongSelf = weakSelf;
if (!strongSelf) {
return;
}
dispatch_async(dispatch_get_main_queue(), ^{
//
sender.enabled = YES;
if (error) {
NSLog(@"[KBPersonaChatCell] 点赞失败:%@", error.localizedDescription);
// TODO:
return;
}
if (response && response.code == 0) {
//
NSInteger currentLikeCount = [strongSelf.persona.likeCount integerValue];
// response.data: true false
if (response.data) {
// 1
currentLikeCount += 1;
sender.selected = YES;
NSLog(@"[KBPersonaChatCell] 点赞成功,新喜欢数:%ld", (long)currentLikeCount);
} else {
// 10
currentLikeCount = MAX(0, currentLikeCount - 1);
sender.selected = NO;
NSLog(@"[KBPersonaChatCell] 取消点赞成功,新喜欢数:%ld", (long)currentLikeCount);
}
//
strongSelf.persona.likeCount = [NSString stringWithFormat:@"%ld", (long)currentLikeCount];
strongSelf.persona.liked = sender.selected;
//
[sender setTitle:strongSelf.persona.likeCount forState:UIControlStateNormal];
} else {
NSLog(@"[KBPersonaChatCell] 点赞失败:%@", response.message ?: @"未知错误");
// TODO:
}
});
}];
}
#pragma mark - Comment View
- (void)showComment {
//
if (self.popView) {
[self.popView dismiss];
}
CGFloat customViewHeight = KB_SCREEN_HEIGHT * 0.8;
KBAICommentView *customView = [[KBAICommentView alloc]
initWithFrame:CGRectMake(0, 0, KB_SCREEN_WIDTH, customViewHeight)];
// ID
// customView.companionId = self.persona.personaId;
LSTPopView *popView = [LSTPopView initWithCustomView:customView
parentView:nil
popStyle:LSTPopStyleSmoothFromBottom
dismissStyle:LSTDismissStyleSmoothToBottom];
self.popView = popView;
popView.priority = 1000;
popView.isAvoidKeyboard = NO;
popView.hemStyle = LSTHemStyleBottom;
popView.dragStyle = LSTDragStyleY_Positive;
popView.dragDistance = customViewHeight * 0.5;
popView.sweepStyle = LSTSweepStyleY_Positive;
popView.swipeVelocity = 1600;
popView.sweepDismissStyle = LSTSweepDismissStyleSmooth;
[popView pop];
}
- (AiVM *)aiVM{
if (!_aiVM) {
_aiVM = [[AiVM alloc] init];
}
return _aiVM;
}
@end