ref: cceb6dcab404be1046047c4ad92c734e3b045e4c
parent: 88a203dfbf54d42f8cc7e1d5f28ec3834d8af91c
author: penny <penny@limitedideas.org>
date: Tue Sep 23 20:57:42 EDT 2025
generic array reverser
--- /dev/null
+++ b/helpers.go
@@ -1,0 +1,9 @@
+package main
+
+func reverseArray[T any](array []T) []T {+ var reversed []T
+ for i := len(array) - 1; i >= 0; i-- {+ reversed = append(reversed, array[i])
+ }
+ return reversed
+}
\ No newline at end of file
--- a/notifications.go
+++ b/notifications.go
@@ -17,10 +17,8 @@
LastID := markers["notifications"].LastID
page := &mastodon.Pagination{SinceID: LastID}- var notificationbuffer []*mastodon.Notification
-
noticeFunc := func(job *GenericJob) {- notificationbuffer, err = hc.client.GetNotificationsExclude(context.Background(), nil, page)
+ notifications, err = hc.client.GetNotificationsExclude(context.Background(), nil, page)
}
noticeJob := hc.dispatchFunc(noticeFunc)
noticeJob.Wait()
@@ -28,10 +26,8 @@
return
}
- //Reverse to print from oldest to newest
- for i := len(notificationbuffer) - 1; i >= 0; i-- {- notifications = append(notifications, notificationbuffer[i])
- }
+ notifications = reverseArray(notifications)
+
return
}
@@ -55,12 +51,12 @@
notifications = append(notifications, notification)
status := func(Notification *mastodon.Notification, plaintext string) {- notification := fmt.Sprintf("Notification [%v] from <%v>: %v\n\n", Notification.Type, Notification.Account.Acct, plaintext)+ notification := fmt.Sprintf("Notification [%s] from <%s>: %s\n\n", Notification.Type, Notification.Account.Acct, plaintext)fmt.Printf(hyphenate(notification))
}
other := func(Notification *mastodon.Notification) {- notification := fmt.Sprintf("Notification [%v] from <%v>\n\n", Notification.Type, Notification.Account.Acct)+ notification := fmt.Sprintf("Notification [%s] from <%s>\n\n", Notification.Type, Notification.Account.Acct)fmt.Printf(hyphenate(notification))
}
@@ -75,12 +71,12 @@
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)+ notification := fmt.Sprintf("[%s] from <%s>: %s\n\n", Notification.Type, Notification.Account.Acct, plaintext)sb.WriteString(hyphenate(notification))
}
other := func(Notification *mastodon.Notification) {- notification := fmt.Sprintf("[%v] from <%v>\n\n", Notification.Type, Notification.Account.Acct)+ notification := fmt.Sprintf("[%s] from <%s>\n\n", Notification.Type, Notification.Account.Acct)sb.WriteString(hyphenate(notification))
}
--- a/pages.go
+++ b/pages.go
@@ -15,12 +15,13 @@
}
type NotificationPages struct {hc *Hellclient
+ page *mastodon.Pagination
}
func (noticeData *NotificationPages) String() string {- page := &mastodon.Pagination{}- notices, err := noticeData.hc.client.GetNotifications(context.Background(), page)
+ notices, err := noticeData.hc.client.GetNotifications(context.Background(), noticeData)
+ noticeData.Limit = 5
if err != nil { fmt.Printf("Error getting notification page: %s\n", err)}
--
⑨