Skip to content

Commit

Permalink
Log when we send to-device messages
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh committed Oct 19, 2023
1 parent 884bd25 commit 03264f1
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions src/rust-crypto/OutgoingRequestProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { IHttpOpts, MatrixHttpApi, Method } from "../http-api";
import { QueryDict } from "../utils";
import { IAuthDict, UIAuthCallback } from "../interactive-auth";
import { UIAResponse } from "../@types/uia";
import { ToDeviceMessageId } from "../@types/event";

/**
* Common interface for all the request types returned by `OlmMachine.outgoingRequests`.
Expand Down Expand Up @@ -82,10 +83,7 @@ export class OutgoingRequestProcessor {
msg.body,
);
} else if (msg instanceof ToDeviceRequest) {
const path =
`/_matrix/client/v3/sendToDevice/${encodeURIComponent(msg.event_type)}/` +
encodeURIComponent(msg.txn_id);
resp = await this.rawJsonRequest(Method.Put, path, {}, msg.body);
resp = await this.sendToDeviceRequest(msg);
} else if (msg instanceof RoomMessageRequest) {
const path =
`/_matrix/client/v3/rooms/${encodeURIComponent(msg.room_id)}/send/` +
Expand Down Expand Up @@ -122,6 +120,34 @@ export class OutgoingRequestProcessor {
}
}

/**
* Send the HTTP request for a `ToDeviceRequest`
*
* @param request request to send

Check failure on line 126 in src/rust-crypto/OutgoingRequestProcessor.ts

View workflow job for this annotation

GitHub Actions / ESLint

tsdoc-param-tag-missing-hyphen: The @param block should be followed by a parameter name and then a hyphen
* @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)) {

Check failure on line 134 in src/rust-crypto/OutgoingRequestProcessor.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 18)

OutgoingRequestProcessor › should handle ToDeviceRequests

TypeError: Cannot convert undefined or null to object at Function.entries (<anonymous>) at OutgoingRequestProcessor.entries [as sendToDeviceRequest] (src/rust-crypto/OutgoingRequestProcessor.ts:134:56) at OutgoingRequestProcessor.sendToDeviceRequest (src/rust-crypto/OutgoingRequestProcessor.ts:86:31) at Object.makeOutgoingRequest (spec/unit/rust-crypto/OutgoingRequestProcessor.spec.ts:128:35)

Check failure on line 134 in src/rust-crypto/OutgoingRequestProcessor.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node latest)

OutgoingRequestProcessor › should handle ToDeviceRequests

TypeError: Cannot convert undefined or null to object at Function.entries (<anonymous>) at OutgoingRequestProcessor.entries [as sendToDeviceRequest] (src/rust-crypto/OutgoingRequestProcessor.ts:134:56) at OutgoingRequestProcessor.sendToDeviceRequest (src/rust-crypto/OutgoingRequestProcessor.ts:86:31) at Object.makeOutgoingRequest (spec/unit/rust-crypto/OutgoingRequestProcessor.spec.ts:128:35)
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>(
method: Method,
path: string,
Expand Down

0 comments on commit 03264f1

Please sign in to comment.