21 lines
964 B
TypeScript
21 lines
964 B
TypeScript
import { useContext } from "react";
|
|
import { SystemAccountContext } from "./SystemAccountsProvider";
|
|
|
|
/**
|
|
* Возвращает функцию для отправки системного сообщения от имени указанного системного аккаунта
|
|
*
|
|
* ВАЖНО! Данный хук отправляет сообщение в текущий залогиненный аккаунт.
|
|
* @param accountUsername имя системного аккаунта от которого необходимо отправить сообщение
|
|
* @returns
|
|
*/
|
|
export function useSendSystemMessage(accountUsername : string) {
|
|
const context = useContext(SystemAccountContext);
|
|
if(!context){
|
|
throw new Error("useSystemSend must be used within a SystemAccountProvider");
|
|
}
|
|
const send = (message: string) => {
|
|
return context.sendMessageFromSystemAccount(accountUsername, message);
|
|
}
|
|
|
|
return send;
|
|
} |