interface FilterContent { users : string [ ] ; repos : string [ ] ; orgs : string [ ] ; } export interface NotificationFilterStateContent { filters : { [ name ] : FilterContent ; } ; forNotifications : string [ ] ; forInvites : string [ ] ; } /**
 * A notification filter is a set of keys that define what should be sent to the user.
 */ export class NotifFilter { static readonly StateType = "uk.half-shot.matrix-github.notif-filter" ; static readonly LegacyStateType = "uk.half-shot.matrix-hookshot.notif-filter" ; static getDefaultContent ( ) { return { filters : { } , forNotifications : [ ] , forInvites : [ ] , } ; } public readonly forNotifications : Set < string > ; public readonly forInvites : Set < string > ; public filters : Record < string , FilterContent > ; constructor ( stateContent ) { this . forNotifications = new Set ( stateContent . forNotifications ) ; this . forInvites = new Set ( stateContent . forInvites ) ; this . filters = stateContent . filters ; } public get empty ( ) { return Object . values ( this . filters ) . length === 0 ; } public getStateContent ( ) { return { filters : this . filters , forInvites : [ ... this . forInvites ] , forNotifications : [ ... this . forNotifications ] , } ; } public shouldInviteToRoom ( user , repo , org ) { return false ; } public shouldSendNotification ( user ? , repo ? , org ? ) { if ( this . forNotifications . size === 0 ) { return true ; } for ( const filterName of this . forNotifications ) { const filter = this . filters [ filterName ] ; if ( ! filter ) { continue ; } if ( user && filter . users . includes ( user . toLowerCase ( ) ) ) { return true ; } if ( repo && filter . repos . includes ( repo . toLowerCase ( ) ) ) { return true ; } if ( org && filter . orgs . includes ( org . toLowerCase ( ) ) ) { return true ; } return false ; } return false ; } public setFilter ( name , filter ) { this . filters [ name ] = filter ; } }