ref: 0eed9734ac90661d40bd8bdfe2403d1349cdd256
parent: 73c533fd15674bab9fa0b33e1a133a9b91e812f7
author: penny <penny@limitedideas.org>
date: Thu Sep 11 23:01:30 EDT 2025
Function to get statuses since an ID
--- a/hellclient.go
+++ b/hellclient.go
@@ -4,7 +4,6 @@
"context"
"fmt"
"io"
- "log"
"os"
"strings"
"sync"
@@ -52,7 +51,7 @@
apidelay time.Duration
}
-//Use this to make private versions of runes to stop default behavior
+// Use this to make private versions of runes to stop default behavior
func toPUA(r rune) rune {const (
puaStart = 0xE000
@@ -83,11 +82,11 @@
Listener: func(line []rune, pos int, key rune) ([]rune, int, bool) { if key == toPUA(readline.CharEnter) && hc.multiLineMode {// handle multi-line input
- line = line[:len(line) - 1]
+ line = line[:len(line)-1]
line = append(line, '\n')
return line, pos, true
}
-
+
//If we get an interupt just clear the line if it's not empty
if key == toPUA(readline.CharInterrupt) { if len(line) > 1 {@@ -102,7 +101,6 @@
if err != nil {return nil, err
}
-
account, err := loadConfig()
if err != nil {@@ -121,7 +119,7 @@
hc.updatePrompt()
//start up post dispatcher
go hc.clientDispatch()
-
+
markers, err := hc.client.GetTimelineMarkers(context.Background(), []string{"home"}) if err != nil {return
@@ -128,43 +126,23 @@
}
initReferenceSystem()
-
+
lastReadID := markers["home"].LastID
- var page *mastodon.Pagination
- statuses, err := hc.client.GetTimelineHome(context.Background(), page)
- maxID := statuses[0].ID
+ statuses, err := GetStatusesSince(lastReadID, hc.client.GetTimelineHome)
if err != nil {return
}
- page = &mastodon.Pagination{MinID: lastReadID} if len(statuses) > 0 {markers["home"].Timeline = "home"
- markers["home"].ID = maxID
+ markers["home"].ID = statuses[len(statuses)-1].ID
homemarker := markers["home"]
hc.client.SetTimelineMarkers(context.Background(), &[]mastodon.Marker{*homemarker})}
- for {- statuses, err := hc.client.GetTimelineHome(context.Background(), page)
- if err != nil {- log.Printf("error fetching timeline: %v", err)- break
- }
- if len(statuses) == 0 {- break
- }
- // Reverse the statuses to print them in chronological order
- for i := len(statuses) - 1; i >= 0; i-- {- status := statuses[i]
- hc.printPost("?"+hc.ctxref.ref, status)- saveRef(hc.ctxref.postmap, status, "?"+hc.ctxref.ref)
- hc.ctxref.ref = IncrementString(hc.ctxref.ref)
- }
- //I really don't understand the server's results but erase the max ID and it paginates up I don't know man
- page.MaxID = ""
- time.Sleep(1 * time.Second)
+ for _, status := range statuses {+ hc.printAndIncrement(hc.ctxref, status)
}
- }()
+ }()
homeMap := make(map[string]*mastodon.Status)
@@ -243,6 +221,3 @@
func (hc *Hellclient) unlock() {hc.block.Unlock()
}
-
-
-
--- a/mastodon.go
+++ b/mastodon.go
@@ -277,13 +277,6 @@
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,18 @@
(debugMap)[debugindex] = obj
}
+func justIncrementPostref(ref *postref, post *mastodon.Status) {+ IncrementRef(ref, post)
+ ref.ref = IncrementString(ref.ref)
+}
+
+func (hc *Hellclient) printAndIncrement(ref *postref, post *mastodon.Status) (returnPost *mastodon.Status) {+ returnPost = hc.printPostS(*ref, post)
+ IncrementRef(ref, post)
+ ref.ref = IncrementString(ref.ref)
+ return
+}
+
func IncrementRef(ref *postref, status *mastodon.Status) {saveCustomStatusRef(ref.postmap, status, ref.ref, ref.prefix)
}
--- /dev/null
+++ b/status.go
@@ -1,0 +1,37 @@
+package main
+
+import (
+ "context"
+ "time"
+
+ "github.com/mattn/go-mastodon"
+)
+
+func GetStatusesSince(ID mastodon.ID, GetTimeline func(ctx context.Context, pg *mastodon.Pagination) ([]*mastodon.Status, error)) ([]*mastodon.Status, error) {+
+ page := &mastodon.Pagination{MinID: ID}+
+ var err error
+ var statuses []*mastodon.Status
+
+ for {+ statusbatch, err := GetTimeline(context.Background(), page)
+ if err != nil {+ return statuses, err
+ }
+
+ if len(statusbatch) == 0 {+ break
+ }
+
+ for i := len(statusbatch) - 1; i >= 0; i-- {+ statuses = append(statuses, statusbatch[i])
+ }
+ //I really don't understand the server's results but erase the max ID and it paginates up I don't know man
+ page.MaxID = ""
+ time.Sleep(1 * time.Second)
+ }
+
+ return statuses, err
+
+}
--
⑨