Add basic structure for (un)subscribing from lists
This commit is contained in:
parent
b93508728a
commit
39b657ce7c
4 changed files with 166 additions and 14 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue