(message string)
| 6311 | } |
| 6312 | |
| 6313 | func chatTitleFromMessage(message string) string { |
| 6314 | const maxWords = 6 |
| 6315 | const maxRunes = 80 |
| 6316 | words := strings.Fields(message) |
| 6317 | if len(words) == 0 { |
| 6318 | return "New Chat" |
| 6319 | } |
| 6320 | truncated := false |
| 6321 | if len(words) > maxWords { |
| 6322 | words = words[:maxWords] |
| 6323 | truncated = true |
| 6324 | } |
| 6325 | title := strings.Join(words, " ") |
| 6326 | if truncated { |
| 6327 | title += "…" |
| 6328 | } |
| 6329 | return truncateRunes(title, maxRunes) |
| 6330 | } |
| 6331 | |
| 6332 | func truncateRunes(value string, maxLen int) string { |
| 6333 | if maxLen <= 0 { |
no test coverage detected