Merge pull request #2747 from robintown/decrypt-reactions
Decrypt reaction events
This commit is contained in:
@@ -43,6 +43,8 @@ test("GridTile is accessible", async () => {
|
|||||||
off: () => {},
|
off: () => {},
|
||||||
client: {
|
client: {
|
||||||
getUserId: () => null,
|
getUserId: () => null,
|
||||||
|
on: () => {},
|
||||||
|
off: () => {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
memberships: [],
|
memberships: [],
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
MatrixEvent,
|
MatrixEvent,
|
||||||
RelationType,
|
RelationType,
|
||||||
RoomEvent as MatrixRoomEvent,
|
RoomEvent as MatrixRoomEvent,
|
||||||
|
MatrixEventEvent,
|
||||||
} from "matrix-js-sdk/src/matrix";
|
} from "matrix-js-sdk/src/matrix";
|
||||||
import { ReactionEventContent } from "matrix-js-sdk/src/types";
|
import { ReactionEventContent } from "matrix-js-sdk/src/types";
|
||||||
import {
|
import {
|
||||||
@@ -184,19 +185,21 @@ export const ReactionsProvider = ({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const reactionTimeouts = new Set<number>();
|
const reactionTimeouts = new Set<number>();
|
||||||
const handleReactionEvent = (event: MatrixEvent): void => {
|
const handleReactionEvent = (event: MatrixEvent): void => {
|
||||||
if (event.isSending()) {
|
// Decrypted events might come from a different room
|
||||||
// Skip any events that are still sending.
|
if (event.getRoomId() !== room.roomId) return;
|
||||||
return;
|
// Skip any events that are still sending.
|
||||||
}
|
if (event.isSending()) return;
|
||||||
|
|
||||||
const sender = event.getSender();
|
const sender = event.getSender();
|
||||||
const reactionEventId = event.getId();
|
const reactionEventId = event.getId();
|
||||||
if (!sender || !reactionEventId) {
|
// Skip any event without a sender or event ID.
|
||||||
// Skip any event without a sender or event ID.
|
if (!sender || !reactionEventId) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.getType() === ElementCallReactionEventType) {
|
if (event.getType() === ElementCallReactionEventType) {
|
||||||
|
room.client
|
||||||
|
.decryptEventIfNeeded(event)
|
||||||
|
.catch((e) => logger.warn(`Failed to decrypt ${event.getId()}`, e));
|
||||||
|
if (event.isBeingDecrypted() || event.isDecryptionFailure()) return;
|
||||||
const content: ECallReactionEventContent = event.getContent();
|
const content: ECallReactionEventContent = event.getContent();
|
||||||
|
|
||||||
const membershipEventId = content?.["m.relates_to"]?.event_id;
|
const membershipEventId = content?.["m.relates_to"]?.event_id;
|
||||||
@@ -295,6 +298,7 @@ export const ReactionsProvider = ({
|
|||||||
|
|
||||||
room.on(MatrixRoomEvent.Timeline, handleReactionEvent);
|
room.on(MatrixRoomEvent.Timeline, handleReactionEvent);
|
||||||
room.on(MatrixRoomEvent.Redaction, handleReactionEvent);
|
room.on(MatrixRoomEvent.Redaction, handleReactionEvent);
|
||||||
|
room.client.on(MatrixEventEvent.Decrypted, handleReactionEvent);
|
||||||
|
|
||||||
// We listen for a local echo to get the real event ID, as timeline events
|
// We listen for a local echo to get the real event ID, as timeline events
|
||||||
// may still be sending.
|
// may still be sending.
|
||||||
@@ -303,6 +307,7 @@ export const ReactionsProvider = ({
|
|||||||
return (): void => {
|
return (): void => {
|
||||||
room.off(MatrixRoomEvent.Timeline, handleReactionEvent);
|
room.off(MatrixRoomEvent.Timeline, handleReactionEvent);
|
||||||
room.off(MatrixRoomEvent.Redaction, handleReactionEvent);
|
room.off(MatrixRoomEvent.Redaction, handleReactionEvent);
|
||||||
|
room.client.off(MatrixEventEvent.Decrypted, handleReactionEvent);
|
||||||
room.off(MatrixRoomEvent.LocalEchoUpdated, handleReactionEvent);
|
room.off(MatrixRoomEvent.LocalEchoUpdated, handleReactionEvent);
|
||||||
reactionTimeouts.forEach((t) => clearTimeout(t));
|
reactionTimeouts.forEach((t) => clearTimeout(t));
|
||||||
// If we're clearing timeouts, we also clear all reactions.
|
// If we're clearing timeouts, we also clear all reactions.
|
||||||
|
|||||||
@@ -138,6 +138,13 @@ export class MockRoom extends EventEmitter {
|
|||||||
this.testRedactedEvents.push(props);
|
this.testRedactedEvents.push(props);
|
||||||
return Promise.resolve({ event_id: randomUUID() });
|
return Promise.resolve({ event_id: randomUUID() });
|
||||||
},
|
},
|
||||||
|
decryptEventIfNeeded: async () => {},
|
||||||
|
on() {
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
off() {
|
||||||
|
return this;
|
||||||
|
},
|
||||||
} as unknown as MatrixClient;
|
} as unknown as MatrixClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user