51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
"use client";
|
|
|
|
import {
|
|
ChatHistoryResponse,
|
|
ChatSendResponse,
|
|
SendMessageRequest,
|
|
UnlockHistoryResponse,
|
|
UnlockPrivateRequest,
|
|
UnlockPrivateResponse,
|
|
} from "@/data/dto/chat";
|
|
import type { ChatApi } from "@/data/services/api";
|
|
import type { UnlockPrivateMessageInput } from "@/data/repositories/interfaces";
|
|
import { Result } from "@/utils";
|
|
|
|
export class ChatRemoteDataSource {
|
|
constructor(private readonly api: ChatApi) {}
|
|
|
|
async sendMessage(
|
|
message: string,
|
|
options?: { image?: string; useWebSocket?: boolean },
|
|
): Promise<Result<ChatSendResponse>> {
|
|
return Result.wrap(async () => {
|
|
const request = SendMessageRequest.from({
|
|
message,
|
|
image: options?.image ?? "",
|
|
useWebSocket: options?.useWebSocket ?? false,
|
|
});
|
|
return await this.api.sendMessage(request);
|
|
});
|
|
}
|
|
|
|
async getHistory(
|
|
limit = 50,
|
|
offset = 0,
|
|
): Promise<Result<ChatHistoryResponse>> {
|
|
return Result.wrap(() => this.api.getHistory(limit, offset));
|
|
}
|
|
|
|
async unlockPrivateMessage(
|
|
input: UnlockPrivateMessageInput,
|
|
): Promise<Result<UnlockPrivateResponse>> {
|
|
return Result.wrap(() =>
|
|
this.api.unlockPrivateMessage(UnlockPrivateRequest.from(input)),
|
|
);
|
|
}
|
|
|
|
async unlockHistory(): Promise<Result<UnlockHistoryResponse>> {
|
|
return Result.wrap(() => this.api.unlockHistory());
|
|
}
|
|
}
|