1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-23 17:02:25 +03:00

crypto: Add new ClientEvent.ReceivedToDeviceMessage with proper OlmEncryptionInfo support (#4891)

* crypto: Add new ClientEvent.ReceivedToDeviceMessage

refactor rename ProcessedToDeviceEvent to ReceivedToDeviceEvent

* fix: Restore legacy isEncrypted() for to-device messages

* Update test for new preprocessToDeviceMessages API

* quick fix on doc

* quick update docs and renaming

* review: Better doc and names for OlmEncryptionInfo

* review: Remove IToDeviceMessage alias and only keep IToDeviceEvent

* review: improve comments of processToDeviceMessages

* review: pass up encrypted event when no crypto callbacks

* review: use single payload for ReceivedToDeviceMessage

* fix linter

* review: minor comment update
This commit is contained in:
Valere Fedronic
2025-07-02 10:02:23 +02:00
committed by GitHub
parent de659d6431
commit 161c12f5d5
9 changed files with 304 additions and 61 deletions

View File

@@ -37,6 +37,7 @@ import {
type IStateEvent,
type IStrippedState,
type ISyncResponse,
type ReceivedToDeviceMessage,
} from "./sync-accumulator.ts";
import { MatrixError } from "./http-api/index.ts";
import {
@@ -150,11 +151,20 @@ class ExtensionToDevice implements Extension<ExtensionToDeviceRequest, Extension
}
public async onResponse(data: ExtensionToDeviceResponse): Promise<void> {
let events = data["events"] || [];
if (events.length > 0 && this.cryptoCallbacks) {
events = await this.cryptoCallbacks.preprocessToDeviceMessages(events);
const events = data["events"] || [];
let receivedToDeviceMessages: ReceivedToDeviceMessage[];
if (this.cryptoCallbacks) {
receivedToDeviceMessages = await this.cryptoCallbacks.preprocessToDeviceMessages(events);
} else {
receivedToDeviceMessages = events.map((rawEvent) =>
// Crypto is not enabled, so we just return the events.
({
message: rawEvent,
encryptionInfo: null,
}),
);
}
processToDeviceMessages(events, this.client);
processToDeviceMessages(receivedToDeviceMessages, this.client);
this.nextBatch = data.next_batch;
}