mirror of
https://github.com/mrusme/neonmodem.git
synced 2024-12-04 14:46:37 -05:00
Implemented Post.URL and o
for browser open
This commit is contained in:
parent
09a4e7923c
commit
a6c29c8677
@ -28,6 +28,8 @@ type Post struct {
|
|||||||
|
|
||||||
Replies []reply.Reply
|
Replies []reply.Reply
|
||||||
|
|
||||||
|
URL string
|
||||||
|
|
||||||
SysIDX int
|
SysIDX int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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{
|
models = append(models, post.Post{
|
||||||
ID: strconv.Itoa(i.ID),
|
ID: strconv.Itoa(i.ID),
|
||||||
|
|
||||||
@ -227,6 +230,8 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) {
|
|||||||
SysIDX: sys.ID,
|
SysIDX: sys.ID,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
URL: fmt.Sprintf("%s/t/%d", baseURL, i.ID),
|
||||||
|
|
||||||
SysIDX: sys.ID,
|
SysIDX: sys.ID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -214,6 +214,8 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) {
|
|||||||
|
|
||||||
Replies: replies,
|
Replies: replies,
|
||||||
|
|
||||||
|
URL: fmt.Sprintf("https://news.ycombinator.com/item?id=%d", i.ID),
|
||||||
|
|
||||||
SysIDX: sys.ID,
|
SysIDX: sys.ID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -167,6 +167,9 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) {
|
|||||||
return []post.Post{}, err
|
return []post.Post{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg := sys.GetConfig()
|
||||||
|
baseURL := cfg["url"].(string)
|
||||||
|
|
||||||
var models []post.Post
|
var models []post.Post
|
||||||
for _, i := range resp.Posts {
|
for _, i := range resp.Posts {
|
||||||
t := "post"
|
t := "post"
|
||||||
@ -211,6 +214,8 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) {
|
|||||||
SysIDX: sys.ID,
|
SysIDX: sys.ID,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
URL: fmt.Sprintf("%s/post/%d", baseURL, i.Post.ID),
|
||||||
|
|
||||||
SysIDX: sys.ID,
|
SysIDX: sys.ID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -175,6 +175,8 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) {
|
|||||||
SysIDX: sys.ID,
|
SysIDX: sys.ID,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
URL: i.ShortIDURL,
|
||||||
|
|
||||||
SysIDX: sys.ID,
|
SysIDX: sys.ID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/mrusme/gobbs/models/post"
|
"github.com/mrusme/gobbs/models/post"
|
||||||
"github.com/mrusme/gobbs/ui/cmd"
|
"github.com/mrusme/gobbs/ui/cmd"
|
||||||
"github.com/mrusme/gobbs/ui/windows/postcreate"
|
"github.com/mrusme/gobbs/ui/windows/postcreate"
|
||||||
|
"github.com/pkg/browser"
|
||||||
)
|
)
|
||||||
|
|
||||||
func handleReply(mi interface{}) (bool, []tea.Cmd) {
|
func handleReply(mi interface{}) (bool, []tea.Cmd) {
|
||||||
@ -25,8 +26,12 @@ func handleReply(mi interface{}) (bool, []tea.Cmd) {
|
|||||||
cmd.MsgError,
|
cmd.MsgError,
|
||||||
WIN_ID,
|
WIN_ID,
|
||||||
cmd.Arg{
|
cmd.Arg{
|
||||||
Name: "error",
|
Name: "error",
|
||||||
Value: errors.New("This system doesn't support replies yet!"),
|
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())
|
).Tea())
|
||||||
return true, cmds
|
return true, cmds
|
||||||
@ -84,6 +89,27 @@ func handleReply(mi interface{}) (bool, []tea.Cmd) {
|
|||||||
return true, cmds
|
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) {
|
func handleNumberKeys(mi interface{}, n int8) (bool, []tea.Cmd) {
|
||||||
var m *Model = mi.(*Model)
|
var m *Model = mi.(*Model)
|
||||||
var cmds []tea.Cmd
|
var cmds []tea.Cmd
|
||||||
|
@ -60,6 +60,7 @@ func NewModel(c *ctx.Ctx) Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
m.tk.KeymapAdd("reply", "reply (prefix with #, e.g. '2r')", "r")
|
m.tk.KeymapAdd("reply", "reply (prefix with #, e.g. '2r')", "r")
|
||||||
|
m.tk.KeymapAdd("open", "open", "o")
|
||||||
|
|
||||||
m.a, _ = aggregator.New(m.ctx)
|
m.a, _ = aggregator.New(m.ctx)
|
||||||
|
|
||||||
@ -70,6 +71,10 @@ func NewModel(c *ctx.Ctx) Model {
|
|||||||
ID: "reply",
|
ID: "reply",
|
||||||
Handler: handleReply,
|
Handler: handleReply,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
ID: "open",
|
||||||
|
Handler: handleOpen,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
OnAnyNumberKey: handleNumberKeys,
|
OnAnyNumberKey: handleNumberKeys,
|
||||||
OnAnyUncaughtKey: handleUncaughtKeys,
|
OnAnyUncaughtKey: handleUncaughtKeys,
|
||||||
|
Loading…
Reference in New Issue
Block a user