feat: [closes #46] limit chat transcripts to 10,000 messages

This commit is contained in:
Jeremy Kahn 2022-10-25 20:17:58 -05:00
parent 6740d8da3d
commit bd6f1d5090
2 changed files with 9 additions and 2 deletions

View File

@ -6,13 +6,15 @@ import { v4 as uuid } from 'uuid'
import { ShellContext } from 'contexts/ShellContext'
import { SettingsContext } from 'contexts/SettingsContext'
import { PeerActions } from 'models/network'
import { ReceivedMessage, UnsentMessage } from 'models/chat'
import { ReceivedMessage, UnsentMessage, Message } from 'models/chat'
import { funAnimalName } from 'fun-animal-names'
import { getPeerName } from 'components/PeerNameDisplay'
import { NotificationService } from 'services/Notification'
import { Audio } from 'services/Audio'
import { PeerRoom } from 'services/PeerRoom'
import { messageTranscriptSizeLimit } from 'config/messaging'
import { usePeerRoomAction } from './usePeerRoomAction'
interface UseRoomConfig {
@ -30,13 +32,17 @@ export function useRoom(
const shellContext = useContext(ShellContext)
const settingsContext = useContext(SettingsContext)
const [isMessageSending, setIsMessageSending] = useState(false)
const [messageLog, setMessageLog] = useState<
const [messageLog, _setMessageLog] = useState<
Array<ReceivedMessage | UnsentMessage>
>([])
const [newMessageAudio] = useState(
() => new Audio(process.env.PUBLIC_URL + '/sounds/new-message.aac')
)
const setMessageLog = (messages: Message[]) => {
_setMessageLog(messages.slice(-messageTranscriptSizeLimit))
}
useEffect(() => {
return () => {
peerRoom.leaveRoom()

View File

@ -1 +1,2 @@
export const messageCharacterSizeLimit = 10_000
export const messageTranscriptSizeLimit = 10_000