Fix traceback on Abuse Report. (#230)

* Have the callback work on the packed event Obj.

And also explicitly pack the Mjolnir object inside the event.

* Add VS ignores.

* Commit suggested review changes.

- Add bind to callback
- Add type cast for event packed object

* Fix missing parenthesis.

* Don't pass Mjolnir obj to handleReport().

Co-authored-by: David Teller <davidt@element.io>
This commit is contained in:
Marco CirilloandDavid Teller authored and GitHub committed 2022-05-13 15:18:30 +02:00
1 parent 74d8caa7e7
commit 27ae3ec625
3 files changed
+5 -5

No files matched your search

+1 -1
View File
@@ -73,5 +73,5 @@ typings/
# Python packing directories.
mjolnir.egg-info/
# VS
# Visual Studio data
.vs
+3 -3
View File
@@ -253,7 +253,7 @@ export class Mjolnir {
// Setup Web APIs
console.log("Creating Web APIs");
const reportManager = new ReportManager(this);
reportManager.on("report.new", this.handleReport);
reportManager.on("report.new", this.handleReport.bind(this));
this.webapis = new WebAPIs(reportManager, this.ruleServer);
// Setup join/leave listener
@@ -1158,9 +1158,9 @@ export class Mjolnir {
return await this.eventRedactionQueue.process(this, roomId);
}
private async handleReport(roomId: string, reporterId: string, event: any, reason?: string) {
private async handleReport(e: { roomId: string, reporterId: string, event: any, reason?: string }) {
for (const protection of this.enabledProtections) {
await protection.handleReport(this, roomId, reporterId, event, reason);
await protection.handleReport(this, e.roomId, e.reporterId, e.event, e.reason);
}
}
}
+1 -1
View File
@@ -39,7 +39,7 @@ export abstract class Protection {
}
/*
* Handle a single reported event from a protecte room, to decide if we
* Handle a single reported event from a protected room, to decide if we
* need to respond to it
*/
async handleReport(mjolnir: Mjolnir, roomId: string, reporterId: string, event: any, reason?: string): Promise<any> {