shithub: hell

Download patch

ref: 046bf407f6bc4ea1d4b35ebbcd449fd493d292c4
parent: a959728f2058c24c83b69faca05ef065ca7586d5
author: penny <penny@limitedideas.org>
date: Fri Sep 12 21:44:01 EDT 2025

Convert timeline stream to use post reference struct

--- a/main.go
+++ b/main.go
@@ -96,7 +96,7 @@
 			switch command {
 			case "notice":
 				notifications, err := hc.GetUnreadNotifications()
-				if len(notifications) != nil {
+				if len(notifications) > 0 {
 					hc.PrintNotifications(notifications)
 					err = hc.SetNotificationsRead(notifications[0].ID)
 				}
--- a/mastodon.go
+++ b/mastodon.go
@@ -326,7 +326,6 @@
 
 	initReferenceSystem()
 
-	postref := "a"
 	idmap := make(map[mastodon.ID]*mastodon.Status)
 	readchan := hc.readMarkerUpdater()
 
@@ -347,31 +346,33 @@
 				case *mastodon.UpdateEvent:
 					readchan <- &post.Status.ID
 					if hc.isPaused {
-						currentPostRef := postref
+						currentPostRef := hc.homeref.ref
 						capturedPost := post
 						hc.actionBuffer = append(hc.actionBuffer, func() {
 							capturedPost.Status = hc.printPost(currentPostRef, capturedPost.Status)
 						})
-					} else {
-						post.Status = hc.printPost(postref, post.Status)
+						justIncrementPostref(hc.homeref, post.Status)
+						idmap[post.Status.ID] = post.Status
+						return
 					}
-					saveRef(postMap, post.Status, postref)
+					hc.printAndIncrement(hc.homeref, post.Status)
 					idmap[post.Status.ID] = post.Status
-					postref = IncrementString(postref)
+					return
 
 				case *mastodon.UpdateEditEvent:
 					if hc.isPaused {
-						currentPostRef := postref
+						currentPostRef := hc.homeref.ref
 						capturedPost := post
 						hc.actionBuffer = append(hc.actionBuffer, func() {
 							fmt.Println(hc.formatEdit(capturedPost.Status, currentPostRef))
 						})
-					} else {
-						fmt.Println(hc.formatEdit(post.Status, postref))
+						justIncrementPostref(hc.homeref, post.Status)
+						idmap[post.Status.ID] = post.Status
+						return
 					}
-					saveRef(postMap, post.Status, postref)
-					postref = IncrementString(postref)
+					printAndIncrementDetailed(hc.homeref, post.Status, hc.formatEdit)
 					idmap[post.Status.ID] = post.Status
+					return
 
 				case *mastodon.DeleteEvent:
 					deleted, ok := idmap[post.ID]
@@ -415,8 +416,7 @@
 					} else {
 						hc.PrintReceivedNotification(post.Notification)
 					}
-					saveRef(postMap, post.Notification.Status, postref)
-					postref = IncrementString(postref)
+					justIncrementPostref(hc.homeref, post.Notification.Status)
 				default:
 					// Catch any other unexpected event types.
 					unhandledEvent := event
--- a/references.go
+++ b/references.go
@@ -2,6 +2,7 @@
 
 import (
 	"strings"
+	"fmt"
 
 	"github.com/mattn/go-mastodon"
 )
@@ -35,6 +36,12 @@
 	IncrementRef(ref, post)
 	ref.ref = IncrementString(ref.ref)
 	return
+}
+
+func printAndIncrementDetailed(ref *postref, post *mastodon.Status, format func(*mastodon.Status, string) string) {
+	fmt.Println(format(post, ref.ref))
+	IncrementRef(ref, post)
+	ref.ref = IncrementString(ref.ref)
 }
 
 // Saves a status when given a postref struct
--