mirror of
https://github.com/adulau/mastodon-markdown-archive.git
synced 2024-11-23 02:17:07 +00:00
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:
parent
33c6f3081c
commit
41663032f9
2 changed files with 18 additions and 8 deletions
|
@ -114,16 +114,26 @@ func (c *Client) buildOrphans() error {
|
|||
return err
|
||||
}
|
||||
|
||||
top := statusContext.Ancestors[0]
|
||||
var top Post;
|
||||
|
||||
for i := range statusContext.Ancestors[1:] {
|
||||
post := statusContext.Ancestors[i+1]
|
||||
c.postIdMap[post.Id] = &post
|
||||
top.descendants = append(top.descendants, &post)
|
||||
// When building a thread from the status context endpoint,
|
||||
// start from the greatest ancestor and add the other ancestors
|
||||
// below it as descendants.
|
||||
// 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 {
|
||||
post := statusContext.Descendants[i]
|
||||
if post.Account.Id != c.account.Id {
|
||||
|
|
2
main.go
2
main.go
|
@ -43,7 +43,7 @@ func main() {
|
|||
MinId: *minId,
|
||||
OnlyMedia: *onlyMedia,
|
||||
Pinned: *pinned,
|
||||
Tagged: *tagged,
|
||||
Tagged: *tagged,
|
||||
}, client.ClientOptions{
|
||||
Threaded: *threaded,
|
||||
Visibility: *visibility,
|
||||
|
|
Loading…
Reference in a new issue