shithub: hell

Download patch

ref: 0337b9f6b26328acb220bba9f9e68a1c8f19d5f8
parent: 32956bab7e8c63735cc6a36ab2f8ce5e7997003b
author: penny <penny@limitedideas.org>
date: Sun Oct 5 14:19:42 EDT 2025

initial work moving to templates

--- a/mastodon.go
+++ b/mastodon.go
@@ -246,30 +246,18 @@
 	return hyphenate(plaintext)
 }
 
-func (hc *Hellclient) RenderPostPlaintext(post *mastodon.Status, postref string, prefix string) (selectedPost *mastodon.Status, plaintext string) {
-	poststring := ""
-	postfix := ""
-	var media []mastodon.Attachment
+func (hc *Hellclient) RenderPostPlaintext(post *mastodon.Status, ref postref, prefix string) (selectedPost *mastodon.Status, plaintext string) {
 	if post.Reblog != nil {
-		poststring = hc.formatReblog(post, postref)
 		selectedPost = post.Reblog
-		media = post.Reblog.MediaAttachments
+		plaintext = fmt.Sprintf("$username Reblogged %s> $boostuser $boostcontent $boosted_media_descriptions", ref.ref)
 	} else {
-		poststring = hc.formatStatusDetailed(post, postref, prefix)
 		selectedPost = post
-		media = post.MediaAttachments
+		plaintext = fmt.Sprintf("%s> $user $content $media_descriptions", ref.ref)
 	}
-
-	for _, item := range media {
-		if item.Description != "" {
-			postfix += fmt.Sprintf("\n🖼️[%s]", item.Description)
-			continue
-		}
-		postfix += "🖼️"
-	}
-
-	plaintext = fmt.Sprintf("%s %s", poststring, postfix)
-	return
+	formatter := &StatusFormatter{hc: hc, status: post,}
+	templater := newStatusTemplateRenderer(formatter)
+	plaintext, _ = templater.render(plaintext)
+	return selectedPost, plaintext
 }
 
 func StreamHomeTimeline(client *mastodon.Client, postMap map[string]*mastodon.Status, hc *Hellclient) {
--- a/renderer.go
+++ b/renderer.go
@@ -17,9 +17,17 @@
 	postContext *postref
 }
 
+// Returns the rendered content of a status's rt
+func (st *StatusFormatter) reblogContent() string {
+	currentpost := st.status
+	defer func(){st.status = currentpost}()
+	st.status = st.status.Reblog
+	return st.statusContent()
+}
+
 // Returns the rendered content of a status
 func (st *StatusFormatter) statusContent() string {
-	renderedPost, plaintexts := st.hc.renderStatus(st.status.Content, st.postContext.ref)
+	renderedPost, plaintexts := st.hc.renderStatus(st.status.Content, "")
 	for key, plaintext := range plaintexts {
 		renderedPost = strings.Replace(renderedPost, key, plaintext, 1)
 	}
@@ -27,9 +35,13 @@
 	return renderedPost
 }
 
-func (st *StatusFormatter) mediaDescriptions() string {
+func (st *StatusFormatter) mediaDescriptions(reblog bool) string {
 	var sb strings.Builder
-	for _, item := range st.status.MediaAttachments {
+	status := st.status
+	if reblog {
+		status = status.Reblog
+	}
+	for _, item := range status.MediaAttachments {
 		if item.Description != "" {
 			sb.WriteString(fmt.Sprintf("\n🖼️[%s]", item.Description))
 			continue
@@ -79,6 +91,24 @@
 	return cf.statusContent()
 }
 
+// Status boost content stringer
+type boostContent struct {
+	*StatusFormatter
+}
+
+func (bc *boostContent) String() string {
+	return bc.reblogContent()
+}
+
+// Media descriptions for boosted posts stringer
+type boostMediaDescriptions struct {
+	*StatusFormatter
+}
+
+func (bm *boostMediaDescriptions) String() string {
+	return bm.mediaDescriptions(true)
+}
+
 // Media description stringer
 type mediaDescriptions struct {
 	*StatusFormatter
@@ -85,7 +115,7 @@
 }
 
 func (md *mediaDescriptions) String() string {
-	return md.mediaDescriptions()
+	return md.mediaDescriptions(false)
 }
 
 // Post detail line (likes rts replies) stringer
@@ -95,6 +125,19 @@
 
 func (dl *detailLine) String() string {
 	return dl.detailLine()
+}
+
+//Boosted username stringer
+type boostedusername struct {
+	*StatusFormatter
+}
+
+func (usr *boostedusername) String() string {
+	var sb strings.Builder
+	sb.WriteString("<")
+	sb.WriteString(usr.status.Reblog.Account.Username)
+	sb.WriteString(">")
+	return sb.String()
 }
 
 // Formatted <username> stringer
--- a/templater.go
+++ b/templater.go
@@ -22,6 +22,9 @@
 			{key: "media_descriptions", stringer: &mediaDescriptions{sf}},
 			{key: "detail_line", stringer: &detailLine{sf}},
 			{key: "username", stringer: &username{sf}},
+			{key: "boostuser", stringer: &boostedusername{sf}},
+			{key: "boostcontent", stringer: &boostContent{sf}},
+			{key: "boosted_media_descriptions", stringer: &boostMediaDescriptions{sf}},
 		},
 	}
 }
--