ref: f02f6adb3fbd547fb52e13b86925469bae0c6a2a
parent: 0483c87417cacff56e96535ba1d1caf76a198100
author: penny <penny@limitedideas.org>
date: Wed Sep 3 18:04:21 EDT 2025
Abstractions for printing and incrementing a post
--- a/hellclient.go
+++ b/hellclient.go
@@ -20,6 +20,7 @@
type postref struct {prefix string
ref string
+ postmap map[string]*mastodon.Status
}
type Hellclient struct {@@ -34,6 +35,7 @@
preferences *Hellprefs
homeMap map[string]*mastodon.Status
+ ctxref *postref
urlMap map[string][]string
debugMap map[string]interface{}actionBuffer []func()
@@ -69,11 +71,18 @@
}()
homeMap := make(map[string]*mastodon.Status)
+
+ ctxref := &postref{+ prefix: "?",
+ ref: "a",
+ postmap: homeMap,
+ }
debugMap := make(map[string]interface{})urlMap := make(map[string][]string)
prefs := &Hellprefs{apidelay: time.Second * 3} hc = Hellclient{rl: rl,homeMap: homeMap,
+ ctxref: ctxref,
debugMap: debugMap,
isPaused: false,
urlMap: urlMap,
--- a/main.go
+++ b/main.go
@@ -33,7 +33,6 @@
homeMap := hc.homeMap
debugMap := hc.debugMap
- postref := "a"
lastindex := ""
interupted := false //use this to check if we were interupted last turn
recentpost := &hc.recentpost
@@ -241,9 +240,7 @@
return
}
*recentpost = rtStatus
- saveWorkRef(homeMap, rtStatus, postref)
- hc.printPost("?"+postref, rtStatus)- postref = IncrementString(postref)
+ hc.printAndIncrement(hc.ctxref, rtStatus)
return
case "parent":
if postItem.InReplyToID == nil {@@ -251,9 +248,7 @@
return
}
parentStatus, _ := client.GetStatus(context.Background(), mastodon.ID(postItem.InReplyToID.(string)))
- saveWorkRef(homeMap, parentStatus, postref)
- hc.printPost("?"+postref, parentStatus)- postref = IncrementString(postref)
+ hc.printAndIncrement(hc.ctxref, parentStatus)
return
case "children":
context, err := client.GetStatusContext(context.Background(), postItem.ID)
@@ -265,9 +260,7 @@
fmt.Printf("\"%v\" has no children\n")}
for post := range context.Descendants {- saveWorkRef(homeMap, context.Descendants[post], postref)
- hc.printPost("?"+postref, context.Descendants[post])- postref = IncrementString(postref)
+ hc.printAndIncrement(hc.ctxref, context.Descendants[post])
}
return
case "edit":
@@ -305,17 +298,13 @@
}
hc.pause(true) // pause so user can read the thread
for post := range context.Ancestors {- saveWorkRef(homeMap, context.Ancestors[post], postref)
- hc.printPost("?"+postref, context.Ancestors[post])- postref = IncrementString(postref)
+ hc.printAndIncrement(hc.ctxref, context.Ancestors[post])
}
hc.printPost(index, postItem)
for post := range context.Descendants {- saveWorkRef(homeMap, context.Descendants[post], postref)
- hc.printPost("?"+postref, context.Descendants[post])- postref = IncrementString(postref)
+ hc.printAndIncrement(hc.ctxref, context.Descendants[post])
}
return
case "account":
--- a/mastodon.go
+++ b/mastodon.go
@@ -253,6 +253,17 @@
fmt.Printf("\r%w\n", err)}
+func (hc *Hellclient) printPostS(ref postref, post *mastodon.Status) *mastodon.Status {+ return hc.printPostDetailed(ref.prefix + ref.ref, post, "")
+}
+
+func (hc *Hellclient) printAndIncrement(ref *postref, post *mastodon.Status) (returnPost *mastodon.Status) {+ IncrementRef(ref, post)
+ returnPost = hc.printPostS(*ref, post)
+ ref.ref = IncrementString(ref.ref)
+ return
+}
+
func (hc *Hellclient) printPost(postref string, post *mastodon.Status) *mastodon.Status {return hc.printPostDetailed(postref, post, "")
}
--- a/references.go
+++ b/references.go
@@ -23,6 +23,10 @@
(debugMap)[debugindex] = obj
}
+func IncrementRef(ref *postref, status *mastodon.Status) {+ saveCustomStatusRef(ref.postmap, status, ref.ref, ref.prefix)
+}
+
func saveWorkRef(statusMap map[string]*mastodon.Status, post *mastodon.Status, index string) {saveCustomStatusRef(statusMap, post, index, "?")
}
--
⑨