Files
keyboard/keyBoard/Class/AiTalk/V/Chat/KBChatTableView.h
2026-02-02 17:41:23 +08:00

109 lines
3.2 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// KBChatTableView.h
// keyBoard
//
// Created by Kiro on 2026/1/23.
//
#import <UIKit/UIKit.h>
#import "KBAiChatMessage.h"
NS_ASSUME_NONNULL_BEGIN
@class KBChatTableView;
@protocol KBChatTableViewDelegate <NSObject>
@optional
- (void)chatTableViewDidScroll:(KBChatTableView *)chatView
scrollView:(UIScrollView *)scrollView;
- (void)chatTableViewDidTriggerLoadMore:(KBChatTableView *)chatView;
@end
/// 聊天列表视图支持用户消息、AI 消息、时间戳、语音播放)
@interface KBChatTableView : UIView
@property (nonatomic, weak) id<KBChatTableViewDelegate> delegate;
/// 是否倒置列表(倒置后:视觉底部为 row=0历史消息向上追加
@property (nonatomic, assign) BOOL inverted;
/// 添加用户消息
- (void)addUserMessage:(NSString *)text;
/// 添加加载中的用户消息
- (void)addLoadingUserMessage;
/// 更新最后一条用户消息
- (void)updateLastUserMessage:(NSString *)text;
/// 添加 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;
/// 标记最后一条用户消息结束加载
- (void)markLastUserMessageLoadingComplete;
/// 清空所有消息
- (void)clearMessages;
/// 移除 loading AI 消息
- (void)removeLoadingAssistantMessage;
/// 移除 loading 用户消息
- (void)removeLoadingUserMessage;
/// 滚动到底部
- (void)scrollToBottom;
/// 停止正在播放的音频
- (void)stopPlayingAudio;
/// 结束加载更多
- (void)endLoadMoreWithHasMoreData:(BOOL)hasMoreData;
/// 重置无更多数据状态
- (void)resetNoMoreData;
/// 更新底部内容 inset用于避开输入栏/键盘)
- (void)updateContentBottomInset:(CGFloat)bottomInset;
/// 添加自定义消息(可用于历史消息或打字机)
- (void)addMessage:(KBAiChatMessage *)message
autoScroll:(BOOL)autoScroll;
/// 用指定消息重载(用于历史消息分页)
- (void)reloadWithMessages:(NSArray<KBAiChatMessage *> *)messages
keepOffset:(BOOL)keepOffset
scrollToBottom:(BOOL)scrollToBottom;
- (void)prependHistoryMessages:(NSArray<KBAiChatMessage *> *)messages
openingMessage:(nullable KBAiChatMessage *)openingMessage;
/// 追加历史消息(倒置模式使用:把更老的消息插入到 openingMessage 之前/末尾)
- (void)appendHistoryMessages:(NSArray<KBAiChatMessage *> *)messages
openingMessage:(nullable KBAiChatMessage *)openingMessage;
/// 刷新指定消息(按对象指针匹配)
- (void)reloadMessage:(KBAiChatMessage *)message;
/// 设置介绍视图文案(使用 tableFooterView 展示nil/空串表示不显示)
- (void)updateIntroFooterText:(nullable NSString *)text;
/// 播放远程音频(用于开场白 prologueAudio
- (void)playRemoteAudioWithURLString:(NSString *)urlString;
@end
NS_ASSUME_NONNULL_END