diff --git a/models/post/post.go b/models/post/post.go index 982c748..5ef2166 100644 --- a/models/post/post.go +++ b/models/post/post.go @@ -28,6 +28,8 @@ type Post struct { Replies []reply.Reply + URL string + SysIDX int } diff --git a/system/discourse/discourse.go b/system/discourse/discourse.go index 62b6ba9..076c64c 100644 --- a/system/discourse/discourse.go +++ b/system/discourse/discourse.go @@ -202,6 +202,9 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) { } } + cfg := sys.GetConfig() + baseURL := cfg["url"].(string) + models = append(models, post.Post{ ID: strconv.Itoa(i.ID), @@ -227,6 +230,8 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) { SysIDX: sys.ID, }, + URL: fmt.Sprintf("%s/t/%d", baseURL, i.ID), + SysIDX: sys.ID, }) } diff --git a/system/hackernews/hackernews.go b/system/hackernews/hackernews.go index 8fc1d5e..26a5e62 100644 --- a/system/hackernews/hackernews.go +++ b/system/hackernews/hackernews.go @@ -214,6 +214,8 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) { Replies: replies, + URL: fmt.Sprintf("https://news.ycombinator.com/item?id=%d", i.ID), + SysIDX: sys.ID, }) } diff --git a/system/lemmy/lemmy.go b/system/lemmy/lemmy.go index 22585d1..f94ed14 100644 --- a/system/lemmy/lemmy.go +++ b/system/lemmy/lemmy.go @@ -167,6 +167,9 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) { return []post.Post{}, err } + cfg := sys.GetConfig() + baseURL := cfg["url"].(string) + var models []post.Post for _, i := range resp.Posts { t := "post" @@ -211,6 +214,8 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) { SysIDX: sys.ID, }, + 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 64146d6..997b641 100644 --- a/system/lobsters/lobsters.go +++ b/system/lobsters/lobsters.go @@ -175,6 +175,8 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) { SysIDX: sys.ID, }, + URL: i.ShortIDURL, + SysIDX: sys.ID, }) } diff --git a/ui/windows/postshow/handlers.go b/ui/windows/postshow/handlers.go index 5311fb6..262060c 100644 --- a/ui/windows/postshow/handlers.go +++ b/ui/windows/postshow/handlers.go @@ -9,6 +9,7 @@ import ( "github.com/mrusme/gobbs/models/post" "github.com/mrusme/gobbs/ui/cmd" "github.com/mrusme/gobbs/ui/windows/postcreate" + "github.com/pkg/browser" ) func handleReply(mi interface{}) (bool, []tea.Cmd) { @@ -25,8 +26,12 @@ func handleReply(mi interface{}) (bool, []tea.Cmd) { cmd.MsgError, WIN_ID, cmd.Arg{ - Name: "error", - Value: errors.New("This system doesn't support replies yet!"), + Name: "error", + Value: errors.New( + "This system doesn't support replies yet!\n" + + "However, you can use `o` to open this post in your browser and " + + "reply there!", + ), }, ).Tea()) return true, cmds @@ -84,6 +89,27 @@ func handleReply(mi interface{}) (bool, []tea.Cmd) { return true, cmds } +func handleOpen(mi interface{}) (bool, []tea.Cmd) { + var m *Model = mi.(*Model) + var cmds []tea.Cmd + + openURL := m.activePost.URL + if err := browser.OpenURL(openURL); err != nil { + m.ctx.Logger.Error(err) + cmds = append(cmds, cmd.New( + cmd.MsgError, + WIN_ID, + cmd.Arg{ + Name: "error", + Value: err, + }, + ).Tea()) + return true, cmds + } + + 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 d3a84a5..f96f24c 100644 --- a/ui/windows/postshow/postshow.go +++ b/ui/windows/postshow/postshow.go @@ -60,6 +60,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.a, _ = aggregator.New(m.ctx) @@ -70,6 +71,10 @@ func NewModel(c *ctx.Ctx) Model { ID: "reply", Handler: handleReply, }, + { + ID: "open", + Handler: handleOpen, + }, }, OnAnyNumberKey: handleNumberKeys, OnAnyUncaughtKey: handleUncaughtKeys,