fix(chat): apply unlocked voice audio url
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import type { ChatLockDetailData } from "@/data/schemas/chat";
|
||||
import { ChatMessage } from "@/data/dto/chat";
|
||||
import type { UnlockedPrivateMessageLocalPatch } from "@/data/repositories/interfaces";
|
||||
import { LocalChatStorage, LocalMessage } from "@/data/storage/chat";
|
||||
import { Result } from "@/utils";
|
||||
|
||||
@@ -10,7 +10,7 @@ export class ChatLocalMessageStore {
|
||||
|
||||
async markMessageUnlocked(
|
||||
messageId: string,
|
||||
lockDetail?: ChatLockDetailData,
|
||||
patch: UnlockedPrivateMessageLocalPatch = {},
|
||||
): Promise<Result<void>> {
|
||||
return Result.wrap(async () => {
|
||||
const localResult = await this.getMessages();
|
||||
@@ -24,7 +24,9 @@ export class ChatLocalMessageStore {
|
||||
changed = true;
|
||||
return ChatMessage.from({
|
||||
...message.toJson(),
|
||||
lockDetail: lockDetail ?? {
|
||||
content: normalizeUnlockedContent(patch.content, message.content),
|
||||
audioUrl: normalizeUnlockedAudioUrl(patch.audioUrl, message.audioUrl),
|
||||
lockDetail: patch.lockDetail ?? {
|
||||
...message.lockDetail,
|
||||
locked: false,
|
||||
showContent: true,
|
||||
@@ -105,6 +107,22 @@ export class ChatLocalMessageStore {
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeUnlockedContent(
|
||||
nextContent: string | undefined,
|
||||
currentContent: string,
|
||||
): string {
|
||||
if (nextContent == null || nextContent.length === 0) return currentContent;
|
||||
return nextContent;
|
||||
}
|
||||
|
||||
function normalizeUnlockedAudioUrl(
|
||||
nextAudioUrl: string | null | undefined,
|
||||
currentAudioUrl: string | null,
|
||||
): string | null {
|
||||
if (nextAudioUrl == null || nextAudioUrl.length === 0) return currentAudioUrl;
|
||||
return nextAudioUrl;
|
||||
}
|
||||
|
||||
function shouldMarkMessageUnlocked(
|
||||
message: ChatMessage,
|
||||
messageId: string,
|
||||
|
||||
@@ -7,7 +7,6 @@ import type {
|
||||
UnlockHistoryResponse,
|
||||
UnlockPrivateResponse,
|
||||
} from "@/data/dto/chat";
|
||||
import type { ChatLockDetailData } from "@/data/schemas/chat";
|
||||
import { chatApi } from "@/data/services/api";
|
||||
import {
|
||||
LocalChatMediaStorage,
|
||||
@@ -18,6 +17,7 @@ import type {
|
||||
CacheRemoteChatMediaInput,
|
||||
ChatMediaLookupInput,
|
||||
IChatRepository,
|
||||
UnlockedPrivateMessageLocalPatch,
|
||||
} from "@/data/repositories/interfaces";
|
||||
import type { Result } from "@/utils";
|
||||
|
||||
@@ -66,11 +66,11 @@ export class ChatRepository implements IChatRepository {
|
||||
/** 把本地缓存中的单条锁定消息标记为已解锁。 */
|
||||
async markPrivateMessageUnlockedInLocal(
|
||||
messageId: string,
|
||||
lockDetail?: ChatLockDetailData,
|
||||
patch?: UnlockedPrivateMessageLocalPatch,
|
||||
): Promise<Result<void>> {
|
||||
return this.localMessages.markMessageUnlocked(
|
||||
messageId,
|
||||
lockDetail,
|
||||
patch,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,12 @@ export interface CacheRemoteChatMediaInput extends ChatMediaLookupInput {
|
||||
remoteUrl: string;
|
||||
}
|
||||
|
||||
export interface UnlockedPrivateMessageLocalPatch {
|
||||
lockDetail?: ChatLockDetailData;
|
||||
audioUrl?: string | null;
|
||||
content?: string;
|
||||
}
|
||||
|
||||
export interface IChatRepository {
|
||||
/** 发送一条消息。 */
|
||||
sendMessage(
|
||||
@@ -51,7 +57,7 @@ export interface IChatRepository {
|
||||
/** 把本地缓存中的单条锁定消息标记为已解锁。 */
|
||||
markPrivateMessageUnlockedInLocal(
|
||||
messageId: string,
|
||||
lockDetail?: ChatLockDetailData,
|
||||
patch?: UnlockedPrivateMessageLocalPatch,
|
||||
): Promise<Result<void>>;
|
||||
|
||||
/** 把一条消息写入本地存储。 */
|
||||
|
||||
Reference in New Issue
Block a user