Files
peko-ios/YuMi/Modules/YMRoom/View/MessageContainerView/Model/XPMessageDataSourceManager.h

95 lines
2.1 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.

//
// XPMessageDataSourceManager.h
// YUMI
//
// Created by YUMI on 2024/12/19.
//
#import <Foundation/Foundation.h>
#import "XPMessageItem.h"
NS_ASSUME_NONNULL_BEGIN
/**
* 消息数据源管理器
* 统一管理所有消息数据,提供线程安全的数据操作
* 支持 DiffableDataSource 的单一数据源架构
*/
@interface XPMessageDataSourceManager : NSObject
/// 所有消息(只读)
@property (nonatomic, strong, readonly) NSArray<XPMessageItem *> *allMessages;
/// 聊天消息(只读)
@property (nonatomic, strong, readonly) NSArray<XPMessageItem *> *chatMessages;
/// 礼物消息(只读)
@property (nonatomic, strong, readonly) NSArray<XPMessageItem *> *giftMessages;
/// 最大消息数量,超过此数量会自动清理旧消息
@property (nonatomic, assign) NSInteger maxMessages;
/**
* 初始化方法
* @param maxMessages 最大消息数量默认1000
*/
- (instancetype)initWithMaxMessages:(NSInteger)maxMessages;
/**
* 添加消息
* @param message 要添加的消息项
*/
- (void)addMessage:(XPMessageItem *)message;
/**
* 同步添加单条消息(调用返回即已写入),适合随后立刻刷新快照的场景
*/
- (void)addMessageSync:(XPMessageItem *)message;
/**
* 批量添加消息
* @param messages 要添加的消息数组
*/
- (void)addMessages:(NSArray<XPMessageItem *> *)messages;
/**
* 移除消息
* @param message 要移除的消息项
*/
- (void)removeMessage:(XPMessageItem *)message;
/**
* 清空所有消息
*/
- (void)clearAllMessages;
/**
* 根据显示类型获取消息
* @param displayType 显示类型1=所有, 2=聊天, 3=礼物
* @return 对应类型的消息数组
*/
- (NSArray<XPMessageItem *> *)messagesForDisplayType:(NSInteger)displayType;
/**
* 手动清理旧消息
* 当消息数量超过 maxMessages 时自动调用
*/
- (void)cleanupOldMessages;
/**
* 获取当前消息总数
* @return 消息总数
*/
- (NSInteger)totalMessageCount;
/**
* 获取指定类型的消息数量
* @param displayType 显示类型
* @return 消息数量
*/
- (NSInteger)messageCountForDisplayType:(NSInteger)displayType;
@end
NS_ASSUME_NONNULL_END