Add mentions
This commit is contained in:
parent
f21145f24f
commit
7048c2ec9b
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue