1
0
mirror of https://github.com/mrusme/neonmodem.git synced 2024-06-09 06:20:43 +00:00

Implemented Post.URL and o for browser open

This commit is contained in:
マリウス 2023-01-05 15:26:27 -05:00
parent 09a4e7923c
commit a6c29c8677
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F
7 changed files with 49 additions and 2 deletions

View File

@ -28,6 +28,8 @@ type Post struct {
Replies []reply.Reply
URL string
SysIDX int
}

View File

@ -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,
})
}

View File

@ -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,
})
}

View File

@ -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,
})
}

View File

@ -175,6 +175,8 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) {
SysIDX: sys.ID,
},
URL: i.ShortIDURL,
SysIDX: sys.ID,
})
}

View File

@ -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

View File

@ -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,