Repository navigation
Expand file tree
/
Copy pathcomment_render.go
More file actions
59 lines (52 loc) · 1.45 KB
/
Copy pathcomment_render.go
File metadata and controls
59 lines (52 loc) · 1.45 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package render
import (
"bbs-go/model"
"bbs-go/model/constants"
"bbs-go/pkg/markdown"
"bbs-go/services"
"html"
)
func BuildComments(comments []model.Comment) []model.CommentResponse {
var ret []model.CommentResponse
for _, comment := range comments {
ret = append(ret, *BuildComment(comment))
}
return ret
}
func BuildComment(comment model.Comment) *model.CommentResponse {
return _buildComment(&comment, true)
}
func _buildComment(comment *model.Comment, buildQuote bool) *model.CommentResponse {
if comment == nil {
return nil
}
ret := &model.CommentResponse{
CommentId: comment.Id,
User: BuildUserInfoDefaultIfNull(comment.UserId),
EntityType: comment.EntityType,
EntityId: comment.EntityId,
QuoteId: comment.QuoteId,
Status: comment.Status,
CreateTime: comment.CreateTime,
}
if comment.Status == constants.StatusOk {
if comment.ContentType == constants.ContentTypeMarkdown {
content := markdown.ToHTML(comment.Content)
ret.Content = handleHtmlContent(content)
} else if comment.ContentType == constants.ContentTypeHtml {
ret.Content = handleHtmlContent(comment.Content)
} else {
ret.Content = html.EscapeString(comment.Content)
}
ret.ImageList = buildImageList(comment.ImageList)
} else {
ret.Content = "内容已删除"
}
if buildQuote && comment.QuoteId > 0 {
quote := _buildComment(services.CommentService.Get(comment.QuoteId), false)
if quote != nil {
ret.Quote = quote
}
}
return ret
}