diff --git a/system/discourse/discourse.go b/system/discourse/discourse.go index 67303e5..5951c82 100644 --- a/system/discourse/discourse.go +++ b/system/discourse/discourse.go @@ -259,21 +259,24 @@ func (sys *System) LoadPost(p *post.Post) error { // first 20 posts otherwise. p.TotalReplies = len(item.PostStream.Stream) if p.TotalReplies > 20 { + var postIDs []int + if p.CurrentRepliesStartIDX == -1 || // Explain to me standard GoFmt logic: p.CurrentRepliesStartIDX > (p.TotalReplies-20) { p.CurrentRepliesStartIDX = (p.TotalReplies - 20) // /)_-) + } else if p.CurrentRepliesStartIDX < -1 { + p.CurrentRepliesStartIDX = 0 } - var postIDs []int if p.CurrentRepliesStartIDX > 0 { postIDs = append(postIDs, item.PostStream.Stream[0]) p.CurrentRepliesStartIDX++ } postIDs = append(postIDs, - item.PostStream.Stream[p.CurrentRepliesStartIDX:]...) + item.PostStream.Stream[p.CurrentRepliesStartIDX:(p.CurrentRepliesStartIDX+20)]...) replies, err := sys.client.Topics.ShowPosts( context.Background(), diff --git a/system/hackernews/hackernews.go b/system/hackernews/hackernews.go index 6c68ef5..5342486 100644 --- a/system/hackernews/hackernews.go +++ b/system/hackernews/hackernews.go @@ -223,7 +223,10 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) { SysIDX: sys.ID, }, - Replies: replies, + // TODO: Implement chunks loading + TotalReplies: 0, + CurrentRepliesStartIDX: -1, + Replies: replies, URL: fmt.Sprintf("https://news.ycombinator.com/item?id=%d", i.ID), diff --git a/system/lemmy/lemmy.go b/system/lemmy/lemmy.go index b543d19..7836f2f 100644 --- a/system/lemmy/lemmy.go +++ b/system/lemmy/lemmy.go @@ -202,6 +202,10 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) { SysIDX: sys.ID, }, + // TODO: Implement chunks loading + TotalReplies: 0, + CurrentRepliesStartIDX: -1, + URL: fmt.Sprintf("%s/post/%d", baseURL, i.Post.ID), SysIDX: sys.ID, diff --git a/system/lobsters/lobsters.go b/system/lobsters/lobsters.go index ed46258..3fdae94 100644 --- a/system/lobsters/lobsters.go +++ b/system/lobsters/lobsters.go @@ -182,6 +182,10 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) { SysIDX: sys.ID, }, + // TODO: Implement chunks loading + TotalReplies: 0, + CurrentRepliesStartIDX: -1, + URL: i.ShortIDURL, SysIDX: sys.ID, diff --git a/ui/windows/postshow/handlers.go b/ui/windows/postshow/handlers.go index 88edd32..22ce8a3 100644 --- a/ui/windows/postshow/handlers.go +++ b/ui/windows/postshow/handlers.go @@ -109,6 +109,16 @@ func handleOpen(mi interface{}) (bool, []tea.Cmd) { return true, cmds } +func handleOlder(mi interface{}) (bool, []tea.Cmd) { + var m *Model = mi.(*Model) + var cmds []tea.Cmd + + m.activePost.CurrentRepliesStartIDX -= 20 + m.ctx.Loading = true + cmds = append(cmds, m.loadPost(m.activePost)) + return true, cmds +} + func handleNumberKeys(mi interface{}, n int8) (bool, []tea.Cmd) { var m *Model = mi.(*Model) var cmds []tea.Cmd diff --git a/ui/windows/postshow/postshow.go b/ui/windows/postshow/postshow.go index 90999ec..5d11f68 100644 --- a/ui/windows/postshow/postshow.go +++ b/ui/windows/postshow/postshow.go @@ -63,6 +63,7 @@ func NewModel(c *ctx.Ctx) Model { m.tk.KeymapAdd("reply", "reply (prefix with #, e.g. '2r')", "r") m.tk.KeymapAdd("open", "open", "o") + m.tk.KeymapAdd("older", "older replies", "z") m.a, _ = aggregator.New(m.ctx) @@ -77,6 +78,10 @@ func NewModel(c *ctx.Ctx) Model { ID: "open", Handler: handleOpen, }, + { + ID: "older", + Handler: handleOlder, + }, }, OnAnyNumberKey: handleNumberKeys, OnAnyUncaughtKey: handleUncaughtKeys, diff --git a/ui/windows/postshow/view.go b/ui/windows/postshow/view.go index 77da471..ade52f3 100644 --- a/ui/windows/postshow/view.go +++ b/ui/windows/postshow/view.go @@ -71,6 +71,10 @@ func (m *Model) renderViewport(p *post.Post) string { caps := (*m.ctx.Systems[p.SysIDX]).GetCapabilities() if caps.IsCapableOf("list:replies") { + if m.activePost.CurrentRepliesStartIDX > 0 { + tmp, _ := m.glam.Render(fmt.Sprintf("\n---\nOlder replies available, press `z` to load\n\n---\n")) + out += tmp + } out += m.renderReplies(0, p.Author.Name, &p.Replies) }