1
This commit is contained in:
@@ -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 {
|
||||
// 取消点赞成功,喜欢数减1(但不能小于0)
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user