mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
fix(dictation): stop recording on channel/thread switch
When the composer's draftKey changes (channel or thread switch), stop any active dictation session so transcript events from a stale WebRTC connection don't leak into the wrong draft. Signed-off-by: klopez4212 <klopez4212@gmail.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type * as React from "react";
|
||||
import { useRef } from "react";
|
||||
import { useEffect, useRef } from "react";
|
||||
import { useDictation } from "./useDictation";
|
||||
|
||||
interface UseComposerDictationOptions {
|
||||
@@ -13,6 +13,8 @@ interface UseComposerDictationOptions {
|
||||
/** Ref to a function that updates the Tiptap editor document. */
|
||||
setEditorContentRef: React.MutableRefObject<(text: string) => void>;
|
||||
submitMessageRef: React.MutableRefObject<() => void>;
|
||||
/** When this key changes (channel/thread switch), active dictation is stopped. */
|
||||
draftKey?: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -27,12 +29,13 @@ export function useComposerDictation({
|
||||
setComposerContent,
|
||||
setEditorContentRef,
|
||||
submitMessageRef,
|
||||
draftKey,
|
||||
}: UseComposerDictationOptions) {
|
||||
const isSendBlockedRef = useRef(false);
|
||||
isSendBlockedRef.current =
|
||||
disabledRef.current || isSendingRef.current || isUploadingRef.current;
|
||||
|
||||
return useDictation({
|
||||
const dictation = useDictation({
|
||||
getText: () => syncContentRef.current(),
|
||||
setText: (text) => {
|
||||
setComposerContent(text);
|
||||
@@ -48,4 +51,13 @@ export function useComposerDictation({
|
||||
},
|
||||
isSendBlockedRef,
|
||||
});
|
||||
|
||||
// Stop dictation when the channel/thread changes so that transcript events
|
||||
// from a stale WebRTC session don't leak into the wrong draft.
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: draftKey is the sole trigger
|
||||
useEffect(() => {
|
||||
dictation.stopRecording();
|
||||
}, [draftKey]);
|
||||
|
||||
return dictation;
|
||||
}
|
||||
|
||||
@@ -275,6 +275,7 @@ function MessageComposerImpl({
|
||||
setComposerContent,
|
||||
setEditorContentRef,
|
||||
submitMessageRef,
|
||||
draftKey: effectiveDraftKey,
|
||||
});
|
||||
const composerScrollRef = React.useRef<HTMLDivElement>(null);
|
||||
// Set after `useLinkEditor` exists below; the editor's link-click handler
|
||||
@@ -1047,5 +1048,4 @@ function MessageComposerImpl({
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export const MessageComposer = React.memo(MessageComposerImpl);
|
||||
|
||||
Reference in New Issue
Block a user