ref: 9d38f0a5cb1e494c072de5e4e1d33954f143faa2
parent: b6389cc0d5745e3bf29058610f73c0081842a5dd
author: penny <penny@limitedideas.org>
date: Thu Aug 21 20:13:13 EDT 2025
Simplify status queue
--- a/dispatch.go
+++ b/dispatch.go
@@ -13,7 +13,9 @@
func (hc *Hellclient) clientDispatch() {var tootQueue []*mastodon.Toot
+ //Last time we sent an API call
var lastfire time.Time
+ //Last time the user sent us a line
var lastreceive time.Time
var comingfast bool
for {@@ -25,7 +27,8 @@
}
lastreceive = time.Now()
tootQueue = append(tootQueue, statustoot)
- default:
+ //API delay needs to be tracked without being reset by new inputs
+ case <-time.After(hc.preferences.apidelay - time.Since(lastfire)):
if 1 > len(tootQueue) {statustoot := <-hc.dispatch
if time.Since(lastreceive) < time.Second {@@ -35,6 +38,7 @@
tootQueue = append(tootQueue, statustoot)
break
}
+ //User is sending lines faster than one a second, flood control
if comingfast { if time.Since(lastreceive) < time.Second {//looks like they're still coming
@@ -45,24 +49,18 @@
comingfast = false
break
}
- if time.Since(lastfire) < hc.preferences.apidelay {- time.Sleep(hc.preferences.apidelay - time.Since(lastfire))
- break
- }
- for _, toot := range tootQueue {- lastfire = time.Now()
- var err error
- status, err := postStatusDetailed(*hc.client, *toot)
- hc.lock()
- hc.recentpost = status
- hc.unlock()
- if err != nil {- fmt.Println(err)
- }
- tootQueue = tootQueue[1:]
- break
+ toot := tootQueue[0]
+ lastfire = time.Now()
+ var err error
+ status, err := postStatusDetailed(*hc.client, *toot)
+ if err != nil {+ fmt.Println(err)
}
+ hc.lock()
+ hc.recentpost = status
+ hc.unlock()
+ tootQueue = tootQueue[1:]
}
}
}
--
⑨