ref: 88a203dfbf54d42f8cc7e1d5f28ec3834d8af91c
parent: 6d79ffcc3f5cc0f7fbaa63920259e7f5ef8b2e7c
author: penny <penny@limitedideas.org>
date: Tue Sep 23 18:08:22 EDT 2025
start adding pagination support
--- a/main.go
+++ b/main.go
@@ -118,6 +118,12 @@
hc.stats.slock.Unlock()
return
case "notice":
+ noticePage := &NotificationPages{}+ noticePage.hc = hc
+
+ fmt.Printf(noticePage.String())
+ return
+ case "notice2":
notifications, err := hc.GetUnreadNotifications()
if len(notifications) > 0 {hc.PrintNotifications(notifications)
--- a/notifications.go
+++ b/notifications.go
@@ -3,6 +3,7 @@
import (
"context"
"fmt"
+ "strings"
"codeberg.org/penny64/hellclient-go-mastodon"
)
@@ -68,19 +69,24 @@
}
func (hc *Hellclient) PrintNotifications(notifications []*mastodon.Notification) {+ fmt.Print(hc.RenderNotifications(notifications))
+}
+func (hc *Hellclient) RenderNotifications(notifications []*mastodon.Notification) string {+ var sb strings.Builder
status := func(Notification *mastodon.Notification, plaintext string) { notification := fmt.Sprintf("[%v] from <%v>: %v\n\n", Notification.Type, Notification.Account.Acct, plaintext)- fmt.Printf(hyphenate(notification))
+ sb.WriteString(hyphenate(notification))
}
other := func(Notification *mastodon.Notification) { notification := fmt.Sprintf("[%v] from <%v>\n\n", Notification.Type, Notification.Account.Acct)- fmt.Printf(hyphenate(notification))
+ sb.WriteString(hyphenate(notification))
}
hc.PrintNotificationsCustom(notifications, status, other)
-
+
+ return sb.String()
}
func (hc *Hellclient) PrintNotificationsCustom(notifications []*mastodon.Notification,
--- /dev/null
+++ b/pages.go
@@ -1,0 +1,39 @@
+package main
+
+import (
+ "context"
+ "fmt"
+
+ "codeberg.org/penny64/hellclient-go-mastodon"
+)
+
+type Page interface {+ String() string
+ Next()
+ Prev()
+ Current() int64
+}
+type NotificationPages struct {+ hc *Hellclient
+}
+
+func (noticeData *NotificationPages) String() string {+ page := &mastodon.Pagination{}+ notices, err := noticeData.hc.client.GetNotifications(context.Background(), page)
+
+ if err != nil {+ fmt.Printf("Error getting notification page: %s\n", err)+ }
+
+ return noticeData.hc.RenderNotifications(notices)
+}
+
+func (noticeData *NotificationPages) Next() {+}
+
+func (noticeData *NotificationPages) Prev() {+}
+
+func (noticeData *NotificationPages) Current() int64 {+ return 0
+}
--
⑨