Remove client-side isLoggedIn value
[ProtonMail-WebClient.git] / packages / docs-core / lib / Models / Comments.ts
blob47a0b53f6408d2d2c0e381e01166ba6b22d6adc7
1 import type { CommentInterface, CommentPayload, CommentType } from '@proton/docs-shared'
2 import { ServerTime } from '@proton/docs-shared'
4 export class Comment implements CommentInterface {
5   constructor(
6     public id: string,
7     public createTime: ServerTime,
8     public modifyTime: ServerTime,
9     public content: string,
10     public parentCommentID: string | null,
11     public author: string,
12     public comments: CommentInterface[],
13     public isPlaceholder: boolean,
14     public type: CommentType,
15   ) {}
17   public asPayload(): CommentPayload {
18     return {
19       id: this.id,
20       createTime: this.createTime.serverTimestamp,
21       modifyTime: this.modifyTime.serverTimestamp,
22       content: this.content,
23       parentCommentID: this.parentCommentID,
24       author: this.author,
25       comments: this.comments.map((comment) => comment.asPayload()),
26       isPlaceholder: this.isPlaceholder,
27       type: this.type,
28     }
29   }
31   static fromPayload(payload: CommentPayload): CommentInterface {
32     return new Comment(
33       payload.id,
34       new ServerTime(payload.createTime),
35       new ServerTime(payload.modifyTime),
36       payload.content,
37       payload.parentCommentID,
38       payload.author,
39       payload.comments.map((comment) => Comment.fromPayload(comment)),
40       payload.isPlaceholder,
41       payload.type,
42     )
43   }