Files
ai-workflow/inbox/internal/app/dashboard/message_helpers.go
T

64 lines
1.3 KiB
Go

package dashboard
import (
"strings"
"inbox/internal/domain/message"
"inbox/internal/domain/topic"
)
func previewText(value string) string {
value = strings.TrimSpace(value)
if value == "" {
return ""
}
lines := strings.Split(value, "\n")
if len(lines) == 0 {
return value
}
return strings.TrimSpace(lines[0])
}
func splitRecipients(value string) []string {
parts := strings.Split(value, ",")
out := make([]string, 0, len(parts))
seen := make(map[string]struct{}, len(parts))
for _, part := range parts {
part = strings.TrimSpace(part)
if part == "" {
continue
}
if _, ok := seen[part]; ok {
continue
}
seen[part] = struct{}{}
out = append(out, part)
}
return out
}
func messageTargetsRole(expr, roleName string) bool {
for _, item := range splitRecipients(expr) {
if item == roleName {
return true
}
}
return false
}
func dashboardMessageItemFor(item message.Record, record topic.Record) dashboardMessageItem {
out := dashboardMessageItem{
MessageID: item.ID,
From: item.FromRoleName,
To: item.ToExpr,
Type: string(item.Type),
Topic: record.Slug,
Stage: item.Stage,
BodyMarkdown: item.BodyMarkdown,
}
if item.ReplyToMessageID != "" {
out.ReplyTo = item.ReplyToMessageID
}
return out
}