better display
This commit is contained in:
parent
cb21e0f6a2
commit
fee62fed53
|
|
@ -68,6 +68,18 @@ type Comment struct {
|
||||||
type APIUser struct {
|
type APIUser struct {
|
||||||
Login string `json:"login"`
|
Login string `json:"login"`
|
||||||
FullName string `json:"full_name"`
|
FullName string `json:"full_name"`
|
||||||
|
Email string `json:"email"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// DisplayName returns the best human-readable name for the user.
|
||||||
|
func (u APIUser) DisplayName() string {
|
||||||
|
if u.FullName != "" {
|
||||||
|
return u.FullName
|
||||||
|
}
|
||||||
|
if u.Email != "" {
|
||||||
|
return u.Email
|
||||||
|
}
|
||||||
|
return u.Login
|
||||||
}
|
}
|
||||||
|
|
||||||
type CommentView struct {
|
type CommentView struct {
|
||||||
|
|
@ -111,12 +123,16 @@ func StripCommentFooter(body string) (string, string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// BuildCommentViews transforms Forgejo comments into view models,
|
// BuildCommentViews transforms Forgejo comments into view models,
|
||||||
// identifying customer vs team comments based on the bot login.
|
// identifying customer vs team comments. A comment is considered a
|
||||||
|
// customer comment if it has a recognizable footer (primary check) OR
|
||||||
|
// if its author matches the bot login (fallback).
|
||||||
func BuildCommentViews(comments []Comment, botLogin string) []CommentView {
|
func BuildCommentViews(comments []Comment, botLogin string) []CommentView {
|
||||||
var views []CommentView
|
var views []CommentView
|
||||||
for _, c := range comments {
|
for _, c := range comments {
|
||||||
if c.User.Login == botLogin {
|
body, email := StripCommentFooter(c.Body)
|
||||||
body, email := StripCommentFooter(c.Body)
|
isCustomer := email != "" || (botLogin != "" && c.User.Login == botLogin)
|
||||||
|
|
||||||
|
if isCustomer {
|
||||||
authorName := email
|
authorName := email
|
||||||
if authorName == "" {
|
if authorName == "" {
|
||||||
authorName = "Customer"
|
authorName = "Customer"
|
||||||
|
|
@ -128,13 +144,9 @@ func BuildCommentViews(comments []Comment, botLogin string) []CommentView {
|
||||||
CreatedAt: c.CreatedAt,
|
CreatedAt: c.CreatedAt,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
name := c.User.FullName
|
|
||||||
if name == "" {
|
|
||||||
name = c.User.Login
|
|
||||||
}
|
|
||||||
views = append(views, CommentView{
|
views = append(views, CommentView{
|
||||||
Body: c.Body,
|
Body: c.Body,
|
||||||
AuthorName: name,
|
AuthorName: c.User.DisplayName(),
|
||||||
IsTeam: true,
|
IsTeam: true,
|
||||||
CreatedAt: c.CreatedAt,
|
CreatedAt: c.CreatedAt,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue