diff --git a/src/app/features/room/RoomInput.tsx b/src/app/features/room/RoomInput.tsx index 27126a3624..ed8b3ae4ca 100644 --- a/src/app/features/room/RoomInput.tsx +++ b/src/app/features/room/RoomInput.tsx @@ -274,6 +274,7 @@ export const getReplyContent = ( const log = createLogger('RoomInput'); const debugLog = createDebugLogger('RoomInput'); +const ENCRYPTION_PREPARATION_INTERVAL_MS = 60_000; interface ReplyEventContent { 'm.relates_to'?: IEventRelation; } @@ -497,9 +498,17 @@ export const RoomInput = forwardRef( const handlePaste = useFilePasteHandler(handleFiles); const dropZoneVisible = useFileDropZone(fileDropContainerRef, handleFiles); const [hasText, setHasText] = useState(false); + const lastEncryptionPreparationAt = useRef(0); const handleEditorChange = useCallback(() => { setHasText(!isEmptyEditor(editor)); - }, [editor]); + if (!room.hasEncryptionStateEvent()) return; + + const now = Date.now(); + if (now - lastEncryptionPreparationAt.current < ENCRYPTION_PREPARATION_INTERVAL_MS) return; + + lastEncryptionPreparationAt.current = now; + mx.getCrypto()?.prepareToEncrypt(room); + }, [editor, mx, room]); const hasContent = hasText || selectedFiles.length > 0; const isComposing = useComposingCheck(); diff --git a/src/app/features/room/message/EncryptedContent.tsx b/src/app/features/room/message/EncryptedContent.tsx index 2ac498318f..99261956d5 100644 --- a/src/app/features/room/message/EncryptedContent.tsx +++ b/src/app/features/room/message/EncryptedContent.tsx @@ -5,8 +5,11 @@ import { useEffect, useState } from 'react'; import { useMatrixClient } from '$hooks/useMatrixClient'; import { scheduleDecrypt } from '$utils/decryptScheduler'; +import { createDebugLogger } from '$utils/debugLogger'; import * as Sentry from '@sentry/react'; +const debugLog = createDebugLogger('EncryptedContent'); + type EncryptedContentProps = { mEvent: MatrixEvent; children: () => ReactNode; @@ -39,6 +42,12 @@ export function EncryptedContent({ mEvent, children }: EncryptedContentProps) { toggleEncrypted(mEvent.getType() === (EventType.RoomMessageEncrypted as string)); const handleDecrypted: MatrixEventHandlerMap[MatrixEventEvent.Decrypted] = (event) => { if (event.isDecryptionFailure()) { + debugLog.error('error', 'Failed to decrypt room event', { + eventId: event.getId(), + roomId: event.getRoomId(), + sender: event.getSender(), + reason: event.decryptionFailureReason ?? 'UNKNOWN_ERROR', + }); Sentry.metrics.count('sable.decryption.failure', 1, { attributes: { reason: event.decryptionFailureReason ?? 'UNKNOWN_ERROR' }, });