ref: 616c1ea077acf6a117643997ab6354ba0fcdc537
parent: 70ed46bbc94c298e09c239ba90372dd55af23f0e
author: penny <penny@limitedideas.org>
date: Fri Sep 26 18:13:04 EDT 2025
convert thread command to use a page
--- a/main.go
+++ b/main.go
@@ -331,21 +331,11 @@
}
case "thread":
- context, err := client.GetStatusContext(context.Background(), postItem.ID)
- if err != nil {- fmt.Println(err)
- return
- }
- hc.pause(true) // pause so user can read the thread
- for post := range context.Ancestors {- hc.printAndIncrement(hc.ctxref, context.Ancestors[post])
- }
-
- hc.printPost(index, postItem)
-
- for post := range context.Descendants {- hc.printAndIncrement(hc.ctxref, context.Descendants[post])
- }
+ hc.pause(true)
+ hc.page = &Page{}+ getter := &ThreadStatusGetter{target: postItem, client: hc.client}+ hc.page.loader = &StatusPages{hc: hc, getter: getter}+ fmt.Print(hc.page.String())
return
case "account":
var account *mastodon.Account
--- a/notifications.go
+++ b/notifications.go
@@ -51,12 +51,12 @@
notifications = append(notifications, notification)
status := func(Notification *mastodon.Notification, plaintext string) {- notification := fmt.Sprintf("Notification [%s] from <%s>: %s\n", Notification.Type, Notification.Account.Acct, plaintext)+ notification := fmt.Sprintf("Notification [%s] from <%s>: %s", Notification.Type, Notification.Account.Acct, plaintext)fmt.Println(hyphenate(notification))
}
other := func(Notification *mastodon.Notification) {- notification := fmt.Sprintf("Notification [%s] from <%s>\n", Notification.Type, Notification.Account.Acct)+ notification := fmt.Sprintf("Notification [%s] from <%s>", Notification.Type, Notification.Account.Acct)fmt.Println(hyphenate(notification))
}
--- a/pages.go
+++ b/pages.go
@@ -22,31 +22,56 @@
page *mastodon.Pagination
}
-type AccountStatusGetter struct {- page *mastodon.Pagination
- ID mastodon.ID
+type ThreadStatusGetter struct {+ target *mastodon.Status
client *mastodon.Client
+ loaded bool
}
-func (getter *AccountStatusGetter) Get(limit int) ([]*mastodon.Status, error) {+//The API doesn't take a limit for this so we ignore the limit
+func (getter *ThreadStatusGetter) Get(limit int) ([]*mastodon.Status, error) {+ if getter.loaded {+ return nil, nil
+ }
+ getter.loaded = true
+ context, err := getter.client.GetStatusContext(context.Background(), getter.target.ID)
+ var statuses []*mastodon.Status
+ for _, post := range context.Descendants {+ statuses = append(statuses, post)
+ }
+ statuses = append(statuses, getter.target)
+ for _, post := range context.Ancestors {+ statuses = append(statuses, post)
+ }
+ return statuses, err
+}
+
+func (getter *BasicStatusGetter) Get(limit int) ([]*mastodon.Status, error) { if getter.page == nil { getter.page = &mastodon.Pagination{}}
getter.page.Limit = int64(limit)
- statuses, err := getter.client.GetAccountStatuses(context.Background(), getter.ID, getter.page)
+ statuses, err := getter.getter(context.Background(), getter.page)
getter.page.MinID = ""
return statuses, err
}
-func (getter *BasicStatusGetter) Get(limit int) ([]*mastodon.Status, error) {+type AccountStatusGetter struct {+ page *mastodon.Pagination
+ ID mastodon.ID
+ client *mastodon.Client
+}
+
+func (getter *AccountStatusGetter) Get(limit int) ([]*mastodon.Status, error) { if getter.page == nil { getter.page = &mastodon.Pagination{}}
getter.page.Limit = int64(limit)
- statuses, err := getter.getter(context.Background(), getter.page)
+ statuses, err := getter.client.GetAccountStatuses(context.Background(), getter.ID, getter.page)
getter.page.MinID = ""
return statuses, err
}
+
type Page struct {loader StatusLoader
--
⑨