diff --git a/api/item.go b/api/item.go index 5360fc2..6eb4a70 100644 --- a/api/item.go +++ b/api/item.go @@ -35,6 +35,43 @@ type filtered struct { name string } +func getUrlsStatus(status *mastodon.Status) ([]util.URL, []mastodon.Mention, []mastodon.Tag, int) { + if status.Reblog != nil { + status = status.Reblog + } + _, urls := util.CleanHTML(status.Content) + if status.Sensitive { + _, u := util.CleanHTML(status.SpoilerText) + urls = append(urls, u...) + } + + realUrls := []util.URL{} + for _, url := range urls { + isNotMention := true + for _, mention := range status.Mentions { + if mention.URL == url.URL { + isNotMention = false + } + } + if isNotMention { + realUrls = append(realUrls, url) + } + } + + length := len(realUrls) + len(status.Mentions) + len(status.Tags) + return realUrls, status.Mentions, status.Tags, length +} +func getUrlsUser(user *mastodon.Account) ([]util.URL, []mastodon.Mention, []mastodon.Tag, int) { + var urls []util.URL + user.Note, urls = util.CleanHTML(user.Note) + for _, f := range user.Fields { + _, fu := util.CleanHTML(f.Value) + urls = append(urls, fu...) + } + + return urls, []mastodon.Mention{}, []mastodon.Tag{}, len(urls) +} + func NewStatusItem(item *mastodon.Status, filters []*mastodon.Filter, timeline string, pinned bool) (sitem Item) { filtered := filtered{inUse: false} if item == nil { @@ -126,31 +163,7 @@ func (s *StatusItem) Raw() interface{} { } func (s *StatusItem) URLs() ([]util.URL, []mastodon.Mention, []mastodon.Tag, int) { - status := s.item - if status.Reblog != nil { - status = status.Reblog - } - _, urls := util.CleanHTML(status.Content) - if status.Sensitive { - _, u := util.CleanHTML(status.SpoilerText) - urls = append(urls, u...) - } - - realUrls := []util.URL{} - for _, url := range urls { - isNotMention := true - for _, mention := range status.Mentions { - if mention.URL == url.URL { - isNotMention = false - } - } - if isNotMention { - realUrls = append(realUrls, url) - } - } - - length := len(realUrls) + len(status.Mentions) + len(status.Tags) - return realUrls, status.Mentions, status.Tags, length + return getUrlsStatus(s.item) } func (s *StatusItem) Filtered() (bool, string) { @@ -194,15 +207,7 @@ func (u *UserItem) Raw() interface{} { } func (u *UserItem) URLs() ([]util.URL, []mastodon.Mention, []mastodon.Tag, int) { - user := u.item.Data - var urls []util.URL - user.Note, urls = util.CleanHTML(user.Note) - for _, f := range user.Fields { - _, fu := util.CleanHTML(f.Value) - urls = append(urls, fu...) - } - - return urls, []mastodon.Mention{}, []mastodon.Tag{}, len(urls) + return getUrlsUser(u.item.Data) } func (s *UserItem) Filtered() (bool, string) { @@ -265,6 +270,23 @@ func (n *NotificationItem) Raw() interface{} { } func (n *NotificationItem) URLs() ([]util.URL, []mastodon.Mention, []mastodon.Tag, int) { + nd := n.Raw().(*NotificationData) + switch n.item.Type { + case "favourite": + return getUrlsStatus(nd.Status.Raw().(*mastodon.Status)) + case "reblog": + return getUrlsStatus(nd.Status.Raw().(*mastodon.Status)) + case "mention": + return getUrlsStatus(nd.Status.Raw().(*mastodon.Status)) + case "status": + return getUrlsStatus(nd.Status.Raw().(*mastodon.Status)) + case "poll": + return getUrlsStatus(nd.Status.Raw().(*mastodon.Status)) + case "follow": + return getUrlsUser(nd.User.Raw().(*User).Data) + case "follow_request": + return getUrlsUser(nd.User.Raw().(*User).Data) + } return nil, nil, nil, 0 } diff --git a/feed/feed.go b/feed/feed.go index 6f5c513..9351192 100644 --- a/feed/feed.go +++ b/feed/feed.go @@ -106,10 +106,13 @@ func (f *Feed) Delete(id uint) { func (f *Feed) Item(index int) (api.Item, error) { f.itemsMux.RLock() defer f.itemsMux.RUnlock() - if index < 0 || index >= len(f.items) { + if f.StickyCount() > 0 && index < f.StickyCount() { + return f.sticky[index], nil + } + if index < 0 || index >= len(f.items)+f.StickyCount() { return nil, errors.New("item out of range") } - return f.items[index], nil + return f.items[index-f.StickyCount()], nil } func (f *Feed) Updated(nt DesktopNotificationType) { diff --git a/main.go b/main.go index 28fb792..6336c2b 100644 --- a/main.go +++ b/main.go @@ -8,7 +8,7 @@ import ( "github.com/rivo/tview" ) -const version = "1.0.12" +const version = "1.0.13" func main() { util.MakeDirs()