Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 5c8b14c

Browse files
authored
Fix requests for senders to submit auto-rageshakes (#12304)
If auto-rageshake-on-UISI is enabled, then when we get a UISI we send the sender a to-device message asking them to also rageshake. Unfortunately, the logic to do so has been broken since c30b263. Also a few other minor cleanups while we're here.
1 parent c3e0535 commit 5c8b14c

File tree

2 files changed

+55
-25
lines changed

2 files changed

+55
-25
lines changed

src/stores/AutoRageshakeStore.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,17 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { ClientEvent, MatrixEvent, MatrixEventEvent, SyncStateData, SyncState } from "matrix-js-sdk/src/matrix";
17+
import {
18+
ClientEvent,
19+
MatrixEvent,
20+
MatrixEventEvent,
21+
SyncStateData,
22+
SyncState,
23+
ToDeviceMessageId,
24+
} from "matrix-js-sdk/src/matrix";
1825
import { sleep } from "matrix-js-sdk/src/utils";
26+
import { v4 as uuidv4 } from "uuid";
27+
import { logger } from "matrix-js-sdk/src/logger";
1928

2029
import SdkConfig from "../SdkConfig";
2130
import sendBugReport from "../rageshake/submit-rageshake";
@@ -108,20 +117,28 @@ export default class AutoRageshakeStore extends AsyncStoreWithClient<IState> {
108117

109118
const now = new Date().getTime();
110119
if (now - this.state.lastRageshakeTime < RAGESHAKE_INTERVAL) {
120+
logger.info(
121+
`Not sending recipient-side autorageshake for event ${ev.getId()}/session ${sessionId}: last rageshake was too recent`,
122+
);
111123
return;
112124
}
113125

114126
await this.updateState({ lastRageshakeTime: now });
115127

128+
const senderUserId = ev.getSender()!;
116129
const eventInfo = {
117130
event_id: ev.getId(),
118131
room_id: ev.getRoomId(),
119132
session_id: sessionId,
120133
device_id: wireContent.device_id,
121-
user_id: ev.getSender()!,
134+
user_id: senderUserId,
122135
sender_key: wireContent.sender_key,
123136
};
124137

138+
logger.info(`Sending recipient-side autorageshake for event ${ev.getId()}/session ${sessionId}`);
139+
// XXX: the rageshake server returns the URL for the github issue... which is typically absent for
140+
// auto-uisis, because we've disabled creation of GH issues for them. So the `recipient_rageshake`
141+
// field is broken.
125142
const rageshakeURL = await sendBugReport(SdkConfig.get().bug_report_endpoint_url, {
126143
userText: "Auto-reporting decryption error (recipient)",
127144
sendLogs: true,
@@ -133,10 +150,11 @@ export default class AutoRageshakeStore extends AsyncStoreWithClient<IState> {
133150
const messageContent = {
134151
...eventInfo,
135152
recipient_rageshake: rageshakeURL,
153+
[ToDeviceMessageId]: uuidv4(),
136154
};
137155
this.matrixClient?.sendToDevice(
138156
AUTO_RS_REQUEST,
139-
new Map([["messageContent.user_id", new Map([[messageContent.device_id, messageContent]])]]),
157+
new Map([[senderUserId, new Map([[messageContent.device_id, messageContent]])]]),
140158
);
141159
}
142160
}
@@ -158,6 +176,9 @@ export default class AutoRageshakeStore extends AsyncStoreWithClient<IState> {
158176
const now = new Date().getTime();
159177
if (now - this.state.lastRageshakeTime > RAGESHAKE_INTERVAL) {
160178
await this.updateState({ lastRageshakeTime: now });
179+
logger.info(
180+
`Sending sender-side autorageshake for event ${messageContent["event_id"]}/session ${messageContent["session_id"]}`,
181+
);
161182
await sendBugReport(SdkConfig.get().bug_report_endpoint_url, {
162183
userText: `Auto-reporting decryption error (sender)\nRecipient rageshake: ${recipientRageshake}`,
163184
sendLogs: true,
@@ -168,6 +189,10 @@ export default class AutoRageshakeStore extends AsyncStoreWithClient<IState> {
168189
auto_uisi: JSON.stringify(messageContent),
169190
},
170191
});
192+
} else {
193+
logger.info(
194+
`Not sending sender-side autorageshake for event ${messageContent["event_id"]}/session ${messageContent["session_id"]}: last rageshake was too recent`,
195+
);
171196
}
172197
}
173198

test/stores/AutoRageshakeStore-test.ts

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ jest.mock("../../src/rageshake/submit-rageshake");
3232
jest.mock("../../src/stores/WidgetStore");
3333
jest.mock("../../src/stores/widgets/WidgetLayoutStore");
3434

35+
const TEST_SENDER = "@[email protected]";
36+
3537
describe("AutoRageshakeStore", () => {
3638
const roomId = "!room:example.com";
3739
let client: MatrixClient;
@@ -59,7 +61,7 @@ describe("AutoRageshakeStore", () => {
5961
event: true,
6062
content: {},
6163
room: roomId,
62-
user: client.getSafeUserId(),
64+
user: TEST_SENDER,
6365
type: EventType.RoomMessage,
6466
});
6567
jest.spyOn(utdEvent, "isDecryptionFailure").mockReturnValue(true);
@@ -81,29 +83,32 @@ describe("AutoRageshakeStore", () => {
8183
jest.advanceTimersByTime(5500);
8284
});
8385

84-
it("should send a rageshake", () => {
85-
expect(mocked(client).sendToDevice.mock.calls).toMatchInlineSnapshot(
86-
`
86+
it("should send a to-device message", () => {
87+
expect(mocked(client).sendToDevice.mock.calls).toEqual([
8788
[
88-
[
8989
"im.vector.auto_rs_request",
90-
Map {
91-
"messageContent.user_id" => Map {
92-
undefined => {
93-
"device_id": undefined,
94-
"event_id": "utd_event_id",
95-
"recipient_rageshake": undefined,
96-
"room_id": "!room:example.com",
97-
"sender_key": undefined,
98-
"session_id": undefined,
99-
"user_id": "@userId:matrix.org",
100-
},
101-
},
102-
},
103-
],
104-
]
105-
`.replace("utd_event_id", utdEvent.getId()!),
106-
);
90+
new Map([
91+
[
92+
TEST_SENDER,
93+
new Map([
94+
[
95+
undefined,
96+
{
97+
"device_id": undefined,
98+
"event_id": utdEvent.getId(),
99+
"org.matrix.msgid": expect.any(String),
100+
"recipient_rageshake": undefined,
101+
"room_id": "!room:example.com",
102+
"sender_key": undefined,
103+
"session_id": undefined,
104+
"user_id": TEST_SENDER,
105+
},
106+
],
107+
]),
108+
],
109+
]),
110+
],
111+
]);
107112
});
108113
});
109114
});

0 commit comments

Comments
 (0)