2026-01-23 21:51:37 +08:00
|
|
|
|
//
|
|
|
|
|
|
// KBChatTableView.h
|
|
|
|
|
|
// keyBoard
|
|
|
|
|
|
//
|
|
|
|
|
|
// Created by Kiro on 2026/1/23.
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#import <UIKit/UIKit.h>
|
2026-01-26 20:36:51 +08:00
|
|
|
|
#import "KBAiChatMessage.h"
|
2026-01-23 21:51:37 +08:00
|
|
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
2026-01-26 20:36:51 +08:00
|
|
|
|
@class KBChatTableView;
|
|
|
|
|
|
|
|
|
|
|
|
@protocol KBChatTableViewDelegate <NSObject>
|
|
|
|
|
|
@optional
|
|
|
|
|
|
- (void)chatTableViewDidScroll:(KBChatTableView *)chatView
|
|
|
|
|
|
scrollView:(UIScrollView *)scrollView;
|
|
|
|
|
|
- (void)chatTableViewDidTriggerLoadMore:(KBChatTableView *)chatView;
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
2026-01-23 21:51:37 +08:00
|
|
|
|
/// 聊天列表视图(支持用户消息、AI 消息、时间戳、语音播放)
|
|
|
|
|
|
@interface KBChatTableView : UIView
|
|
|
|
|
|
|
2026-01-26 20:36:51 +08:00
|
|
|
|
@property (nonatomic, weak) id<KBChatTableViewDelegate> delegate;
|
|
|
|
|
|
|
2026-01-31 22:40:50 +08:00
|
|
|
|
/// 是否倒置列表(倒置后:视觉底部为 row=0,历史消息向上追加)
|
|
|
|
|
|
@property (nonatomic, assign) BOOL inverted;
|
|
|
|
|
|
|
2026-01-23 21:51:37 +08:00
|
|
|
|
/// 添加用户消息
|
|
|
|
|
|
- (void)addUserMessage:(NSString *)text;
|
|
|
|
|
|
|
2026-01-29 14:42:49 +08:00
|
|
|
|
/// 添加加载中的用户消息
|
|
|
|
|
|
- (void)addLoadingUserMessage;
|
|
|
|
|
|
|
|
|
|
|
|
/// 更新最后一条用户消息
|
|
|
|
|
|
- (void)updateLastUserMessage:(NSString *)text;
|
|
|
|
|
|
|
2026-01-23 21:51:37 +08:00
|
|
|
|
/// 添加 AI 消息(带语音)
|
|
|
|
|
|
- (void)addAssistantMessage:(NSString *)text
|
|
|
|
|
|
audioDuration:(NSTimeInterval)duration
|
|
|
|
|
|
audioData:(nullable NSData *)audioData;
|
|
|
|
|
|
|
|
|
|
|
|
/// 添加 AI 消息(带 audioId,异步加载音频)
|
|
|
|
|
|
- (void)addAssistantMessage:(NSString *)text
|
|
|
|
|
|
audioId:(nullable NSString *)audioId;
|
|
|
|
|
|
|
|
|
|
|
|
/// 更新最后一条 AI 消息(用于打字机效果)
|
|
|
|
|
|
- (void)updateLastAssistantMessage:(NSString *)text;
|
|
|
|
|
|
|
|
|
|
|
|
/// 标记最后一条 AI 消息完成
|
|
|
|
|
|
- (void)markLastAssistantMessageComplete;
|
|
|
|
|
|
|
2026-01-29 14:42:49 +08:00
|
|
|
|
/// 标记最后一条用户消息结束加载
|
|
|
|
|
|
- (void)markLastUserMessageLoadingComplete;
|
|
|
|
|
|
|
2026-01-23 21:51:37 +08:00
|
|
|
|
/// 清空所有消息
|
|
|
|
|
|
- (void)clearMessages;
|
|
|
|
|
|
|
2026-01-29 20:56:24 +08:00
|
|
|
|
/// 移除 loading AI 消息
|
|
|
|
|
|
- (void)removeLoadingAssistantMessage;
|
|
|
|
|
|
|
2026-01-23 21:51:37 +08:00
|
|
|
|
/// 滚动到底部
|
|
|
|
|
|
- (void)scrollToBottom;
|
|
|
|
|
|
|
|
|
|
|
|
/// 停止正在播放的音频
|
|
|
|
|
|
- (void)stopPlayingAudio;
|
|
|
|
|
|
|
2026-01-26 20:36:51 +08:00
|
|
|
|
/// 结束加载更多
|
|
|
|
|
|
- (void)endLoadMoreWithHasMoreData:(BOOL)hasMoreData;
|
|
|
|
|
|
|
|
|
|
|
|
/// 重置无更多数据状态
|
|
|
|
|
|
- (void)resetNoMoreData;
|
|
|
|
|
|
|
2026-01-27 16:28:17 +08:00
|
|
|
|
/// 更新底部内容 inset(用于避开输入栏/键盘)
|
|
|
|
|
|
- (void)updateContentBottomInset:(CGFloat)bottomInset;
|
|
|
|
|
|
|
2026-01-26 20:36:51 +08:00
|
|
|
|
/// 添加自定义消息(可用于历史消息或打字机)
|
|
|
|
|
|
- (void)addMessage:(KBAiChatMessage *)message
|
|
|
|
|
|
autoScroll:(BOOL)autoScroll;
|
|
|
|
|
|
|
|
|
|
|
|
/// 用指定消息重载(用于历史消息分页)
|
|
|
|
|
|
- (void)reloadWithMessages:(NSArray<KBAiChatMessage *> *)messages
|
|
|
|
|
|
keepOffset:(BOOL)keepOffset
|
|
|
|
|
|
scrollToBottom:(BOOL)scrollToBottom;
|
|
|
|
|
|
|
2026-01-30 21:24:17 +08:00
|
|
|
|
- (void)prependHistoryMessages:(NSArray<KBAiChatMessage *> *)messages
|
|
|
|
|
|
openingMessage:(nullable KBAiChatMessage *)openingMessage;
|
|
|
|
|
|
|
2026-01-31 22:40:50 +08:00
|
|
|
|
/// 追加历史消息(倒置模式使用:把更老的消息插入到 openingMessage 之前/末尾)
|
|
|
|
|
|
- (void)appendHistoryMessages:(NSArray<KBAiChatMessage *> *)messages
|
|
|
|
|
|
openingMessage:(nullable KBAiChatMessage *)openingMessage;
|
|
|
|
|
|
|
2026-01-31 23:17:58 +08:00
|
|
|
|
/// 刷新指定消息(按对象指针匹配)
|
|
|
|
|
|
- (void)reloadMessage:(KBAiChatMessage *)message;
|
|
|
|
|
|
|
2026-02-02 13:26:38 +08:00
|
|
|
|
/// 设置介绍视图文案(使用 tableFooterView 展示;nil/空串表示不显示)
|
|
|
|
|
|
- (void)updateIntroFooterText:(nullable NSString *)text;
|
|
|
|
|
|
|
2026-01-23 21:51:37 +08:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|