RocketChat/Rocket.Chat

View on GitHub
apps/meteor/client/views/room/body/hooks/useQuoteMessageByUrl.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { useSearchParameter } from '@rocket.chat/ui-contexts';
import { useEffect } from 'react';

import { useChat } from '../../contexts/ChatContext';

export const useQuoteMessageByUrl = () => {
    const replyMID = useSearchParameter('reply');

    const chat = useChat();

    if (!chat) {
        throw new Error('No ChatContext provided');
    }

    useEffect(() => {
        if (!replyMID) {
            return;
        }

        chat.data.getMessageByID(replyMID).then((message) => {
            if (!message) {
                return;
            }

            chat.composer?.quoteMessage(message);
        });
    }, [chat.data, chat.composer, replyMID]);
};