feat(media): implement caching for chat media and update components to use cached media
This commit is contained in:
@@ -19,6 +19,19 @@ import type {
|
||||
UnlockHistoryResponse,
|
||||
UnlockPrivateResponse,
|
||||
} from "@/data/dto/chat";
|
||||
import type {
|
||||
LocalChatMediaKind,
|
||||
LocalChatMediaRow,
|
||||
} from "@/data/storage/chat";
|
||||
|
||||
export interface ChatMediaLookupInput {
|
||||
messageId: string;
|
||||
kind: LocalChatMediaKind;
|
||||
}
|
||||
|
||||
export interface CacheRemoteChatMediaInput extends ChatMediaLookupInput {
|
||||
remoteUrl: string;
|
||||
}
|
||||
|
||||
export interface IChatRepository {
|
||||
/** 发送一条消息。 */
|
||||
@@ -58,4 +71,24 @@ export interface IChatRepository {
|
||||
|
||||
/** 获取本地消息数量。 */
|
||||
getLocalMessageCount(): Promise<Result<number>>;
|
||||
|
||||
/** 获取本地缓存的图片 / 音频 Blob。 */
|
||||
getCachedMedia(
|
||||
input: ChatMediaLookupInput,
|
||||
): Promise<Result<LocalChatMediaRow | null>>;
|
||||
|
||||
/** 下载并缓存远程图片 / 音频 Blob。 */
|
||||
cacheRemoteMedia(
|
||||
input: CacheRemoteChatMediaInput,
|
||||
): Promise<Result<LocalChatMediaRow>>;
|
||||
|
||||
/** 后台预缓存历史消息中的图片 / 音频。失败不影响聊天主流程。 */
|
||||
prefetchMediaForMessages(
|
||||
messages: readonly ChatMessage[],
|
||||
): Promise<Result<void>>;
|
||||
|
||||
/** 后台预缓存发送响应中的图片 / 音频。失败不影响聊天主流程。 */
|
||||
prefetchMediaForSendResponse(
|
||||
response: ChatSendResponse,
|
||||
): Promise<Result<void>>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user