You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-07 23:02:56 +03:00
Element-R: log when we send to-device messages (#3810)
* Log when we send to-device messages * lint * fix test
This commit is contained in:
committed by
GitHub
parent
febc4c9ad6
commit
7501e28dec
@@ -121,7 +121,7 @@ describe("OutgoingRequestProcessor", () => {
|
|||||||
|
|
||||||
it("should handle ToDeviceRequests", async () => {
|
it("should handle ToDeviceRequests", async () => {
|
||||||
// first, mock up the ToDeviceRequest as we might expect to receive it from the Rust layer ...
|
// first, mock up the ToDeviceRequest as we might expect to receive it from the Rust layer ...
|
||||||
const testBody = '{ "foo": "bar" }';
|
const testBody = '{ "messages": { "user": {"device": "bar" }}}';
|
||||||
const outgoingRequest = new ToDeviceRequest("1234", "test/type", "test/txnid", testBody);
|
const outgoingRequest = new ToDeviceRequest("1234", "test/type", "test/txnid", testBody);
|
||||||
|
|
||||||
// ... then poke it into the OutgoingRequestProcessor under test.
|
// ... then poke it into the OutgoingRequestProcessor under test.
|
||||||
|
@@ -31,6 +31,7 @@ import { IHttpOpts, MatrixHttpApi, Method } from "../http-api";
|
|||||||
import { QueryDict } from "../utils";
|
import { QueryDict } from "../utils";
|
||||||
import { IAuthDict, UIAuthCallback } from "../interactive-auth";
|
import { IAuthDict, UIAuthCallback } from "../interactive-auth";
|
||||||
import { UIAResponse } from "../@types/uia";
|
import { UIAResponse } from "../@types/uia";
|
||||||
|
import { ToDeviceMessageId } from "../@types/event";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common interface for all the request types returned by `OlmMachine.outgoingRequests`.
|
* Common interface for all the request types returned by `OlmMachine.outgoingRequests`.
|
||||||
@@ -82,10 +83,7 @@ export class OutgoingRequestProcessor {
|
|||||||
msg.body,
|
msg.body,
|
||||||
);
|
);
|
||||||
} else if (msg instanceof ToDeviceRequest) {
|
} else if (msg instanceof ToDeviceRequest) {
|
||||||
const path =
|
resp = await this.sendToDeviceRequest(msg);
|
||||||
`/_matrix/client/v3/sendToDevice/${encodeURIComponent(msg.event_type)}/` +
|
|
||||||
encodeURIComponent(msg.txn_id);
|
|
||||||
resp = await this.rawJsonRequest(Method.Put, path, {}, msg.body);
|
|
||||||
} else if (msg instanceof RoomMessageRequest) {
|
} else if (msg instanceof RoomMessageRequest) {
|
||||||
const path =
|
const path =
|
||||||
`/_matrix/client/v3/rooms/${encodeURIComponent(msg.room_id)}/send/` +
|
`/_matrix/client/v3/rooms/${encodeURIComponent(msg.room_id)}/send/` +
|
||||||
@@ -122,6 +120,34 @@ export class OutgoingRequestProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send the HTTP request for a `ToDeviceRequest`
|
||||||
|
*
|
||||||
|
* @param request - request to send
|
||||||
|
* @returns JSON-serialized body of the response, if successful
|
||||||
|
*/
|
||||||
|
private async sendToDeviceRequest(request: ToDeviceRequest): Promise<string> {
|
||||||
|
// a bit of extra logging, to help trace to-device messages through the system
|
||||||
|
const parsedBody: { messages: Record<string, Record<string, Record<string, any>>> } = JSON.parse(request.body);
|
||||||
|
|
||||||
|
const messageList = [];
|
||||||
|
for (const [userId, perUserMessages] of Object.entries(parsedBody.messages)) {
|
||||||
|
for (const [deviceId, message] of Object.entries(perUserMessages)) {
|
||||||
|
messageList.push(`${userId}/${deviceId} (msgid ${message[ToDeviceMessageId]})`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
`Sending batch of to-device messages. type=${request.event_type} txnid=${request.txn_id}`,
|
||||||
|
messageList,
|
||||||
|
);
|
||||||
|
|
||||||
|
const path =
|
||||||
|
`/_matrix/client/v3/sendToDevice/${encodeURIComponent(request.event_type)}/` +
|
||||||
|
encodeURIComponent(request.txn_id);
|
||||||
|
return await this.rawJsonRequest(Method.Put, path, {}, request.body);
|
||||||
|
}
|
||||||
|
|
||||||
private async makeRequestWithUIA<T>(
|
private async makeRequestWithUIA<T>(
|
||||||
method: Method,
|
method: Method,
|
||||||
path: string,
|
path: string,
|
||||||
|
Reference in New Issue
Block a user