Add mentions

This commit is contained in:
ekzyis 2024-09-23 01:10:24 +02:00
parent f21145f24f
commit 7048c2ec9b
1 changed files with 31 additions and 0 deletions

View File

@ -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
}