fix(desktop): surface native quick-reply send failures as an error toast
Fixes #79 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
This commit is contained in:
@@ -1,7 +1,10 @@
|
|||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { MsgType } from 'matrix-js-sdk';
|
import { MsgType } from 'matrix-js-sdk';
|
||||||
|
import { useSetAtom } from 'jotai';
|
||||||
|
import { Icons } from 'folds';
|
||||||
import { useMatrixClient } from './useMatrixClient';
|
import { useMatrixClient } from './useMatrixClient';
|
||||||
import { useTauriEvent } from './useTauri';
|
import { useTauriEvent } from './useTauri';
|
||||||
|
import { createErrorToast, toastQueueAtom } from '../state/toast';
|
||||||
|
|
||||||
/** Payload of the `lotus-notification-activate` event (a plain body click). */
|
/** Payload of the `lotus-notification-activate` event (a plain body click). */
|
||||||
interface ActivateDetail {
|
interface ActivateDetail {
|
||||||
@@ -27,6 +30,7 @@ interface ReplyDetail {
|
|||||||
export function useTauriToastActions(): void {
|
export function useTauriToastActions(): void {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const mx = useMatrixClient();
|
const mx = useMatrixClient();
|
||||||
|
const setToast = useSetAtom(toastQueueAtom);
|
||||||
|
|
||||||
useTauriEvent<ActivateDetail>('lotus-notification-activate', ({ path }) => {
|
useTauriEvent<ActivateDetail>('lotus-notification-activate', ({ path }) => {
|
||||||
if (path) navigate(path);
|
if (path) navigate(path);
|
||||||
@@ -34,6 +38,17 @@ export function useTauriToastActions(): void {
|
|||||||
|
|
||||||
useTauriEvent<ReplyDetail>('lotus-notification-reply', ({ roomId, text }) => {
|
useTauriEvent<ReplyDetail>('lotus-notification-reply', ({ roomId, text }) => {
|
||||||
if (!roomId || !text) return;
|
if (!roomId || !text) return;
|
||||||
mx.sendMessage(roomId, { msgtype: MsgType.Text, body: text }).catch(() => undefined);
|
// #79 — a quick-reply failure (offline, no send permission, etc.) used to
|
||||||
|
// be swallowed with no feedback, leaving the user believing it was sent.
|
||||||
|
// Surface it via the in-app error toast instead.
|
||||||
|
mx.sendMessage(roomId, { msgtype: MsgType.Text, body: text }).catch(() => {
|
||||||
|
setToast(
|
||||||
|
createErrorToast(
|
||||||
|
'Your quick reply could not be sent. Please try again.',
|
||||||
|
Icons.Warning,
|
||||||
|
'Reply failed',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user