Live video on the AT Protocol

Merge pull request #841 from ElshadHu/fix-char-limit-chat

Fix char limit chat

authored by

Eli Mallon and committed by
GitHub
60db4587 5ea7ad20

+43 -2
+1
js/components/package.json
··· 42 42 "expo-sensors": "^15.0.7", 43 43 "expo-sqlite": "~15.2.12", 44 44 "expo-video": "^2.0.0", 45 + "graphemer": "^1.4.0", 45 46 "hls.js": "^1.5.17", 46 47 "i18next": "^25.4.2", 47 48 "i18next-browser-languagedetector": "^8.2.0",
+24 -2
js/components/src/components/chat/chat-box.tsx
··· 1 1 import Picker from "@emoji-mart/react"; 2 + import Graphemer from "graphemer"; 2 3 import { AtSignIcon, ExternalLink, X } from "lucide-react-native"; 3 4 import { env } from "process"; 4 5 import { useEffect, useMemo, useRef, useState } from "react"; 5 6 import { Platform, Pressable, TextInput } from "react-native"; 6 7 import { ChatMessageViewHydrated } from "streamplace"; 7 - import { Button, Loader, Text, useTheme, View } from "../../"; 8 + import { Button, Loader, Text, toast, useTheme, View } from "../../"; 8 9 import { handleSlashCommand } from "../../lib/slash-commands"; 9 10 import { registerTeleportCommand } from "../../lib/slash-commands/teleport"; 10 11 import { StreamNotifications } from "../../lib/stream-notifications"; ··· 41 42 ..."😀🥸😍😘😁🥸😆🥸😜🥸😂😅🥸🙂🤫😱🥸🤣😗😄🥸😎🤓😲😯😰🥸😥🥸😣🥸😞😓🥸😩😩🥸😤🥱", 42 43 ]; 43 44 45 + const graphemer = new Graphemer(); 46 + 44 47 export function ChatBox({ 45 48 isPopout, 46 49 chatBoxStyle, ··· 65 68 new Map(), 66 69 ); 67 70 const [filteredEmojis, setFilteredEmojis] = useState<any[]>([]); 71 + const isOverLimit = graphemer.countGraphemes(message) > 300; 68 72 69 73 let linfo = useLivestream(); 70 74 ··· 255 259 256 260 const submit = async () => { 257 261 if (!message.trim()) return; 262 + if (graphemer.countGraphemes(message) > 300) { 263 + toast.show( 264 + "Message too long", 265 + "Please limit your message to 300 characters.", 266 + { 267 + variant: "error", 268 + duration: 3, 269 + }, 270 + ); 271 + return; 272 + } 258 273 259 274 const messageText = message; 260 275 setMessage(""); ··· 457 472 } 458 473 } 459 474 }} 460 - style={[chatBoxStyle]} 475 + style={[ 476 + chatBoxStyle, 477 + isOverLimit && { 478 + borderColor: "#ef4444", 479 + borderWidth: 2, 480 + outline: "none", 481 + }, 482 + ]} 461 483 // "submit" won't blur on enter 462 484 submitBehavior="submit" 463 485 placeholder="Type a message..."
+15
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 ) ··· 41 43 if err != nil { 42 44 return nil, fmt.Errorf("error decoding feed post: %w", err) 43 45 } 46 + // Truncate message text if it is a ChatMessage 47 + if msg, ok := rec.(*streamplace.ChatMessage); ok { 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() 56 + } 57 + } 58 + 44 59 message := &streamplace.ChatDefs_MessageView{ 45 60 LexiconTypeID: "place.stream.chat.defs#messageView", 46 61 }
+3
pnpm-lock.yaml
··· 479 479 expo-video: 480 480 specifier: ^2.0.0 481 481 version: 2.2.1(expo@53.0.11(@babel/core@7.26.0)(@expo/metro-runtime@5.0.4(react-native@0.79.3(@babel/core@7.26.0)(@types/react@18.3.12)(bufferutil@4.0.8)(react@19.0.0)(utf-8-validate@5.0.10)))(bufferutil@4.0.8)(react-native-webview@13.15.0(react-native@0.79.3(@babel/core@7.26.0)(@types/react@18.3.12)(bufferutil@4.0.8)(react@19.0.0)(utf-8-validate@5.0.10))(react@19.0.0))(react-native@0.79.3(@babel/core@7.26.0)(@types/react@18.3.12)(bufferutil@4.0.8)(react@19.0.0)(utf-8-validate@5.0.10))(react@19.0.0)(utf-8-validate@5.0.10))(react-native@0.79.3(@babel/core@7.26.0)(@types/react@18.3.12)(bufferutil@4.0.8)(react@19.0.0)(utf-8-validate@5.0.10))(react@19.0.0) 482 + graphemer: 483 + specifier: ^1.4.0 484 + version: 1.4.0 482 485 hls.js: 483 486 specifier: ^1.5.17 484 487 version: 1.5.17