Element-R: Report events with withheld keys separately to Posthog. (#12755)

* Remove refs to deprecated method

`MatrixEvent.isEncryptedDisabledForUnverifiedDevices` is now deprecated

* Report new posthog code for withheld message keys
This commit is contained in:
Richard van der Hoff 2024-07-10 10:22:59 +01:00 committed by GitHub
parent c894bebaa0
commit 19f9f98564
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 35 additions and 56 deletions

View file

@ -73,7 +73,7 @@
}, },
"dependencies": { "dependencies": {
"@babel/runtime": "^7.12.5", "@babel/runtime": "^7.12.5",
"@matrix-org/analytics-events": "^0.23.0", "@matrix-org/analytics-events": "^0.24.0",
"@matrix-org/emojibase-bindings": "^1.1.2", "@matrix-org/emojibase-bindings": "^1.1.2",
"@matrix-org/matrix-wysiwyg": "2.37.4", "@matrix-org/matrix-wysiwyg": "2.37.4",
"@matrix-org/react-sdk-module-api": "^2.4.0", "@matrix-org/react-sdk-module-api": "^2.4.0",

View file

@ -78,7 +78,10 @@ export class DecryptionFailureTracker {
// Map JS-SDK error codes to tracker codes for aggregation // Map JS-SDK error codes to tracker codes for aggregation
switch (errorCode) { switch (errorCode) {
case DecryptionFailureCode.MEGOLM_UNKNOWN_INBOUND_SESSION_ID: case DecryptionFailureCode.MEGOLM_UNKNOWN_INBOUND_SESSION_ID:
case DecryptionFailureCode.MEGOLM_KEY_WITHHELD:
return "OlmKeysNotSentError"; return "OlmKeysNotSentError";
case DecryptionFailureCode.MEGOLM_KEY_WITHHELD_FOR_UNVERIFIED_DEVICE:
return "RoomKeysWithheldForUnverifiedDevice";
case DecryptionFailureCode.OLM_UNKNOWN_MESSAGE_INDEX: case DecryptionFailureCode.OLM_UNKNOWN_MESSAGE_INDEX:
return "OlmIndexError"; return "OlmIndexError";
case DecryptionFailureCode.HISTORICAL_MESSAGE_NO_KEY_BACKUP: case DecryptionFailureCode.HISTORICAL_MESSAGE_NO_KEY_BACKUP:

View file

@ -23,8 +23,10 @@ import { IBodyProps } from "./IBodyProps";
import { LocalDeviceVerificationStateContext } from "../../../contexts/LocalDeviceVerificationStateContext"; import { LocalDeviceVerificationStateContext } from "../../../contexts/LocalDeviceVerificationStateContext";
function getErrorMessage(mxEvent: MatrixEvent, isVerified: boolean | undefined): string { function getErrorMessage(mxEvent: MatrixEvent, isVerified: boolean | undefined): string {
if (mxEvent.isEncryptedDisabledForUnverifiedDevices) return _t("timeline|decryption_failure|blocked");
switch (mxEvent.decryptionFailureReason) { switch (mxEvent.decryptionFailureReason) {
case DecryptionFailureCode.MEGOLM_KEY_WITHHELD_FOR_UNVERIFIED_DEVICE:
return _t("timeline|decryption_failure|blocked");
case DecryptionFailureCode.HISTORICAL_MESSAGE_NO_KEY_BACKUP: case DecryptionFailureCode.HISTORICAL_MESSAGE_NO_KEY_BACKUP:
return _t("timeline|decryption_failure|historical_event_no_key_backup"); return _t("timeline|decryption_failure|historical_event_no_key_backup");

View file

@ -490,47 +490,22 @@ describe("DecryptionFailureTracker", function () {
const now = Date.now(); const now = Date.now();
const event1 = await createFailedDecryptionEvent({ async function createAndTrackEventWithError(code: DecryptionFailureCode) {
code: DecryptionFailureCode.MEGOLM_UNKNOWN_INBOUND_SESSION_ID, const event = await createFailedDecryptionEvent({ code });
}); tracker.addVisibleEvent(event);
tracker.addVisibleEvent(event1); eventDecrypted(tracker, event, now);
eventDecrypted(tracker, event1, now); return event;
}
const event2 = await createFailedDecryptionEvent({ await createAndTrackEventWithError(DecryptionFailureCode.MEGOLM_UNKNOWN_INBOUND_SESSION_ID);
code: DecryptionFailureCode.OLM_UNKNOWN_MESSAGE_INDEX, await createAndTrackEventWithError(DecryptionFailureCode.OLM_UNKNOWN_MESSAGE_INDEX);
}); await createAndTrackEventWithError(DecryptionFailureCode.HISTORICAL_MESSAGE_NO_KEY_BACKUP);
tracker.addVisibleEvent(event2); await createAndTrackEventWithError(DecryptionFailureCode.HISTORICAL_MESSAGE_BACKUP_UNCONFIGURED);
eventDecrypted(tracker, event2, now); await createAndTrackEventWithError(DecryptionFailureCode.HISTORICAL_MESSAGE_WORKING_BACKUP);
await createAndTrackEventWithError(DecryptionFailureCode.HISTORICAL_MESSAGE_USER_NOT_JOINED);
const event3 = await createFailedDecryptionEvent({ await createAndTrackEventWithError(DecryptionFailureCode.MEGOLM_KEY_WITHHELD);
code: DecryptionFailureCode.HISTORICAL_MESSAGE_NO_KEY_BACKUP, await createAndTrackEventWithError(DecryptionFailureCode.MEGOLM_KEY_WITHHELD_FOR_UNVERIFIED_DEVICE);
}); await createAndTrackEventWithError(DecryptionFailureCode.UNKNOWN_ERROR);
tracker.addVisibleEvent(event3);
eventDecrypted(tracker, event3, now);
const event4 = await createFailedDecryptionEvent({
code: DecryptionFailureCode.HISTORICAL_MESSAGE_BACKUP_UNCONFIGURED,
});
tracker.addVisibleEvent(event4);
eventDecrypted(tracker, event4, now);
const event5 = await createFailedDecryptionEvent({
code: DecryptionFailureCode.HISTORICAL_MESSAGE_WORKING_BACKUP,
});
tracker.addVisibleEvent(event5);
eventDecrypted(tracker, event5, now);
const event6 = await createFailedDecryptionEvent({
code: DecryptionFailureCode.HISTORICAL_MESSAGE_USER_NOT_JOINED,
});
tracker.addVisibleEvent(event6);
eventDecrypted(tracker, event6, now);
const event7 = await createFailedDecryptionEvent({
code: DecryptionFailureCode.UNKNOWN_ERROR,
});
tracker.addVisibleEvent(event7);
eventDecrypted(tracker, event7, now);
// Pretend "now" is Infinity // Pretend "now" is Infinity
tracker.checkFailures(Infinity); tracker.checkFailures(Infinity);
@ -542,6 +517,8 @@ describe("DecryptionFailureTracker", function () {
"HistoricalMessage", "HistoricalMessage",
"HistoricalMessage", "HistoricalMessage",
"ExpectedDueToMembership", "ExpectedDueToMembership",
"OlmKeysNotSentError",
"RoomKeysWithheldForUnverifiedDevice",
"UnknownError", "UnknownError",
]); ]);
}); });

View file

@ -50,18 +50,15 @@ describe("DecryptionFailureBody", () => {
expect(container).toMatchSnapshot(); expect(container).toMatchSnapshot();
}); });
it(`Should display "The sender has blocked you from receiving this message"`, () => { it(`Should display "The sender has blocked you from receiving this message"`, async () => {
// When // When
const event = mkEvent({ const event = await mkDecryptionFailureMatrixEvent({
type: "m.room.message", code: DecryptionFailureCode.MEGOLM_KEY_WITHHELD_FOR_UNVERIFIED_DEVICE,
room: "myfakeroom", msg: "withheld",
user: "myfakeuser", roomId: "myfakeroom",
content: { sender: "myfakeuser",
msgtype: "m.bad.encrypted",
},
event: true,
}); });
jest.spyOn(event, "isEncryptedDisabledForUnverifiedDevices", "get").mockReturnValue(true);
const { container } = customRender(event); const { container } = customRender(event);
// Then // Then

View file

@ -1773,10 +1773,10 @@
resolved "https://registry.yarnpkg.com/@mapbox/whoots-js/-/whoots-js-3.1.0.tgz#497c67a1cef50d1a2459ba60f315e448d2ad87fe" resolved "https://registry.yarnpkg.com/@mapbox/whoots-js/-/whoots-js-3.1.0.tgz#497c67a1cef50d1a2459ba60f315e448d2ad87fe"
integrity sha512-Es6WcD0nO5l+2BOQS4uLfNPYQaNDfbot3X1XUoloz+x0mPDS3eeORZJl06HXjwBG1fOGwCRnzK88LMdxKRrd6Q== integrity sha512-Es6WcD0nO5l+2BOQS4uLfNPYQaNDfbot3X1XUoloz+x0mPDS3eeORZJl06HXjwBG1fOGwCRnzK88LMdxKRrd6Q==
"@matrix-org/analytics-events@^0.23.0": "@matrix-org/analytics-events@^0.24.0":
version "0.23.1" version "0.24.0"
resolved "https://registry.yarnpkg.com/@matrix-org/analytics-events/-/analytics-events-0.23.1.tgz#206224f63e64b8cd892f704964204bce433bd189" resolved "https://registry.yarnpkg.com/@matrix-org/analytics-events/-/analytics-events-0.24.0.tgz#21a64537ac975b18e1eb13d9fd0bdc7d448a6039"
integrity sha512-+DuK5F313bZfO0jCsP7X3u0FQ09IM9Ujc9Zf//XoxzGThG9pvSYsEyNXQO7kUeQHwXlOobtVg1QcP172kN+h/g== integrity sha512-3FDdtqZ+5cMqVffWjFNOIQ7RDFN6XS11kqdtN2ps8uvq5ce8gT0yXQvK37WeKWKZZ5QAKeoMzGhud+lsVcb1xg==
"@matrix-org/emojibase-bindings@^1.1.2": "@matrix-org/emojibase-bindings@^1.1.2":
version "1.1.3" version "1.1.3"