mirror of
https://github.com/adulau/mastodon-markdown-archive.git
synced 2024-11-21 09:27:05 +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,7 +114,14 @@ func (c *Client) buildOrphans() error {
|
|||
return err
|
||||
}
|
||||
|
||||
top := statusContext.Ancestors[0]
|
||||
var top 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]
|
||||
|
@ -123,6 +130,9 @@ func (c *Client) buildOrphans() error {
|
|||
}
|
||||
|
||||
top.descendants = append(top.descendants, c.postIdMap[postId])
|
||||
} else {
|
||||
top = *c.postIdMap[postId]
|
||||
}
|
||||
|
||||
for i := range statusContext.Descendants {
|
||||
post := statusContext.Descendants[i]
|
||||
|
|
Loading…
Reference in a new issue