11import type { SettingsState } from '../../../types' ;
2- import type { Notification , StateType } from '../../../typesGitHub' ;
2+ import type {
3+ Notification ,
4+ StateType ,
5+ SubjectUser ,
6+ } from '../../../typesGitHub' ;
37import {
48 filterNotificationByHandle ,
59 hasExcludeHandleFilters ,
@@ -45,29 +49,8 @@ export function filterDetailedNotifications(
4549 let passesFilters = true ;
4650
4751 if ( settings . detailedNotifications ) {
48- if ( userTypeFilter . hasFilters ( settings ) ) {
49- passesFilters =
50- passesFilters &&
51- settings . filterUserTypes . some ( ( userType ) =>
52- userTypeFilter . filterNotification ( notification , userType ) ,
53- ) ;
54- }
55-
56- if ( hasIncludeHandleFilters ( settings ) ) {
57- passesFilters =
58- passesFilters &&
59- settings . filterIncludeHandles . some ( ( handle ) =>
60- filterNotificationByHandle ( notification , handle ) ,
61- ) ;
62- }
63-
64- if ( hasExcludeHandleFilters ( settings ) ) {
65- passesFilters =
66- passesFilters &&
67- ! settings . filterExcludeHandles . some ( ( handle ) =>
68- filterNotificationByHandle ( notification , handle ) ,
69- ) ;
70- }
52+ passesFilters =
53+ passesFilters && passesUserFilters ( notification , settings ) ;
7154
7255 passesFilters =
7356 passesFilters && passesStateFilter ( notification , settings ) ;
@@ -88,6 +71,39 @@ export function hasAnyFiltersSet(settings: SettingsState): boolean {
8871 ) ;
8972}
9073
74+ function passesUserFilters (
75+ notification : Notification ,
76+ settings : SettingsState ,
77+ ) : boolean {
78+ let passesFilters = true ;
79+
80+ if ( userTypeFilter . hasFilters ( settings ) ) {
81+ passesFilters =
82+ passesFilters &&
83+ settings . filterUserTypes . some ( ( userType ) =>
84+ userTypeFilter . filterNotification ( notification , userType ) ,
85+ ) ;
86+ }
87+
88+ if ( hasIncludeHandleFilters ( settings ) ) {
89+ passesFilters =
90+ passesFilters &&
91+ settings . filterIncludeHandles . some ( ( handle ) =>
92+ filterNotificationByHandle ( notification , handle ) ,
93+ ) ;
94+ }
95+
96+ if ( hasExcludeHandleFilters ( settings ) ) {
97+ passesFilters =
98+ passesFilters &&
99+ ! settings . filterExcludeHandles . some ( ( handle ) =>
100+ filterNotificationByHandle ( notification , handle ) ,
101+ ) ;
102+ }
103+
104+ return passesFilters ;
105+ }
106+
91107function passesStateFilter (
92108 notification : Notification ,
93109 settings : SettingsState ,
@@ -105,7 +121,16 @@ export function isStateFilteredOut(
105121 state : StateType ,
106122 settings : SettingsState ,
107123) : boolean {
108- const notification = { subject : { state } } as Notification ;
124+ const notification = { subject : { state : state } } as Notification ;
109125
110126 return ! passesStateFilter ( notification , settings ) ;
111127}
128+
129+ export function isUserFilteredOut (
130+ user : SubjectUser ,
131+ settings : SettingsState ,
132+ ) : boolean {
133+ const notification = { subject : { user : user } } as Notification ;
134+
135+ return ! passesUserFilters ( notification , settings ) ;
136+ }
0 commit comments