ref: f0b417480ed5554d0cebb6bd82c7a5c4dea8b002
parent: 992a04bed0dab9da71b6428bb122c4b35883b048
author: penny <penny@limitedideas.org>
date: Tue Nov 4 15:48:05 EST 2025
port four more commands
--- a/commands.go
+++ b/commands.go
@@ -7,7 +7,8 @@
"time"
"context"
"strconv"
-
+
+ "github.com/k3a/html2text"
mastodon "codeberg.org/penny64/hellclient-go-mastodon"
)
@@ -966,6 +967,102 @@
return cmd
}
+//another printer fixme
+func (hc *Hellclient) parentcmd() cmder {+ cmd := &basiccmd{}+ cmd.hc = hc
+ cmd.bname = "parent"
+ cmd.bflags = status
+ cmd.doer = func(data *cmddata) string {+ parentfunc := func() {+ if data.status.InReplyToID == nil {+ fmt.Printf("%v doesn't have a parent\n", data.index)+ return
+ }
+ parentStatus, _ := hc.client.GetStatus(context.Background(), mastodon.ID(data.status.InReplyToID.(string)))
+ hc.printAndIncrement(hc.ctxref, parentStatus)
+ return
+ }
+ hc.dispatchAnon(parentfunc).Wait()
+ return ""
+ }
+ return cmd
+}
+
+//another printer fixme
+func (hc *Hellclient) childrencmd() cmder {+ cmd := &basiccmd{}+ cmd.hc = hc
+ cmd.bname = "children"
+ cmd.bflags = status
+ cmd.doer = func(data *cmddata) string {+ childfunc := func() {+ context, err := hc.client.GetStatusContext(context.Background(), data.status.ID)
+ if err != nil {+ fmt.Println(err)
+ return
+ }
+ if len(context.Descendants) == 0 {+ fmt.Printf("\"%s\" has no children\n", data.index)+ }
+ for post := range context.Descendants {+ hc.printAndIncrement(hc.ctxref, context.Descendants[post])
+ }
+ return
+ }
+ hc.dispatchAnon(childfunc).Wait()
+ return ""
+ }
+ return cmd
+}
+
+func (hc *Hellclient) editcmd() cmder {+ cmd := &basiccmd{}+ cmd.hc = hc
+ cmd.bname = "edit"
+ cmd.bflags = status
+ cmd.doer = func(data *cmddata) string {+ var err error
+ if data.content == "" || data.content == " " {+ if data.status.Account.ID != hc.currentuser.ID {+ return fmt.Sprintf("cannot edit other's statuses!\n")+ }
+ fixedHTML, err := prepareForEdit(data.status)
+ if err != nil {+ return fmt.Sprintf("Error loading post HTML: %s\n", err)+ }
+ hc.rl.SetDefault(fmt.Sprintf("/edit %v %v", data.index, html2text.HTML2TextWithOptions(fixedHTML, html2text.WithUnixLineBreaks())))+ return ""
+ }
+ var MediaIDs []mastodon.ID
+ for _, media := range data.status.MediaAttachments {+ MediaIDs = append(MediaIDs, media.ID)
+ }
+ toot := &mastodon.Toot{+ Status: data.content,
+ MediaIDs: MediaIDs,
+ Sensitive: data.status.Sensitive,
+ SpoilerText: data.status.SpoilerText,
+ Visibility: data.status.Visibility,
+ Language: data.status.Language,
+ }
+ if data.status.InReplyToID != nil {+ id := mastodon.ID(data.status.InReplyToID.(string))
+ toot.InReplyToID = id
+ }
+ editfunc := func() {+ _, err = hc.client.UpdateStatus(context.Background(), toot, data.status.ID)
+ }
+ hc.dispatchAnon(editfunc).Wait()
+ if err != nil {+ return fmt.Sprintf("err: %s\n", err)+ }
+ return ""
+ }
+ return cmd
+}
+
+
// Commmands are lazy evaluated in this order
// Single/two letter matches need to match the most common commands
func (hc *Hellclient) newCmdArray() []cmder {@@ -976,11 +1073,14 @@
hc.unmarkcmd(),
hc.translatecmd(),
hc.catcmd(),
+ hc.childrencmd(),
hc.replycmd(),
hc.rtcmd(),
hc.rmcmd(),
&reloadcmd{hc}, &profilecmd{hc, hc.cmdload},+ hc.publiccmd(),
+ hc.parentcmd(),
&dmcmd{hc},hc.downloadcmd(),
&helpcmd{hc},@@ -999,12 +1099,13 @@
hc.homecmd(),
hc.hrtcmd(),
hc.localcmd(),
- hc.publiccmd(),
hc.statusurlcmd("open", &hc.preferences.Browser), hc.urlcmd("url", &hc.preferences.Browser), hc.urlcmd("play", &hc.preferences.MediaPlayer), hc.mediacmd("view", &hc.preferences.ImageViewer), hc.mediacmd("import", &hc.preferences.MediaImport),+ hc.editcmd(),
+
}
return cmdarray
}
--- a/main.go
+++ b/main.go
@@ -22,7 +22,6 @@
homeMap := hc.homeMap
lastindex := ""
- recentpost := &hc.recentpost
var lastaccount *mastodon.Account
@@ -119,48 +118,6 @@
//Commands require status indexes
switch command {- case "rt":
- rtfunc := func() {- rtStatus, err := client.Reblog(context.Background(), postItem.ID)
- if err != nil {- fmt.Println(err)
- return
- }
- *recentpost = rtStatus
- hc.printAndIncrement(hc.ctxref, rtStatus)
- return
- }
- hc.dispatchAnon(rtfunc).Wait()
- return
- case "parent":
- parentfunc := func() {- if postItem.InReplyToID == nil {- fmt.Printf("%v doesn't have a parent\n", index)- return
- }
- parentStatus, _ := client.GetStatus(context.Background(), mastodon.ID(postItem.InReplyToID.(string)))
- hc.printAndIncrement(hc.ctxref, parentStatus)
- return
- }
- hc.dispatchAnon(parentfunc).Wait()
- return
- case "children":
- childfunc := func() {- context, err := client.GetStatusContext(context.Background(), postItem.ID)
- if err != nil {- fmt.Println(err)
- return
- }
- if len(context.Descendants) == 0 {- fmt.Printf("\"%s\" has no children\n", index)- }
- for post := range context.Descendants {- hc.printAndIncrement(hc.ctxref, context.Descendants[post])
- }
- return
- }
- hc.dispatchAnon(childfunc).Wait()
- return
case "edit":
if content == "" || content == " " { if (postItem == nil) || postItem.Account.ID != hc.currentuser.ID {--
⑨