fix(chat): isolate pending flows and cancel stale requests
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
import type { UnlockPrivateMessageInput } from "@/data/repositories/interfaces";
|
||||
import type {
|
||||
ChatRequestOptions,
|
||||
ChatSendOptions,
|
||||
UnlockPrivateMessageInput,
|
||||
} from "@/data/repositories/interfaces";
|
||||
import {
|
||||
ChatHistoryResponse,
|
||||
ChatSendResponse,
|
||||
@@ -17,7 +21,7 @@ export class ChatRemoteDataSource {
|
||||
async sendMessage(
|
||||
characterId: string,
|
||||
message: string,
|
||||
options?: { image?: string; useWebSocket?: boolean },
|
||||
options?: ChatSendOptions,
|
||||
): Promise<Result<ChatSendResponse>> {
|
||||
return Result.wrap(async () => {
|
||||
const request = SendMessageRequestSchema.parse({
|
||||
@@ -26,7 +30,7 @@ export class ChatRemoteDataSource {
|
||||
image: options?.image ?? "",
|
||||
useWebSocket: options?.useWebSocket ?? false,
|
||||
});
|
||||
return await this.api.sendMessage(request);
|
||||
return await this.api.sendMessage(request, options);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -34,23 +38,34 @@ export class ChatRemoteDataSource {
|
||||
characterId: string,
|
||||
limit = 50,
|
||||
offset = 0,
|
||||
options?: ChatRequestOptions,
|
||||
): Promise<Result<ChatHistoryResponse>> {
|
||||
return Result.wrap(() => this.api.getHistory(characterId, limit, offset));
|
||||
return Result.wrap(() =>
|
||||
this.api.getHistory(characterId, limit, offset, options),
|
||||
);
|
||||
}
|
||||
|
||||
async unlockPrivateMessage(
|
||||
input: UnlockPrivateMessageInput,
|
||||
options?: ChatRequestOptions,
|
||||
): Promise<Result<UnlockPrivateResponse>> {
|
||||
return Result.wrap(() =>
|
||||
this.api.unlockPrivateMessage(UnlockPrivateRequestSchema.parse(input)),
|
||||
this.api.unlockPrivateMessage(
|
||||
UnlockPrivateRequestSchema.parse(input),
|
||||
options,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
async unlockHistory(
|
||||
characterId: string,
|
||||
options?: ChatRequestOptions,
|
||||
): Promise<Result<UnlockHistoryResponse>> {
|
||||
return Result.wrap(() =>
|
||||
this.api.unlockHistory(UnlockHistoryRequestSchema.parse({ characterId })),
|
||||
this.api.unlockHistory(
|
||||
UnlockHistoryRequestSchema.parse({ characterId }),
|
||||
options,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user