mirror of
https://github.com/the-draupnir-project/Draupnir.git
synced 2026-10-23 09:22:24 +00:00
Make updateForEvent actually update PolicyLists. (#448)
For some reason we were relying on a mjolnir listening to `'PolicyList.batch'` to update policy lists. This was exposing an implementation detail to Mjolnir and including it as part of the implementation of `PolicyList.updateForEvent()` which is supposed to cause the `PolicyList` to update (eventually). I am confident this was because of a need before batching was introduced to get the changes to a policy list directly from the method call to `PolicyList.update()`, whereas now you can just listen to `PolicyList.update`. The `'PolicyList.batch'` event has now been removed and the PolicyList event batcher (`UpdateBatcher`) now calls `PolicyList.update()` internally.
This commit is contained in:
1 parent
704bb660c2
commit
5de0dae62a
3 files changed
+17
-12
No files matched your search
@@ -56,9 +56,6 @@ declare interface PolicyList {
|
||||
// PolicyList.update is emitted when the PolicyList has pulled new rules from Matrix and informs listeners of any changes.
|
||||
on(event: 'PolicyList.update', listener: (list: PolicyList, changes: ListRuleChange[]) => void): this
|
||||
emit(event: 'PolicyList.update', list: PolicyList, changes: ListRuleChange[]): boolean
|
||||
// PolicyList.batch is emitted when the PolicyList has created a batch from the events provided by `updateForEvent`.
|
||||
on(event: 'PolicyList.batch', listener: (list: PolicyList) => void): this
|
||||
emit(event: 'PolicyList.batch', list: PolicyList): boolean
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -476,7 +473,8 @@ export default PolicyList;
|
||||
|
||||
/**
|
||||
* Helper class that emits a batch event on a `PolicyList` when it has made a batch
|
||||
* out of the events given to `addToBatch`.
|
||||
* out of the Matrix events given to `addToBatch` via `updateForEvent`.
|
||||
* The `UpdateBatcher` will then call `list.update()` on the associated `PolicyList` once it has finished batching events.
|
||||
*/
|
||||
class UpdateBatcher {
|
||||
// Whether we are waiting for more events to form a batch.
|
||||
@@ -510,7 +508,8 @@ class UpdateBatcher {
|
||||
await new Promise(resolve => setTimeout(resolve, this.waitPeriodMS));
|
||||
} while ((Date.now() - start) < this.maxWaitMS && this.latestEventId !== eventId)
|
||||
this.reset();
|
||||
this.banList.emit('PolicyList.batch', this.banList);
|
||||
// batching finished, update the associated list.
|
||||
await this.banList.updateList();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user