From da449a03cd409e05c9c0bd84634bb56c75dc4510 Mon Sep 17 00:00:00 2001 From: Ryuuusuke Date: Wed, 18 Feb 2026 15:29:03 +0700 Subject: [PATCH 1/2] feat: autoread when open in browser --- internal/commands/list.go | 48 +++++++++++-------- internal/commands/viewport.go | 87 +++++++++++++++++++---------------- 2 files changed, 76 insertions(+), 59 deletions(-) diff --git a/internal/commands/list.go b/internal/commands/list.go index 7ea97d6..d1ee56c 100644 --- a/internal/commands/list.go +++ b/internal/commands/list.go @@ -195,26 +195,7 @@ func updateList(msg tea.Msg, m model) (tea.Model, tea.Cmd) { cmds = append(cmds, refreshList(m)) case key.Matches(msg, ListKeyMap.Read): - if m.list.SettingFilter() { - break - } - - if len(m.list.Items()) == 0 { - return m, m.list.NewStatusMessage("No items to mark.") - } - - item := m.list.SelectedItem() - if item == nil { - return m, m.list.NewStatusMessage("No item selected.") - } - - current := item.(TUIItem) - err := m.commands.store.ToggleRead(current.ID) - if err != nil { - return m, m.list.NewStatusMessage(fmt.Sprintf("Error marking read: %s", err)) - } - - cmds = append(cmds, m.UpdateList()) + markReadList(&m, &cmds) case key.Matches(msg, ListKeyMap.ToggleReads): if m.list.SettingFilter() { @@ -282,6 +263,9 @@ func updateList(msg tea.Msg, m model) (tea.Model, tea.Cmd) { current := item.(TUIItem) cmd = m.OpenLink(current.URL) cmds = append(cmds, cmd) + if !current.Read && m.commands.config.AutoRead { + markReadList(&m, &cmds) + } case key.Matches(msg, ListKeyMap.Sort): if m.list.SettingFilter() || m.list.IsFiltered() { @@ -370,3 +354,27 @@ func getEditor(vars ...string) string { return "nano" } + +func markReadList(m *model, cmds *[]tea.Cmd) (tea.Model, tea.Cmd) { + if m.list.SettingFilter() { + return m, nil + } + + if len(m.list.Items()) == 0 { + return m, m.list.NewStatusMessage("No items to mark.") + } + + item := m.list.SelectedItem() + if item == nil { + return m, m.list.NewStatusMessage("No item selected.") + } + + current := item.(TUIItem) + err := m.commands.store.ToggleRead(current.ID) + if err != nil { + return m, m.list.NewStatusMessage(fmt.Sprintf("Error marking read: %s", err)) + } + + *cmds = append(*cmds, m.UpdateList()) + return m, nil +} diff --git a/internal/commands/viewport.go b/internal/commands/viewport.go index c14db3b..5e61598 100644 --- a/internal/commands/viewport.go +++ b/internal/commands/viewport.go @@ -48,7 +48,11 @@ func updateViewport(msg tea.Msg, m model) (tea.Model, tea.Cmd) { it := ItemToTUIItem(current) cmd = m.OpenLink(it.URL) + cmds = append(cmds, cmd) + if !current.Read() && m.commands.config.AutoRead { + markRead(m) + } case key.Matches(msg, ViewportKeyMap.Favourite): current, err := m.commands.store.GetItemByID(*m.selectedArticle) @@ -63,45 +67,7 @@ func updateViewport(msg tea.Msg, m model) (tea.Model, tea.Cmd) { } case key.Matches(msg, ViewportKeyMap.Read): - if m.commands.config.AutoRead { - return m, nil - } - current, err := m.commands.store.GetItemByID(*m.selectedArticle) - if err != nil { - m.selectedArticle = nil - return m, m.list.NewStatusMessage("Error: failed to get article") - } - err = m.commands.store.ToggleRead(current.ID) - if err != nil { - m.selectedArticle = nil - return m, m.list.NewStatusMessage("Error marking read") - } - - if !m.commands.config.ShowRead { - index := m.list.Index() - - if m.lastRead != nil && current.ID == (*m.lastRead).(TUIItem).ID { - // un-read re-add post back to list - m.list.InsertItem(index, *m.lastRead) - m.lastReadIndex = index - m.lastRead = nil - } else { - // remove post and store backup for un-read - items := m.list.Items() - item := items[index] - m.list.RemoveItem(index) - m.lastReadIndex = index - m.lastRead = &item - } - } - - // trigger refresh to update read indication - content, err := m.commands.GetGlamourisedArticle(*m.selectedArticle) - if err != nil { - m.selectedArticle = nil - return m, m.list.NewStatusMessage("Error rendering article") - } - m.viewport.SetContent(content) + markRead(m) case key.Matches(msg, ViewportKeyMap.Prev): navIndex := m.getPrevIndex() @@ -228,3 +194,46 @@ func viewportView(m model) string { func (m model) viewportHelp() string { return helpStyle.Render(m.help.View(ViewportKeyMap)) } + +func markRead(m model) (tea.Model, tea.Cmd) { + if m.commands.config.AutoRead { + return m, nil + } + current, err := m.commands.store.GetItemByID(*m.selectedArticle) + if err != nil { + m.selectedArticle = nil + return m, m.list.NewStatusMessage("Error: failed to get article") + } + err = m.commands.store.ToggleRead(current.ID) + if err != nil { + m.selectedArticle = nil + return m, m.list.NewStatusMessage("Error marking read") + } + + if !m.commands.config.ShowRead { + index := m.list.Index() + + if m.lastRead != nil && current.ID == (*m.lastRead).(TUIItem).ID { + // un-read re-add post back to list + m.list.InsertItem(index, *m.lastRead) + m.lastReadIndex = index + m.lastRead = nil + } else { + // remove post and store backup for un-read + items := m.list.Items() + item := items[index] + m.list.RemoveItem(index) + m.lastReadIndex = index + m.lastRead = &item + } + } + + // trigger refresh to update read indication + content, err := m.commands.GetGlamourisedArticle(*m.selectedArticle) + if err != nil { + m.selectedArticle = nil + return m, m.list.NewStatusMessage("Error rendering article") + } + m.viewport.SetContent(content) + return m, nil +} From f943c72c11eeb3f7120c454af4987fdabdef727c Mon Sep 17 00:00:00 2001 From: Ryuuusuke Date: Wed, 18 Feb 2026 22:52:03 +0700 Subject: [PATCH 2/2] fix: silent error caused by cmds not returning --- internal/commands/list.go | 20 ++++++++++++-------- internal/commands/viewport.go | 20 ++++++++++++-------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/internal/commands/list.go b/internal/commands/list.go index d1ee56c..f7fbe2e 100644 --- a/internal/commands/list.go +++ b/internal/commands/list.go @@ -195,7 +195,9 @@ func updateList(msg tea.Msg, m model) (tea.Model, tea.Cmd) { cmds = append(cmds, refreshList(m)) case key.Matches(msg, ListKeyMap.Read): - markReadList(&m, &cmds) + if cmd := markReadList(&m, &cmds); cmd != nil { + cmds = append(cmds, cmd) + } case key.Matches(msg, ListKeyMap.ToggleReads): if m.list.SettingFilter() { @@ -264,7 +266,9 @@ func updateList(msg tea.Msg, m model) (tea.Model, tea.Cmd) { cmd = m.OpenLink(current.URL) cmds = append(cmds, cmd) if !current.Read && m.commands.config.AutoRead { - markReadList(&m, &cmds) + if cmd := markReadList(&m, &cmds); cmd != nil { + cmds = append(cmds, cmd) + } } case key.Matches(msg, ListKeyMap.Sort): @@ -355,26 +359,26 @@ func getEditor(vars ...string) string { return "nano" } -func markReadList(m *model, cmds *[]tea.Cmd) (tea.Model, tea.Cmd) { +func markReadList(m *model, cmds *[]tea.Cmd) tea.Cmd { if m.list.SettingFilter() { - return m, nil + return nil } if len(m.list.Items()) == 0 { - return m, m.list.NewStatusMessage("No items to mark.") + return m.list.NewStatusMessage("No items to mark.") } item := m.list.SelectedItem() if item == nil { - return m, m.list.NewStatusMessage("No item selected.") + return m.list.NewStatusMessage("No item selected.") } current := item.(TUIItem) err := m.commands.store.ToggleRead(current.ID) if err != nil { - return m, m.list.NewStatusMessage(fmt.Sprintf("Error marking read: %s", err)) + return m.list.NewStatusMessage(fmt.Sprintf("Error marking read: %s", err)) } *cmds = append(*cmds, m.UpdateList()) - return m, nil + return nil } diff --git a/internal/commands/viewport.go b/internal/commands/viewport.go index 5e61598..f84ced8 100644 --- a/internal/commands/viewport.go +++ b/internal/commands/viewport.go @@ -51,7 +51,9 @@ func updateViewport(msg tea.Msg, m model) (tea.Model, tea.Cmd) { cmds = append(cmds, cmd) if !current.Read() && m.commands.config.AutoRead { - markRead(m) + if cmd := markRead(&m); cmd != nil { + cmds = append(cmds, cmd) + } } case key.Matches(msg, ViewportKeyMap.Favourite): @@ -67,7 +69,9 @@ func updateViewport(msg tea.Msg, m model) (tea.Model, tea.Cmd) { } case key.Matches(msg, ViewportKeyMap.Read): - markRead(m) + if cmd := markRead(&m); cmd != nil { + cmds = append(cmds, cmd) + } case key.Matches(msg, ViewportKeyMap.Prev): navIndex := m.getPrevIndex() @@ -195,19 +199,19 @@ func (m model) viewportHelp() string { return helpStyle.Render(m.help.View(ViewportKeyMap)) } -func markRead(m model) (tea.Model, tea.Cmd) { +func markRead(m *model) tea.Cmd { if m.commands.config.AutoRead { - return m, nil + return nil } current, err := m.commands.store.GetItemByID(*m.selectedArticle) if err != nil { m.selectedArticle = nil - return m, m.list.NewStatusMessage("Error: failed to get article") + return m.list.NewStatusMessage("Error: failed to get article") } err = m.commands.store.ToggleRead(current.ID) if err != nil { m.selectedArticle = nil - return m, m.list.NewStatusMessage("Error marking read") + return m.list.NewStatusMessage("Error marking read") } if !m.commands.config.ShowRead { @@ -232,8 +236,8 @@ func markRead(m model) (tea.Model, tea.Cmd) { content, err := m.commands.GetGlamourisedArticle(*m.selectedArticle) if err != nil { m.selectedArticle = nil - return m, m.list.NewStatusMessage("Error rendering article") + return m.list.NewStatusMessage("Error rendering article") } m.viewport.SetContent(content) - return m, nil + return nil }