Composer: Fix custom emoji leftovers when opening attachments (#2506)

This commit is contained in:
Alexander Zinchuk 2023-02-08 00:47:29 +01:00
parent 28dc43ab4a
commit 0c57ef9c48
2 changed files with 18 additions and 5 deletions

View File

@ -146,7 +146,15 @@ const MessageInput: FC<OwnProps & StateProps> = ({
const [isTextFormatterDisabled, setIsTextFormatterDisabled] = useState<boolean>(false);
const { isMobile } = useAppLayout();
useInputCustomEmojis(getHtml, inputRef, sharedCanvasRef, sharedCanvasHqRef, absoluteContainerRef);
useInputCustomEmojis(
getHtml,
inputRef,
sharedCanvasRef,
sharedCanvasHqRef,
absoluteContainerRef,
isAttachmentModalInput ? 'attachment' : undefined,
isActive,
);
const maxInputHeight = isMobile ? 256 : 416;
const updateInputHeight = useCallback((willSend = false) => {

View File

@ -37,6 +37,8 @@ export default function useInputCustomEmojis(
sharedCanvasRef: React.RefObject<HTMLCanvasElement>,
sharedCanvasHqRef: React.RefObject<HTMLCanvasElement>,
absoluteContainerRef: React.RefObject<HTMLElement>,
prefixId?: string,
isActive?: boolean,
) {
const mapRef = useRef<Map<string, CustomEmojiPlayer>>(new Map());
@ -59,7 +61,7 @@ export default function useInputCustomEmojis(
const customEmojies = Array.from(inputRef.current.querySelectorAll<HTMLElement>('.custom-emoji'));
customEmojies.forEach((element) => {
const id = element.dataset.uniqueId!;
const id = `${prefixId || ''}${element.dataset.uniqueId!}`;
const documentId = element.dataset.documentId!;
if (!id) {
return;
@ -105,7 +107,10 @@ export default function useInputCustomEmojis(
});
removeContainers(Array.from(removedContainers));
}, [absoluteContainerRef, inputRef, isMobile, removeContainers, sharedCanvasHqRef, sharedCanvasRef]);
}, [
absoluteContainerRef, inputRef, prefixId, isMobile, removeContainers, sharedCanvasHqRef,
sharedCanvasRef,
]);
useEffect(() => {
addCustomEmojiInputRenderCallback(synchronizeElements);
@ -116,13 +121,13 @@ export default function useInputCustomEmojis(
}, [synchronizeElements]);
useEffect(() => {
if (!getHtml() || !inputRef.current || !sharedCanvasRef.current) {
if (!getHtml() || !inputRef.current || !sharedCanvasRef.current || !isActive) {
removeContainers(Array.from(mapRef.current.keys()));
return;
}
synchronizeElements();
}, [getHtml, synchronizeElements, inputRef, removeContainers, sharedCanvasRef]);
}, [getHtml, synchronizeElements, inputRef, removeContainers, sharedCanvasRef, isActive]);
useResizeObserver(sharedCanvasRef, synchronizeElements, true);