tangled
alpha
login
or
join now
stream.place
/
streamplace
74
fork
atom
Live video on the AT Protocol
74
fork
atom
overview
issues
1
pulls
pipelines
use uniseg for chat message length limit
ElshadHu
1 month ago
e2951aa2
7b5977ed
+10
-3
1 changed file
expand all
collapse all
unified
split
pkg
model
chat_message.go
+10
-3
pkg/model/chat_message.go
···
5
5
"errors"
6
6
"fmt"
7
7
"hash/fnv"
8
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
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
46
-
runes := []rune(msg.Text)
47
47
-
if len(runes) > 300 {
48
48
-
msg.Text = string(runes[:300])
48
48
+
graphemeCount := uniseg.GraphemeClusterCount(msg.Text)
49
49
+
if graphemeCount > 300 {
50
50
+
gr := uniseg.NewGraphemes(msg.Text)
51
51
+
var result strings.Builder
52
52
+
for count := 0; count < 300 && gr.Next(); count++ {
53
53
+
result.WriteString(gr.Str())
54
54
+
}
55
55
+
msg.Text = result.String()
49
56
}
50
57
}
51
58