|
|
|
|
@ -17,6 +17,7 @@ type apiIDFunc func(pg *mastodon.Pagination, id mastodon.ID) ([]api.Item, error)
|
|
|
|
|
type apiSearchFunc func(search string) ([]api.Item, error) |
|
|
|
|
type apiSearchPGFunc func(pg *mastodon.Pagination, search string) ([]api.Item, error) |
|
|
|
|
type apiThreadFunc func(status *mastodon.Status) ([]api.Item, error) |
|
|
|
|
type apiHistoryFunc func(status *mastodon.Status) ([]api.Item, error) |
|
|
|
|
|
|
|
|
|
type FeedType uint |
|
|
|
|
|
|
|
|
|
@ -29,6 +30,7 @@ const (
|
|
|
|
|
FollowRequests |
|
|
|
|
Blocking |
|
|
|
|
Muting |
|
|
|
|
History |
|
|
|
|
InvalidFeed |
|
|
|
|
Notification |
|
|
|
|
Saved |
|
|
|
|
@ -52,10 +54,11 @@ type LoadingLock struct {
|
|
|
|
|
type DesktopNotificationType uint |
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
|
DekstopNotificationNone DesktopNotificationType = iota |
|
|
|
|
DeskstopNotificationNone DesktopNotificationType = iota |
|
|
|
|
DesktopNotificationFollower |
|
|
|
|
DesktopNotificationFavorite |
|
|
|
|
DesktopNotificationMention |
|
|
|
|
DesktopNotificationUpdate |
|
|
|
|
DesktopNotificationBoost |
|
|
|
|
DesktopNotificationPoll |
|
|
|
|
DesktopNotificationPost |
|
|
|
|
@ -100,14 +103,14 @@ func (f *Feed) Delete(id uint) {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
f.items = items |
|
|
|
|
f.Updated(DekstopNotificationNone) |
|
|
|
|
f.Updated(DeskstopNotificationNone) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (f *Feed) Clear() { |
|
|
|
|
f.itemsMux.Lock() |
|
|
|
|
defer f.itemsMux.Unlock() |
|
|
|
|
f.items = []api.Item{} |
|
|
|
|
f.Updated(DekstopNotificationNone) |
|
|
|
|
f.Updated(DeskstopNotificationNone) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (f *Feed) Item(index int) (api.Item, error) { |
|
|
|
|
@ -142,7 +145,7 @@ func (f *Feed) LoadNewer() {
|
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
f.loadNewer() |
|
|
|
|
f.Updated(DekstopNotificationNone) |
|
|
|
|
f.Updated(DeskstopNotificationNone) |
|
|
|
|
f.loadingNewer.last = time.Now() |
|
|
|
|
f.loadingNewer.mux.Unlock() |
|
|
|
|
} |
|
|
|
|
@ -160,7 +163,7 @@ func (f *Feed) LoadOlder() {
|
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
f.loadOlder() |
|
|
|
|
f.Updated(DekstopNotificationNone) |
|
|
|
|
f.Updated(DeskstopNotificationNone) |
|
|
|
|
f.loadingOlder.last = time.Now() |
|
|
|
|
f.loadingOlder.mux.Unlock() |
|
|
|
|
} |
|
|
|
|
@ -191,7 +194,7 @@ func (f *Feed) singleNewerSearch(fn apiSearchFunc, search string) {
|
|
|
|
|
f.itemsMux.Lock() |
|
|
|
|
if len(items) > 0 { |
|
|
|
|
f.items = append(items, f.items...) |
|
|
|
|
f.Updated(DekstopNotificationNone) |
|
|
|
|
f.Updated(DeskstopNotificationNone) |
|
|
|
|
} |
|
|
|
|
f.itemsMux.Unlock() |
|
|
|
|
} |
|
|
|
|
@ -204,7 +207,20 @@ func (f *Feed) singleThread(fn apiThreadFunc, status *mastodon.Status) {
|
|
|
|
|
f.itemsMux.Lock() |
|
|
|
|
if len(items) > 0 { |
|
|
|
|
f.items = append(items, f.items...) |
|
|
|
|
f.Updated(DekstopNotificationNone) |
|
|
|
|
f.Updated(DeskstopNotificationNone) |
|
|
|
|
} |
|
|
|
|
f.itemsMux.Unlock() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (f *Feed) singleHistory(fn apiHistoryFunc, status *mastodon.Status) { |
|
|
|
|
items, err := fn(status) |
|
|
|
|
if err != nil { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
f.itemsMux.Lock() |
|
|
|
|
if len(items) > 0 { |
|
|
|
|
f.items = append(items, f.items...) |
|
|
|
|
f.Updated(DeskstopNotificationNone) |
|
|
|
|
} |
|
|
|
|
f.itemsMux.Unlock() |
|
|
|
|
} |
|
|
|
|
@ -237,7 +253,7 @@ func (f *Feed) normalNewer(fn apiFunc) {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
f.items = append(items, f.items...) |
|
|
|
|
f.Updated(DekstopNotificationNone) |
|
|
|
|
f.Updated(DeskstopNotificationNone) |
|
|
|
|
} |
|
|
|
|
f.itemsMux.Unlock() |
|
|
|
|
f.apiDataMux.Unlock() |
|
|
|
|
@ -266,7 +282,7 @@ func (f *Feed) normalOlder(fn apiFunc) {
|
|
|
|
|
f.apiData.MaxID = item.Item.ID |
|
|
|
|
} |
|
|
|
|
f.items = append(f.items, items...) |
|
|
|
|
f.Updated(DekstopNotificationNone) |
|
|
|
|
f.Updated(DeskstopNotificationNone) |
|
|
|
|
} |
|
|
|
|
f.itemsMux.Unlock() |
|
|
|
|
f.apiDataMux.Unlock() |
|
|
|
|
@ -288,7 +304,7 @@ func (f *Feed) newerSearchPG(fn apiSearchPGFunc, search string) {
|
|
|
|
|
item := items[0].Raw().(*mastodon.Status) |
|
|
|
|
f.apiData.MinID = item.ID |
|
|
|
|
f.items = append(items, f.items...) |
|
|
|
|
f.Updated(DekstopNotificationNone) |
|
|
|
|
f.Updated(DeskstopNotificationNone) |
|
|
|
|
if f.apiData.MaxID == mastodon.ID("") { |
|
|
|
|
item = items[len(items)-1].Raw().(*mastodon.Status) |
|
|
|
|
f.apiData.MaxID = item.ID |
|
|
|
|
@ -317,7 +333,7 @@ func (f *Feed) olderSearchPG(fn apiSearchPGFunc, search string) {
|
|
|
|
|
item := items[len(items)-1].Raw().(*mastodon.Status) |
|
|
|
|
f.apiData.MaxID = item.ID |
|
|
|
|
f.items = append(f.items, items...) |
|
|
|
|
f.Updated(DekstopNotificationNone) |
|
|
|
|
f.Updated(DeskstopNotificationNone) |
|
|
|
|
} |
|
|
|
|
f.itemsMux.Unlock() |
|
|
|
|
f.apiDataMux.Unlock() |
|
|
|
|
@ -339,7 +355,7 @@ func (f *Feed) normalNewerUser(fn apiIDFunc, id mastodon.ID) {
|
|
|
|
|
item := items[0].Raw().(*mastodon.Status) |
|
|
|
|
f.apiData.MinID = item.ID |
|
|
|
|
f.items = append(items, f.items...) |
|
|
|
|
f.Updated(DekstopNotificationNone) |
|
|
|
|
f.Updated(DeskstopNotificationNone) |
|
|
|
|
if f.apiData.MaxID == mastodon.ID("") { |
|
|
|
|
item = items[len(items)-1].Raw().(*mastodon.Status) |
|
|
|
|
f.apiData.MaxID = item.ID |
|
|
|
|
@ -368,7 +384,7 @@ func (f *Feed) normalOlderUser(fn apiIDFunc, id mastodon.ID) {
|
|
|
|
|
item := items[len(items)-1].Raw().(*mastodon.Status) |
|
|
|
|
f.apiData.MaxID = item.ID |
|
|
|
|
f.items = append(f.items, items...) |
|
|
|
|
f.Updated(DekstopNotificationNone) |
|
|
|
|
f.Updated(DeskstopNotificationNone) |
|
|
|
|
} |
|
|
|
|
f.itemsMux.Unlock() |
|
|
|
|
f.apiDataMux.Unlock() |
|
|
|
|
@ -390,7 +406,7 @@ func (f *Feed) normalNewerID(fn apiIDFunc, id mastodon.ID) {
|
|
|
|
|
item := items[0].Raw().(*mastodon.Status) |
|
|
|
|
f.apiData.MinID = item.ID |
|
|
|
|
f.items = append(items, f.items...) |
|
|
|
|
f.Updated(DekstopNotificationNone) |
|
|
|
|
f.Updated(DeskstopNotificationNone) |
|
|
|
|
if f.apiData.MaxID == mastodon.ID("") { |
|
|
|
|
item = items[len(items)-1].Raw().(*mastodon.Status) |
|
|
|
|
f.apiData.MaxID = item.ID |
|
|
|
|
@ -419,7 +435,7 @@ func (f *Feed) normalOlderID(fn apiIDFunc, id mastodon.ID) {
|
|
|
|
|
item := items[len(items)-1].Raw().(*mastodon.Status) |
|
|
|
|
f.apiData.MaxID = item.ID |
|
|
|
|
f.items = append(f.items, items...) |
|
|
|
|
f.Updated(DekstopNotificationNone) |
|
|
|
|
f.Updated(DeskstopNotificationNone) |
|
|
|
|
} |
|
|
|
|
f.itemsMux.Unlock() |
|
|
|
|
f.apiDataMux.Unlock() |
|
|
|
|
@ -433,7 +449,7 @@ func (f *Feed) normalEmpty(fn apiEmptyFunc) {
|
|
|
|
|
f.itemsMux.Lock() |
|
|
|
|
if len(items) > 0 { |
|
|
|
|
f.items = append(f.items, items...) |
|
|
|
|
f.Updated(DekstopNotificationNone) |
|
|
|
|
f.Updated(DeskstopNotificationNone) |
|
|
|
|
} |
|
|
|
|
f.itemsMux.Unlock() |
|
|
|
|
} |
|
|
|
|
@ -459,7 +475,7 @@ func (f *Feed) linkNewer(fn apiFunc) {
|
|
|
|
|
f.itemsMux.Lock() |
|
|
|
|
if len(items) > 0 { |
|
|
|
|
f.items = append(items, f.items...) |
|
|
|
|
f.Updated(DekstopNotificationNone) |
|
|
|
|
f.Updated(DeskstopNotificationNone) |
|
|
|
|
} |
|
|
|
|
f.itemsMux.Unlock() |
|
|
|
|
} |
|
|
|
|
@ -484,7 +500,7 @@ func (f *Feed) linkOlder(fn apiFunc) {
|
|
|
|
|
f.itemsMux.Lock() |
|
|
|
|
if len(items) > 0 { |
|
|
|
|
f.items = append(f.items, items...) |
|
|
|
|
f.Updated(DekstopNotificationNone) |
|
|
|
|
f.Updated(DeskstopNotificationNone) |
|
|
|
|
} |
|
|
|
|
f.itemsMux.Unlock() |
|
|
|
|
} |
|
|
|
|
@ -510,7 +526,7 @@ func (f *Feed) linkNewerID(fn apiIDFunc, id mastodon.ID) {
|
|
|
|
|
f.itemsMux.Lock() |
|
|
|
|
if len(items) > 0 { |
|
|
|
|
f.items = append(items, f.items...) |
|
|
|
|
f.Updated(DekstopNotificationNone) |
|
|
|
|
f.Updated(DeskstopNotificationNone) |
|
|
|
|
} |
|
|
|
|
f.itemsMux.Unlock() |
|
|
|
|
} |
|
|
|
|
@ -535,7 +551,7 @@ func (f *Feed) linkOlderID(fn apiIDFunc, id mastodon.ID) {
|
|
|
|
|
f.itemsMux.Lock() |
|
|
|
|
if len(items) > 0 { |
|
|
|
|
f.items = append(f.items, items...) |
|
|
|
|
f.Updated(DekstopNotificationNone) |
|
|
|
|
f.Updated(DeskstopNotificationNone) |
|
|
|
|
} |
|
|
|
|
f.itemsMux.Unlock() |
|
|
|
|
} |
|
|
|
|
@ -584,7 +600,7 @@ func (f *Feed) startStreamNotification(rec *api.Receiver, timeline string, err e
|
|
|
|
|
}, f.accountClient.Filters) |
|
|
|
|
f.itemsMux.Lock() |
|
|
|
|
f.items = append([]api.Item{s}, f.items...) |
|
|
|
|
nft := DekstopNotificationNone |
|
|
|
|
nft := DeskstopNotificationNone |
|
|
|
|
switch t.Notification.Type { |
|
|
|
|
case "follow", "follow_request": |
|
|
|
|
nft = DesktopNotificationFollower |
|
|
|
|
@ -594,10 +610,14 @@ func (f *Feed) startStreamNotification(rec *api.Receiver, timeline string, err e
|
|
|
|
|
nft = DesktopNotificationBoost |
|
|
|
|
case "mention": |
|
|
|
|
nft = DesktopNotificationMention |
|
|
|
|
case "update": |
|
|
|
|
nft = DesktopNotificationUpdate |
|
|
|
|
case "status": |
|
|
|
|
nft = DesktopNotificationPost |
|
|
|
|
case "poll": |
|
|
|
|
nft = DesktopNotificationPoll |
|
|
|
|
default: |
|
|
|
|
nft = DeskstopNotificationNone |
|
|
|
|
} |
|
|
|
|
f.Updated(nft) |
|
|
|
|
f.itemsMux.Unlock() |
|
|
|
|
@ -716,6 +736,18 @@ func NewThread(ac *api.AccountClient, status *mastodon.Status) *Feed {
|
|
|
|
|
return feed |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func NewHistory(ac *api.AccountClient, status *mastodon.Status) *Feed { |
|
|
|
|
feed := newFeed(ac, History) |
|
|
|
|
once := true |
|
|
|
|
feed.loadNewer = func() { |
|
|
|
|
if once { |
|
|
|
|
feed.singleHistory(feed.accountClient.GetHistory, status) |
|
|
|
|
once = false |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return feed |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func NewTag(ac *api.AccountClient, search string) *Feed { |
|
|
|
|
feed := newFeed(ac, Tag) |
|
|
|
|
feed.name = search |
|
|
|
|
|