1 import type { HttpHeaders } from '../Types/HttpHeaders'
2 import type { GetCommentThreadResponse } from '../Types/GetCommentThreadResponse'
3 import type { ApiResult } from '@proton/docs-shared'
4 import { DocsApiPrivateRouteBuilder } from '../Routes/DocsApiPrivateRouteBuilder'
5 import { DocsApiPublicRouteBuilder } from '../Routes/DocsApiPublicRouteBuilder'
6 import { isPublicNodeMeta, type NodeMeta, type PublicNodeMeta } from '@proton/drive-store/lib/interface'
7 import type { RouteExecutor } from '../RouteExecutor'
9 export class ApiGetThread {
11 private readonly executor: RouteExecutor,
12 private publicContextHeaders: HttpHeaders | undefined,
16 nodeMeta: NodeMeta | PublicNodeMeta
18 }): Promise<ApiResult<GetCommentThreadResponse>> {
19 if (isPublicNodeMeta(dto.nodeMeta)) {
20 return this.executePublic(dto, dto.nodeMeta)
22 return this.executePrivate(dto, dto.nodeMeta)
26 private async executePrivate(
31 ): Promise<ApiResult<GetCommentThreadResponse>> {
32 const route = new DocsApiPrivateRouteBuilder({
33 volumeId: nodeMeta.volumeId,
34 linkId: nodeMeta.linkId,
36 threadId: dto.threadId,
39 return this.executor.execute(route)
42 private async executePublic(
46 nodeMeta: PublicNodeMeta,
47 ): Promise<ApiResult<GetCommentThreadResponse>> {
48 if (!this.publicContextHeaders) {
49 throw new Error('Public context headers not set')
52 const route = new DocsApiPublicRouteBuilder({
53 token: nodeMeta.token,
54 linkId: nodeMeta.linkId,
55 headers: this.publicContextHeaders,
57 threadId: dto.threadId,
60 return this.executor.execute(route)