Files
desktop/app/providers/SystemAccountsProvider/useSendSystemMessage.ts
2026-01-31 02:59:35 +02:00

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;
}