parent
3268207afe
commit
559ed99cdf
5 changed files with 125 additions and 3 deletions
|
@ -20,3 +20,49 @@ func cmdTimeline(c *cli.Context) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func cmdTimelineHome(c *cli.Context) error {
|
||||
return cmdTimeline(c)
|
||||
}
|
||||
|
||||
func cmdTimelinePublic(c *cli.Context) error {
|
||||
client := c.App.Metadata["client"].(*mastodon.Client)
|
||||
config := c.App.Metadata["config"].(*mastodon.Config)
|
||||
timeline, err := client.GetTimelinePublic(context.Background(), false, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s := newScreen(config)
|
||||
for i := len(timeline) - 1; i >= 0; i-- {
|
||||
s.displayStatus(c.App.Writer, timeline[i])
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func cmdTimelineLocal(c *cli.Context) error {
|
||||
client := c.App.Metadata["client"].(*mastodon.Client)
|
||||
config := c.App.Metadata["config"].(*mastodon.Config)
|
||||
timeline, err := client.GetTimelinePublic(context.Background(), true, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s := newScreen(config)
|
||||
for i := len(timeline) - 1; i >= 0; i-- {
|
||||
s.displayStatus(c.App.Writer, timeline[i])
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func cmdTimelineDirect(c *cli.Context) error {
|
||||
client := c.App.Metadata["client"].(*mastodon.Client)
|
||||
config := c.App.Metadata["config"].(*mastodon.Config)
|
||||
timeline, err := client.GetTimelineDirect(context.Background(), nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s := newScreen(config)
|
||||
for i := len(timeline) - 1; i >= 0; i-- {
|
||||
s.displayStatus(c.App.Writer, timeline[i])
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -14,7 +14,13 @@ func TestCmdTimeline(t *testing.T) {
|
|||
func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.URL.Path {
|
||||
case "/api/v1/timelines/home":
|
||||
fmt.Fprintln(w, `[{"content": "zzz"}]`)
|
||||
fmt.Fprintln(w, `[{"content": "home"}]`)
|
||||
return
|
||||
case "/api/v1/timelines/public":
|
||||
fmt.Fprintln(w, `[{"content": "public"}]`)
|
||||
return
|
||||
case "/api/v1/timelines/direct":
|
||||
fmt.Fprintln(w, `[{"content": "direct"}]`)
|
||||
return
|
||||
}
|
||||
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
||||
|
@ -22,9 +28,25 @@ func TestCmdTimeline(t *testing.T) {
|
|||
},
|
||||
func(app *cli.App) {
|
||||
app.Run([]string{"mstdn", "timeline"})
|
||||
app.Run([]string{"mstdn", "timeline-home"})
|
||||
app.Run([]string{"mstdn", "timeline-public"})
|
||||
app.Run([]string{"mstdn", "timeline-local"})
|
||||
app.Run([]string{"mstdn", "timeline-direct"})
|
||||
},
|
||||
)
|
||||
if !strings.Contains(out, "zzz") {
|
||||
t.Fatalf("%q should be contained in output of command: %v", "zzz", out)
|
||||
want := strings.Join([]string{
|
||||
"@example.com",
|
||||
"home",
|
||||
"@example.com",
|
||||
"home",
|
||||
"@example.com",
|
||||
"public",
|
||||
"@example.com",
|
||||
"public",
|
||||
"@example.com",
|
||||
"direct",
|
||||
}, "\n") + "\n"
|
||||
if !strings.Contains(out, want) {
|
||||
t.Fatalf("%q should be contained in output of command: %v", want, out)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -235,6 +235,26 @@ func makeApp() *cli.App {
|
|||
Usage: "show timeline",
|
||||
Action: cmdTimeline,
|
||||
},
|
||||
{
|
||||
Name: "timeline-home",
|
||||
Usage: "show timeline home",
|
||||
Action: cmdTimelineHome,
|
||||
},
|
||||
{
|
||||
Name: "timeline-local",
|
||||
Usage: "show timeline local",
|
||||
Action: cmdTimelineLocal,
|
||||
},
|
||||
{
|
||||
Name: "timeline-public",
|
||||
Usage: "show timeline public",
|
||||
Action: cmdTimelinePublic,
|
||||
},
|
||||
{
|
||||
Name: "timeline-direct",
|
||||
Usage: "show timeline direct",
|
||||
Action: cmdTimelineDirect,
|
||||
},
|
||||
{
|
||||
Name: "notification",
|
||||
Usage: "show notification",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue