Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/app/features/room/RoomInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -497,9 +498,17 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
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();
Expand Down
9 changes: 9 additions & 0 deletions src/app/features/room/message/EncryptedContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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' },
});
Expand Down
Loading