Fix bug in thread building using status context

It cannot be assumed that an ancestor will exist
when building a thread using the status context
API. Use the current orphan as the starting point
if no ancestor exists.
This commit is contained in:
Gabriel Garrido 2024-08-03 08:33:33 +02:00
parent 33c6f3081c
commit 41663032f9
2 changed files with 18 additions and 8 deletions

View file

@ -114,16 +114,26 @@ func (c *Client) buildOrphans() error {
return err return err
} }
top := statusContext.Ancestors[0] var top Post;
for i := range statusContext.Ancestors[1:] { // When building a thread from the status context endpoint,
post := statusContext.Ancestors[i+1] // start from the greatest ancestor and add the other ancestors
c.postIdMap[post.Id] = &post // below it as descendants.
top.descendants = append(top.descendants, &post) // Otherwise, use the orphan as the start.
if len(statusContext.Ancestors) > 0 {
top = statusContext.Ancestors[0]
for i := range statusContext.Ancestors[1:] {
post := statusContext.Ancestors[i+1]
c.postIdMap[post.Id] = &post
top.descendants = append(top.descendants, &post)
}
top.descendants = append(top.descendants, c.postIdMap[postId])
} else {
top = *c.postIdMap[postId]
} }
top.descendants = append(top.descendants, c.postIdMap[postId])
for i := range statusContext.Descendants { for i := range statusContext.Descendants {
post := statusContext.Descendants[i] post := statusContext.Descendants[i]
if post.Account.Id != c.account.Id { if post.Account.Id != c.account.Id {

View file

@ -43,7 +43,7 @@ func main() {
MinId: *minId, MinId: *minId,
OnlyMedia: *onlyMedia, OnlyMedia: *onlyMedia,
Pinned: *pinned, Pinned: *pinned,
Tagged: *tagged, Tagged: *tagged,
}, client.ClientOptions{ }, client.ClientOptions{
Threaded: *threaded, Threaded: *threaded,
Visibility: *visibility, Visibility: *visibility,