ref: a959728f2058c24c83b69faca05ef065ca7586d5
parent: 0eed9734ac90661d40bd8bdfe2403d1349cdd256
author: penny <penny@limitedideas.org>
date: Fri Sep 12 21:11:45 EDT 2025
Tweak notifications and add a timeline marker background process
--- a/hellclient.go
+++ b/hellclient.go
@@ -133,10 +133,7 @@
return
}
if len(statuses) > 0 {- markers["home"].Timeline = "home"
- markers["home"].ID = statuses[len(statuses)-1].ID
- homemarker := markers["home"]
- hc.client.SetTimelineMarkers(context.Background(), &[]mastodon.Marker{*homemarker})+ hc.updateReadMarker(&statuses[len(statuses)-1].ID, "home")
}
for _, status := range statuses {--- a/main.go
+++ b/main.go
@@ -95,9 +95,11 @@
//Contextual commands that need to handle their own requirements
switch command {case "notice":
- notifications, _ := hc.GetUnreadNotifications()
- hc.PrintNotifications(notifications)
- err = hc.SetNotificationsRead(notifications[0].ID)
+ notifications, err := hc.GetUnreadNotifications()
+ if len(notifications) != nil {+ hc.PrintNotifications(notifications)
+ err = hc.SetNotificationsRead(notifications[0].ID)
+ }
if err != nil {fmt.Println(err)
return
--- a/mastodon.go
+++ b/mastodon.go
@@ -7,6 +7,7 @@
"log"
"net/url"
"strings"
+ "time"
"github.com/k3a/html2text"
"github.com/mattn/go-mastodon"
@@ -327,6 +328,7 @@
postref := "a"
idmap := make(map[mastodon.ID]*mastodon.Status)
+ readchan := hc.readMarkerUpdater()
// Enter a loop to continuously listen for events from the event channel.
for {@@ -343,6 +345,7 @@
defer hc.unlock()
switch post := event.(type) {case *mastodon.UpdateEvent:
+ readchan <- &post.Status.ID
if hc.isPaused {currentPostRef := postref
capturedPost := post
@@ -428,4 +431,35 @@
}()
}
}
+}
+
+// Options are home and notifications
+func (hc *Hellclient) updateReadMarker(ID *mastodon.ID, timeline string) {+ marker := &mastodon.Marker{+ Timeline: timeline,
+ ID: *ID,
+ }
+ hc.client.SetTimelineMarkers(context.Background(), &[]mastodon.Marker{*marker})+}
+
+// Periodically set the timeline read marker to the most recent status
+// Currently this will leak if a client is destroyed
+func (hc *Hellclient) readMarkerUpdater() (statuschan chan *mastodon.ID) {+ statuschan = make(chan *mastodon.ID)
+ var ID *mastodon.ID
+ var lastfire time.Time
+ go func() {+ for {+ select {+ case ID = <-statuschan:
+ continue
+ case <-time.After((time.Minute * 4) - time.Since(lastfire)):
+ lastfire = time.Now()
+ if ID != nil {+ hc.updateReadMarker(ID, "home")
+ }
+ }
+ }
+ }()
+ return
}
--- a/notifications.go
+++ b/notifications.go
@@ -15,7 +15,12 @@
LastID := markers["notifications"].LastID
page := &mastodon.Pagination{SinceID: LastID}- notifications, err = hc.client.GetNotificationsExclude(context.Background(), nil, page)
+ notificationbuffer, err := hc.client.GetNotificationsExclude(context.Background(), nil, page)
+
+ //Reverse to print from oldest to newest
+ for i := len(notificationbuffer) - 1; i >= 0; i-- {+ notifications = append(notifications, notificationbuffer[i])
+ }
return
}
--- a/references.go
+++ b/references.go
@@ -23,11 +23,13 @@
(debugMap)[debugindex] = obj
}
+// just increment a postref given a status and struct
func justIncrementPostref(ref *postref, post *mastodon.Status) {IncrementRef(ref, post)
ref.ref = IncrementString(ref.ref)
}
+// print and increment a status given a postref struct
func (hc *Hellclient) printAndIncrement(ref *postref, post *mastodon.Status) (returnPost *mastodon.Status) {returnPost = hc.printPostS(*ref, post)
IncrementRef(ref, post)
@@ -35,6 +37,7 @@
return
}
+// Saves a status when given a postref struct
func IncrementRef(ref *postref, status *mastodon.Status) {saveCustomStatusRef(ref.postmap, status, ref.ref, ref.prefix)
}
--
⑨