shithub: hell

Download patch

ref: da1d839c6298789a515737419fb05e9bd62f2bef
parent: 1823d7ad99fdd2decf2c264b62b3e2e18e4e5dc7
author: penny <penny@limitedideas.org>
date: Tue Oct 7 16:54:34 EDT 2025

port notification rendering to line templates

--- a/notifications.go
+++ b/notifications.go
@@ -37,7 +37,6 @@
 	if err != nil {
 		return
 	}
-
 	marker := markers["notifications"]
 	marker.ID = ID
 	marker.Timeline = "notifications"
@@ -49,19 +48,8 @@
 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 [%s] from <%s>: %s\n", Notification.Type, Notification.Account.Acct, plaintext)
-		fmt.Print(notification)
-	}
-
-	other := func(Notification *mastodon.Notification) {
-		notification := fmt.Sprintf("Notification [%s] from <%s>\n", Notification.Type, Notification.Account.Acct)
-		fmt.Print(notification)
-	}
-
-	hc.PrintNotificationsCustom(notifications, status, other)
-
+	plaintexts := hc.RenderNotificationsArray(notifications)
+	fmt.Print(plaintexts[0])
 }
 
 func (hc *Hellclient) PrintNotifications(notifications []*mastodon.Notification) {
@@ -70,18 +58,20 @@
 
 func (hc *Hellclient) RenderNotificationsArray(notifications []*mastodon.Notification) []string {
 	var noticeTexts []string
-	status := func(Notification *mastodon.Notification, plaintext string) {
-		notification := fmt.Sprintf("[%s] from <%s>: %s", Notification.Type, Notification.Account.Acct, plaintext)
-		noticeTexts = append(noticeTexts, notification)
+	formatter := &StatusFormatter{hc: hc, postContext: hc.ctxref}
+	templater := newStatusTemplateRenderer(formatter)
+	for item := range notifications {
+		formatter.notif = notifications[item]
+		if formatter.notif.Status != nil {
+			formatter.status = formatter.notif.Status
+			line, _ := templater.render("$status_notif")
+			noticeTexts = append(noticeTexts, line)
+			justIncrementPostref(hc.ctxref, formatter.status)
+			continue
+		}
+		line, _ := templater.render("$other_notif")
+		noticeTexts = append(noticeTexts, line)
 	}
-
-	other := func(Notification *mastodon.Notification) {
-		notification := fmt.Sprintf("[%s] from <%s>", Notification.Type, Notification.Account.Acct)
-		noticeTexts = append(noticeTexts, notification)
-	}
-
-	hc.PrintNotificationsCustom(notifications, status, other)
-
 	return noticeTexts
 }
 
@@ -92,22 +82,4 @@
 		sb.WriteString(text)
 	}
 	return sb.String()
-}
-
-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)
-		printstatus(Notification, plaintext)
-
-		saveRef(hc.ctxref.postmap, Notification.Status, hc.ctxref)
-		hc.ctxref.ref = IncrementString(hc.ctxref.ref)
-		continue
-	}
 }
--- a/templater.go
+++ b/templater.go
@@ -35,6 +35,8 @@
 	// macro templates
 	template.tempdefs = append(template.tempdefs, []*templateDefs{
 		{key: "standard_status", stringer: &standardStatus{template}},
+		{key: "status_notif", stringer: &statusNotification{template}},
+		{key: "other_notif", stringer: &otherNotification{template}},
 	}...)
 	return template
 }
@@ -72,12 +74,21 @@
 	return line
 }
 
-// Renders a standard notification line
-type standardNotification struct {
+// Renders a status notification line
+type statusNotification struct {
 	*templateRenderer
 }
 
-func (sn *standardNotification) String() string {
-	line, _ := sn.renderRaw("$notif_user $notif_type $standard_status")
+func (sn *statusNotification) String() string {
+	line, _ := sn.renderRaw("$notif_type from $notif_user: $standard_status")
+	return line
+}
+
+type otherNotification struct {
+	*templateRenderer
+}
+
+func (on *otherNotification) String() string {
+	line, _ := on.renderRaw("$notif_type from $notif_user")
 	return line
 }
--