feat: filter notifications by type (#2371)

Co-authored-by: Xabi <xabi.rn@gmail.com>
Co-authored-by: userquin <userquin@gmail.com>
This commit is contained in:
Ayo Ayco 2023-09-06 11:13:16 +02:00 committed by GitHub
parent e9c5de577e
commit 907d9999dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 171 additions and 31 deletions

View file

@ -0,0 +1,20 @@
import type { mastodon } from 'masto'
import { NOTIFICATION_FILTER_TYPES } from '~/constants'
/**
* Typeguard to check if an object is a valid notification filter
* @param obj the object to be checked
* @returns boolean and assigns type to object if true
*/
export function isNotificationFilter(obj: unknown): obj is mastodon.v1.NotificationType {
return !!obj && NOTIFICATION_FILTER_TYPES.includes(obj as unknown as mastodon.v1.NotificationType)
}
/**
* Typeguard to check if an object is a valid notification
* @param obj the object to be checked
* @returns boolean and assigns type to object if true
*/
export function isNotification(obj: unknown): obj is mastodon.v1.NotificationType {
return !!obj && ['mention', ...NOTIFICATION_FILTER_TYPES].includes(obj as unknown as mastodon.v1.NotificationType)
}