-
Notifications
You must be signed in to change notification settings - Fork 3
/
convert_thread.go
45 lines (39 loc) · 994 Bytes
/
convert_thread.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package gqlmodel
import (
"github.com/reearth/reearth-cms/server/pkg/thread"
"github.com/samber/lo"
)
func ToThread(th *thread.Thread) *Thread {
if th == nil {
return nil
}
return &Thread{
ID: IDFrom(th.ID()),
WorkspaceID: IDFrom(th.Workspace()),
Comments: lo.Map(th.Comments(), func(c *thread.Comment, _ int) *Comment { return ToComment(c, th) }),
}
}
func ToComment(c *thread.Comment, th *thread.Thread) *Comment {
if c == nil {
return nil
}
var authorID ID
var authorType OperatorType
if c.Author().User() != nil {
authorID = IDFrom(*c.Author().User())
authorType = OperatorTypeUser
}
if c.Author().Integration() != nil {
authorID = IDFrom(*c.Author().Integration())
authorType = OperatorTypeIntegration
}
return &Comment{
ID: IDFrom(c.ID()),
ThreadID: IDFrom(th.ID()),
WorkspaceID: IDFrom(th.Workspace()),
AuthorID: authorID,
AuthorType: authorType,
Content: c.Content(),
CreatedAt: c.CreatedAt(),
}
}