Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try {
await room.onMatrixReaction(ev);
} catch (e) {
log.error("Failed procesing reaction message: ", e);
endTimer({outcome: "fail"});
return;
}
endTimer({outcome: "success"});
}
let success = false;
// Handle a m.room.message event
if (ev.type === "m.room.message" || ev.content) {
if (ev.content["m.relates_to"] !== undefined) {
const relatesTo = ev.content["m.relates_to"];
if (relatesTo.rel_type === "m.replace" && relatesTo.event_id) {
// We have an edit.
try {
success = await room.onMatrixEdit(ev);
} catch (e) {
log.error("Failed processing matrix edit: ", e);
endTimer({outcome: "fail"});
return;
}
}
}
try {
success = await room.onMatrixMessage(ev);
} catch (e) {
log.error("Failed processing matrix message: ", e);
endTimer({outcome: "fail"});
// Handle a m.reaction event
if (ev.type === "m.reaction") {
room.onMatrixReaction(ev).then(
() => endTimer({outcome: "success"}),
(e) => {
log.error("Failed procesing matrix message: ", e);
endTimer({outcome: "fail"});
}
);
return;
}
// Handle a m.room.message event
if (ev.type === "m.room.message" || ev.content) {
if (ev.content['m.relates_to'] !== undefined) {
const relates_to = ev.content['m.relates_to'];
if (relates_to.rel_type === "m.replace" && relates_to.event_id !== undefined) {
log.info("edit in progress");
// We have an edit.
room.onMatrixEdit(ev).then(
() => endTimer({outcome: "success"}),
(e) => {
log.error("Failed procesing matrix message: ", e);
endTimer({outcome: "fail"});
}
);
return;
}
}
room.onMatrixMessage(ev).then(
() => endTimer({outcome: "success"}),
// Handle a m.reaction event
if (ev.type === "m.reaction") {
room.onMatrixReaction(ev).then(
() => endTimer({outcome: "success"}),
(e) => {
log.error("Failed procesing matrix message: ", e);
endTimer({outcome: "fail"});
}
);
return;
}
// Handle a m.room.message event
if (ev.type === "m.room.message" || ev.content) {
if (ev.content['m.relates_to'] !== undefined) {
const relates_to = ev.content['m.relates_to'];
if (relates_to.rel_type === "m.replace" && relates_to.event_id !== undefined) {
log.info("edit in progress");
// We have an edit.
room.onMatrixEdit(ev).then(
() => endTimer({outcome: "success"}),
(e) => {
log.error("Failed procesing matrix message: ", e);
endTimer({outcome: "fail"});
}
);
return;
}
}
room.onMatrixMessage(ev).then(
() => endTimer({outcome: "success"}),
(e) => {
private async findParentReply(message: any, depth: number = 0): Promise {
const MAX_DEPTH = 10;
// Extract the referenced event
if (!message.content) { return message.event_id; }
if (!message.content["m.relates_to"]) { return message.event_id; }
if (!message.content["m.relates_to"]["m.in_reply_to"]) { return message.event_id; }
const parentEventId = message.content["m.relates_to"]["m.in_reply_to"].event_id;
if (!parentEventId) { return message.event_id; }
if (depth > MAX_DEPTH) {
return parentEventId; // We have hit our depth limit, use this one.
}
const intent = await this.getIntentForRoom(message.room_id);
const nextEvent = await intent.getClient().fetchRoomEvent(message.room_id, parentEventId);
return this.findParentReply(nextEvent, depth++);
}
if (!alg) {
// MatrixClient has already checked that this room should be encrypted,
// so this is an unexpected situation.
throw new Error("Room was previously configured to use encryption, but is " + "no longer. Perhaps the homeserver is hiding the " + "configuration event.");
}
if (!this._roomDeviceTrackingState[roomId]) {
this.trackRoomDevices(roomId);
}
// wait for all the room devices to be loaded
await this._roomDeviceTrackingState[roomId];
let content = event.getContent();
// If event has an m.relates_to then we need
// to put this on the wrapping event instead
const mRelatesTo = content['m.relates_to'];
if (mRelatesTo) {
// Clone content here so we don't remove `m.relates_to` from the local-echo
content = Object.assign({}, content);
delete content['m.relates_to'];
}
const encryptedContent = await alg.encryptMessage(room, event.getType(), content);
if (mRelatesTo) {
encryptedContent['m.relates_to'] = mRelatesTo;
}
event.makeEncrypted("m.room.encrypted", encryptedContent, this._olmDevice.deviceCurve25519Key, this._olmDevice.deviceEd25519Key);
};
}
if (!this._roomDeviceTrackingState[roomId]) {
this.trackRoomDevices(roomId);
}
// wait for all the room devices to be loaded
await this._roomDeviceTrackingState[roomId];
let content = event.getContent();
// If event has an m.relates_to then we need
// to put this on the wrapping event instead
const mRelatesTo = content['m.relates_to'];
if (mRelatesTo) {
// Clone content here so we don't remove `m.relates_to` from the local-echo
content = Object.assign({}, content);
delete content['m.relates_to'];
}
const encryptedContent = await alg.encryptMessage(
room, event.getType(), content);
if (mRelatesTo) {
encryptedContent['m.relates_to'] = mRelatesTo;
}
event.makeEncrypted(
"m.room.encrypted",
encryptedContent,
this._olmDevice.deviceCurve25519Key,
this._olmDevice.deviceEd25519Key,
);
};
isRelation(relType = undefined) {
// Relation info is lifted out of the encrypted content when sent to
// encrypted rooms, so we have to check `getWireContent` for this.
const content = this.getWireContent();
const relation = content && content["m.relates_to"];
return relation && relation.rel_type && relation.event_id && (relType && relation.rel_type === relType || !relType);
},
return function (event) {
// listen for events related to this verification
if (event.getRoomId() !== roomId || event.getSender() !== userId) {
return;
}
const content = event.getContent();
if (!content["m.relates_to"]) {
return;
}
const relatesTo = content["m.relationship"] || content["m.relates_to"];
if (!relatesTo.rel_type || relatesTo.rel_type !== "m.reference" || !relatesTo.event_id || relatesTo.event_id !== eventId) {
return;
}
// the event seems to be related to this verification, so pass it on to
// the verification handler
target.handleEvent(event);
};
}
["rel_type"].forEach((prop) => {
if (
!event.content ||
!event.content["m.relates_to"] ||
!event.content["m.relates_to"][prop]
) {
return;
}
event.content["m.relates_to"][prop] = intern(event.content["m.relates_to"][prop]);
});
["rel_type"].forEach(prop => {
if (!event.content || !event.content["m.relates_to"] || !event.content["m.relates_to"][prop]) {
return;
}
event.content["m.relates_to"][prop] = intern(event.content["m.relates_to"][prop]);
});