ref: 0e378d63fd104262b1388b8be05d89bdbf29df06
parent: 1f40f47ce09940c3f34ba469eb2f0162599372d2
author: penny <penny@limitedideas.org>
date: Sat Aug 30 21:25:33 EDT 2025
Move clientdispatch start to hc init
--- a/hellclient.go
+++ b/hellclient.go
@@ -2,6 +2,7 @@
import (
"context"
+ "fmt"
"io"
"strings"
"sync"
@@ -55,11 +56,18 @@
dispatch := make(chan *mastodon.Toot, 15)
+ var hc Hellclient
+
+ defer func() {+ //start up post dispatcher
+ go hc.clientDispatch()
+ }()
+
homeMap := make(map[string]*mastodon.Status)
debugMap := make(map[string]interface{})urlMap := make(map[string][]string)
prefs := &Hellprefs{apidelay: time.Second * 3}- return &Hellclient{rl: rl,+ hc = Hellclient{rl: rl,homeMap: homeMap,
debugMap: debugMap,
isPaused: false,
@@ -68,14 +76,22 @@
currentuser: currentuser,
dispatch: dispatch,
preferences: prefs,
- }, nil
+ }
+ return &hc, nil
}
func (hc *Hellclient) updatePrompt() {var sb strings.Builder
+
+ var pg mastodon.Pagination
+ notifications, _ := hc.client.GetNotifications(context.Background(), &pg)
+ if len(notifications) > 0 {+ sb.WriteString(fmt.Sprintf("ur:%v ", len(notifications)))+ }
if hc.isPaused { sb.WriteString("STREAMING PAUSED ")}
+
sb.WriteString("Hell> ")hc.rl.SetPrompt(sb.String())
}
--- a/main.go
+++ b/main.go
@@ -14,15 +14,14 @@
func main() {hc, err := NewHellclient()
- //start up post dispatcher
- go hc.clientDispatch()
if err != nil { fmt.Printf("Error starting account: %v\n", err)return
}
- rl := hc.rl
- client := hc.client
+ rl := *hc.rl
+ client := *hc.client
+
//Horrible io pipe hack
//Replaces system stdout with the readline one
r, w, _ := os.Pipe()
@@ -43,7 +42,7 @@
return
}
- go StreamHomeTimeline(client, homeMap, hc)
+ go StreamHomeTimeline(&client, homeMap, hc)
for { func() {@@ -99,7 +98,7 @@
} else {postItem, postOK = homeMap[lastindex]
}
-
+
//Okay now see if the post we end up with is a reblog
if postOK { if postItem.Reblog != nil {@@ -277,12 +276,12 @@
MediaIDs = append(MediaIDs, media.ID)
}
toot := &mastodon.Toot{- Status: content,
- MediaIDs: MediaIDs,
- Sensitive: postItem.Sensitive,
+ Status: content,
+ MediaIDs: MediaIDs,
+ Sensitive: postItem.Sensitive,
SpoilerText: postItem.SpoilerText,
- Visibility: postItem.Visibility,
- Language: postItem.Language,
+ Visibility: postItem.Visibility,
+ Language: postItem.Language,
}
if postItem.InReplyToID != nil {id := mastodon.ID(postItem.InReplyToID.(string))
@@ -293,7 +292,7 @@
fmt.Println(err)
return
}
-
+
case "thread":
context, err := client.GetStatusContext(context.Background(), postItem.ID)
if err != nil {--- a/mastodon.go
+++ b/mastodon.go
@@ -189,7 +189,6 @@
}
func postStatusDetailed(client mastodon.Client, toot mastodon.Toot) (status *mastodon.Status, err error) {-
status, err = client.PostStatus(context.Background(), &toot)
return
}
--
⑨