处理了评论新增评论,在聊天里的评论数也一同改变
This commit is contained in:
@@ -22,7 +22,7 @@
|
|||||||
/// 聊天会话被重置的通知
|
/// 聊天会话被重置的通知
|
||||||
static NSString * const KBChatSessionDidResetNotification = @"KBChatSessionDidResetNotification";
|
static NSString * const KBChatSessionDidResetNotification = @"KBChatSessionDidResetNotification";
|
||||||
|
|
||||||
@interface KBPersonaChatCell () <KBChatTableViewDelegate, KBChatMessageActionPopViewDelegate>
|
@interface KBPersonaChatCell () <KBChatTableViewDelegate, KBChatMessageActionPopViewDelegate, KBAICommentViewDelegate>
|
||||||
|
|
||||||
/// 背景图
|
/// 背景图
|
||||||
@property (nonatomic, strong) UIImageView *backgroundImageView;
|
@property (nonatomic, strong) UIImageView *backgroundImageView;
|
||||||
@@ -1250,6 +1250,7 @@ static NSString * const KBChatSessionDidResetNotification = @"KBChatSessionDidRe
|
|||||||
CGFloat customViewHeight = KB_SCREEN_HEIGHT * 0.75;
|
CGFloat customViewHeight = KB_SCREEN_HEIGHT * 0.75;
|
||||||
KBAICommentView *customView = [[KBAICommentView alloc]
|
KBAICommentView *customView = [[KBAICommentView alloc]
|
||||||
initWithFrame:CGRectMake(0, 0, KB_SCREEN_WIDTH, customViewHeight)];
|
initWithFrame:CGRectMake(0, 0, KB_SCREEN_WIDTH, customViewHeight)];
|
||||||
|
customView.delegate = self;
|
||||||
|
|
||||||
NSString *commentCount = self.persona.commentCount;
|
NSString *commentCount = self.persona.commentCount;
|
||||||
NSInteger totalCommentCount = [commentCount integerValue];;
|
NSInteger totalCommentCount = [commentCount integerValue];;
|
||||||
@@ -1281,6 +1282,18 @@ static NSString * const KBChatSessionDidResetNotification = @"KBChatSessionDidRe
|
|||||||
[popView pop];
|
[popView pop];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark - KBAICommentViewDelegate
|
||||||
|
|
||||||
|
- (void)commentView:(KBAICommentView *)view didUpdateTotalCommentCount:(NSInteger)totalCommentCount {
|
||||||
|
// 容错:确保回调的人设与当前 cell 的人设一致
|
||||||
|
if (view.companionId <= 0 || view.companionId != self.persona.personaId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.persona.commentCount = [NSString stringWithFormat:@"%ld", (long)totalCommentCount];
|
||||||
|
[self.commentButton setTitle:self.persona.commentCount forState:UIControlStateNormal];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- (AiVM *)aiVM{
|
- (AiVM *)aiVM{
|
||||||
|
|||||||
@@ -105,6 +105,8 @@
|
|||||||
}
|
}
|
||||||
// 点击发送后清空输入
|
// 点击发送后清空输入
|
||||||
[self clearText];
|
[self clearText];
|
||||||
|
// 发送后收起键盘
|
||||||
|
[self.textField resignFirstResponder];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,19 @@
|
|||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
@class KBAICommentView;
|
||||||
|
|
||||||
|
@protocol KBAICommentViewDelegate <NSObject>
|
||||||
|
@optional
|
||||||
|
/// 评论总数变化回调(例如发送评论/回复成功后)
|
||||||
|
- (void)commentView:(KBAICommentView *)view didUpdateTotalCommentCount:(NSInteger)totalCommentCount;
|
||||||
|
@end
|
||||||
|
|
||||||
/// 抖音风格评论视图
|
/// 抖音风格评论视图
|
||||||
@interface KBAICommentView : UIView
|
@interface KBAICommentView : UIView
|
||||||
|
|
||||||
|
@property(nonatomic, weak, nullable) id<KBAICommentViewDelegate> delegate;
|
||||||
|
|
||||||
/// AI 陪聊角色 ID
|
/// AI 陪聊角色 ID
|
||||||
@property(nonatomic, assign) NSInteger companionId;
|
@property(nonatomic, assign) NSInteger companionId;
|
||||||
|
|
||||||
|
|||||||
@@ -940,6 +940,9 @@ static NSInteger const kRepliesLoadCount = 5;
|
|||||||
strongSelf.totalCommentCount += 1;
|
strongSelf.totalCommentCount += 1;
|
||||||
[strongSelf updateTitle];
|
[strongSelf updateTitle];
|
||||||
[strongSelf hideEmptyState];
|
[strongSelf hideEmptyState];
|
||||||
|
if ([strongSelf.delegate respondsToSelector:@selector(commentView:didUpdateTotalCommentCount:)]) {
|
||||||
|
[strongSelf.delegate commentView:strongSelf didUpdateTotalCommentCount:strongSelf.totalCommentCount];
|
||||||
|
}
|
||||||
|
|
||||||
[strongSelf.tableView beginUpdates];
|
[strongSelf.tableView beginUpdates];
|
||||||
[strongSelf.tableView
|
[strongSelf.tableView
|
||||||
@@ -1044,6 +1047,9 @@ static NSInteger const kRepliesLoadCount = 5;
|
|||||||
|
|
||||||
strongSelf.totalCommentCount += 1;
|
strongSelf.totalCommentCount += 1;
|
||||||
[strongSelf updateTitle];
|
[strongSelf updateTitle];
|
||||||
|
if ([strongSelf.delegate respondsToSelector:@selector(commentView:didUpdateTotalCommentCount:)]) {
|
||||||
|
[strongSelf.delegate commentView:strongSelf didUpdateTotalCommentCount:strongSelf.totalCommentCount];
|
||||||
|
}
|
||||||
|
|
||||||
// 若当前已完整展开,则直接插入新行;否则保持 displayedReplies 为前缀,避免破坏 loadMoreReplies 逻辑
|
// 若当前已完整展开,则直接插入新行;否则保持 displayedReplies 为前缀,避免破坏 loadMoreReplies 逻辑
|
||||||
if (wasFullyExpanded) {
|
if (wasFullyExpanded) {
|
||||||
|
|||||||
Reference in New Issue
Block a user