Live video on the AT Protocol

use uniseg for chat message length limit

ElshadHu e2951aa2 7b5977ed

+10 -3
+10 -3
pkg/model/chat_message.go
··· 5 5 "errors" 6 6 "fmt" 7 7 "hash/fnv" 8 + "strings" 8 9 "time" 9 10 10 11 "github.com/bluesky-social/indigo/api/bsky" 11 12 lexutil "github.com/bluesky-social/indigo/lex/util" 13 + "github.com/rivo/uniseg" 12 14 "gorm.io/gorm" 13 15 "stream.place/streamplace/pkg/streamplace" 14 16 ) ··· 43 45 } 44 46 // Truncate message text if it is a ChatMessage 45 47 if msg, ok := rec.(*streamplace.ChatMessage); ok { 46 - runes := []rune(msg.Text) 47 - if len(runes) > 300 { 48 - msg.Text = string(runes[:300]) 48 + graphemeCount := uniseg.GraphemeClusterCount(msg.Text) 49 + if graphemeCount > 300 { 50 + gr := uniseg.NewGraphemes(msg.Text) 51 + var result strings.Builder 52 + for count := 0; count < 300 && gr.Next(); count++ { 53 + result.WriteString(gr.Str()) 54 + } 55 + msg.Text = result.String() 49 56 } 50 57 } 51 58