Add basic structure for (un)subscribing from lists

This commit is contained in:
Travis Ralston 2019-10-31 15:53:18 -06:00
parent b93508728a
commit 39b657ce7c
4 changed files with 166 additions and 14 deletions

View file

@ -33,6 +33,14 @@ export class Mjolnir {
constructor() {
}
get roomIds(): string[] {
return this._roomIds;
}
get lists(): BanList[] {
return this._lists;
}
start() {
this._mjolnirWatchRef = SettingsStore.watchSetting("mjolnirRooms", null, this._onListsChanged.bind(this));
@ -101,6 +109,18 @@ export class Mjolnir {
return list;
}
async subscribeToList(roomId: string) {
const roomIds = [...this._roomIds, roomId];
await SettingsStore.setValue("mjolnirRooms", null, SettingLevel.ACCOUNT, roomIds);
this._lists.push(new BanList(roomId));
}
async unsubscribeFromList(roomId: string) {
const roomIds = this._roomIds.filter(r => r !== roomId);
await SettingsStore.setValue("mjolnirRooms", null, SettingLevel.ACCOUNT, roomIds);
this._lists = this._lists.filter(b => b.roomId !== roomId);
}
_onEvent(event) {
if (!MatrixClientPeg.get()) return;
if (!this._roomIds.includes(event.getRoomId())) return;