mirror of
https://github.com/adulau/mastodon-markdown-archive.git
synced 2024-11-21 17:37:06 +00:00
Default threading to false, and slight threading refactor
This commit is contained in:
parent
4158621927
commit
b5ead62468
2 changed files with 20 additions and 17 deletions
|
@ -80,7 +80,15 @@ func New(userURL string, filters PostsFilter, threaded bool) (Client, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if threaded {
|
if threaded {
|
||||||
client.threadReplies(posts)
|
for _, post := range posts {
|
||||||
|
client.threadPost(post.Id)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(client.orphans) > 0 {
|
||||||
|
if err := client.buildOrphans(); err != nil {
|
||||||
|
return client, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return client, nil
|
return client, nil
|
||||||
|
@ -143,23 +151,18 @@ func (c *Client) flushReplies(post *Post, descendants *[]*Post) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) threadReplies(posts []Post) {
|
func (c *Client) threadPost(postId string) {
|
||||||
for i := range posts {
|
post := c.postIdMap[postId]
|
||||||
post := &posts[i]
|
|
||||||
if post.InReplyToId == "" {
|
|
||||||
c.flushReplies(post, &post.descendants)
|
|
||||||
c.output = append(c.output, post.Id)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, ok := c.postIdMap[post.InReplyToId]; ok {
|
if post.InReplyToId == "" {
|
||||||
c.replies[post.InReplyToId] = post.Id
|
c.flushReplies(post, &post.descendants)
|
||||||
} else {
|
c.output = append(c.output, post.Id)
|
||||||
c.orphans = append(c.orphans, post.Id)
|
return
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(c.orphans) > 0 {
|
if _, ok := c.postIdMap[post.InReplyToId]; ok {
|
||||||
c.buildOrphans()
|
c.replies[post.InReplyToId] = post.Id
|
||||||
|
} else {
|
||||||
|
c.orphans = append(c.orphans, post.Id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
main.go
2
main.go
|
@ -23,7 +23,7 @@ func main() {
|
||||||
persistFirst := flag.String("persist-first", "", "Location to persist the post id of the first post returned")
|
persistFirst := flag.String("persist-first", "", "Location to persist the post id of the first post returned")
|
||||||
persistLast := flag.String("persist-last", "", "Location to persist the post id of the last post returned")
|
persistLast := flag.String("persist-last", "", "Location to persist the post id of the last post returned")
|
||||||
templateFile := flag.String("template", "", "Template to use for post rendering, if passed")
|
templateFile := flag.String("template", "", "Template to use for post rendering, if passed")
|
||||||
threaded := flag.Bool("threaded", true, "Thread replies for a post in a single file")
|
threaded := flag.Bool("threaded", false, "Thread replies for a post in a single file")
|
||||||
filenameTemplate := flag.String("filename", "", "Template for post filename")
|
filenameTemplate := flag.String("filename", "", "Template for post filename")
|
||||||
porcelain := flag.Bool("porcelain", false, "Prints the amount of fetched posts to stdout in a parsable manner")
|
porcelain := flag.Bool("porcelain", false, "Prints the amount of fetched posts to stdout in a parsable manner")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue