shithub: hell

Download patch

ref: 669115f1219e7ba31100740ad6dbe3e14a6667e7
parent: 6bc49eaa4e79a09e0adf12006162374b3fc48c62
author: penny <penny@limitedideas.org>
date: Wed Sep 3 22:58:58 EDT 2025

Streaming uses notification printing functions

--- a/hellclient.go
+++ b/hellclient.go
@@ -37,6 +37,7 @@
 	//Global status map for status indexes
 	//Needs to be converted to a postref struct
 	homeMap map[string]*mastodon.Status
+	homeref      *postref
 	//Contextual indexes for commands
 	ctxref       *postref
 	urlMap       map[string][]string
@@ -80,6 +81,12 @@
 		ref:     "a",
 		postmap: homeMap,
 	}
+	
+	homeref := &postref{
+		ref:     "a",
+		postmap: homeMap,
+	}
+	
 	debugMap := make(map[string]interface{})
 	urlMap := make(map[string][]string)
 	prefs := &Hellprefs{apidelay: time.Second * 3}
@@ -86,6 +93,7 @@
 	hc = Hellclient{rl: rl,
 		homeMap:     homeMap,
 		ctxref:      ctxref,
+		homeref:     homeref,
 		debugMap:    debugMap,
 		isPaused:    false,
 		urlMap:      urlMap,
--- a/mastodon.go
+++ b/mastodon.go
@@ -382,25 +382,23 @@
 					return
 
 				case *mastodon.NotificationEvent:
+					hc.updatePrompt()
 					if post.Notification.Status == nil {
-						notification := fmt.Sprintf("Notification [%v] from <%v>\n", post.Notification.Type, post.Notification.Account.Acct)
 						if hc.isPaused {
 							hc.actionBuffer = append(hc.actionBuffer, func() {
-								fmt.Printf(hyphenate(notification))
+								hc.PrintReceivedNotification(post.Notification)
 							})
 						} else {
-							fmt.Printf(hyphenate(notification))
+							hc.PrintReceivedNotification(post.Notification)
 						}
 						return
 					}
-					_, plaintext = hc.RenderPostPlaintext(post.Notification.Status, postref, "")
-					notification := fmt.Sprintf("Notification [%v] from <%v>: %v\n", post.Notification.Type, post.Notification.Account.Acct, plaintext)
 					if hc.isPaused {
 						hc.actionBuffer = append(hc.actionBuffer, func() {
-							fmt.Printf(hyphenate(notification))
+							hc.PrintReceivedNotification(post.Notification)
 						})
 					} else {
-						fmt.Printf(hyphenate(notification))
+						hc.PrintReceivedNotification(post.Notification)
 					}
 					saveRef(postMap, post.Notification.Status, postref)
 					postref = IncrementString(postref)
--- a/notifications.go
+++ b/notifications.go
@@ -2,6 +2,7 @@
 
 import (
 	"context"
+	"fmt"
 
 	"github.com/mattn/go-mastodon"
 )
@@ -13,19 +14,59 @@
 	}
 
 	LastID := markers["notifications"].LastID
-
 	page := &mastodon.Pagination{SinceID: LastID}
-
 	notifications, err = hc.client.GetNotificationsExclude(context.Background(), nil, page)
-
 	return
 }
 
+func (hc *Hellclient) PrintReceivedNotification(notification *mastodon.Notification) {
+	var notifications []*mastodon.Notification
+	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)
+		fmt.Printf(hyphenate(notification))
+	}
+
+	other := func(Notification *mastodon.Notification) {
+		notification := fmt.Sprintf("Notification [%v] from <%v>\n\n", Notification.Type, Notification.Account.Acct)
+		fmt.Printf(hyphenate(notification))
+	}
+
+	hc.PrintNotificationsCustom(notifications, status, other)
+
+}
+
 func (hc *Hellclient) PrintNotifications(notifications []*mastodon.Notification) {
 
-	for _, notification := range notifications {
-		PrintObjectProperties(notification, hc.debugMap)
+	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))
 	}
 
-	return
+	other := func(Notification *mastodon.Notification) {
+		notification := fmt.Sprintf("[%v] from <%v>\n\n", Notification.Type, Notification.Account.Acct)
+		fmt.Printf(hyphenate(notification))
+	}
+
+	hc.PrintNotificationsCustom(notifications, status, other)
+
+}
+
+func (hc *Hellclient) PrintNotificationsCustom(notifications []*mastodon.Notification,
+	printstatus func(*mastodon.Notification, string),
+	printother func(*mastodon.Notification)) {
+	for _, Notification := range notifications {
+		if Notification.Status == nil {
+			printother(Notification)
+			continue
+		}
+
+		_, plaintext := hc.RenderPostPlaintext(Notification.Status, hc.ctxref.ref, "")
+		printstatus(Notification, plaintext)
+
+		saveRef(hc.ctxref.postmap, Notification.Status, hc.ctxref.ref)
+		hc.ctxref.ref = IncrementString(hc.ctxref.ref)
+		continue
+	}
 }
--