From 7048c2ec9b48fab672fd3fed57cfa133d9057e3a Mon Sep 17 00:00:00 2001 From: ekzyis Date: Mon, 23 Sep 2024 01:10:24 +0200 Subject: [PATCH] Add mentions --- notifications.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/notifications.go b/notifications.go index 7f29e64..57015bc 100644 --- a/notifications.go +++ b/notifications.go @@ -84,3 +84,34 @@ func (c *Client) Notifications() (*NotificationsCursor, error) { } return &respBody.Data.Notifications, nil } + +func (c *Client) Mentions() ([]Notification, error) { + return c.filterNotifications( + func(n Notification) bool { + return n.Type == "Mention" + }, + ) +} + +func (c *Client) filterNotifications(f func(Notification) bool) ([]Notification, error) { + var ( + n *NotificationsCursor + err error + ) + + if n, err = c.Notifications(); err != nil { + return nil, err + } + + return filter(n.Notifications, f), nil +} + +func filter[T any](s []T, f func(T) bool) []T { + var r []T + for _, v := range s { + if f(v) { + r = append(r, v) + } + } + return r +}