2017-04-15 14:52:11 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-04-17 04:10:29 +02:00
|
|
|
"context"
|
2017-04-15 14:52:11 +02:00
|
|
|
"fmt"
|
2017-04-19 13:52:14 +02:00
|
|
|
"net/url"
|
|
|
|
"strings"
|
2017-04-15 14:52:11 +02:00
|
|
|
|
|
|
|
"github.com/fatih/color"
|
|
|
|
"github.com/mattn/go-mastodon"
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
2017-04-19 13:52:14 +02:00
|
|
|
func acct(acct, host string) string {
|
|
|
|
if !strings.Contains(acct, "@") {
|
|
|
|
acct += "@" + host
|
|
|
|
}
|
|
|
|
return acct
|
|
|
|
}
|
|
|
|
|
2017-04-15 14:52:11 +02:00
|
|
|
func cmdTimeline(c *cli.Context) error {
|
|
|
|
client := c.App.Metadata["client"].(*mastodon.Client)
|
2017-04-19 13:52:14 +02:00
|
|
|
config := c.App.Metadata["config"].(*mastodon.Config)
|
2017-04-17 04:10:29 +02:00
|
|
|
timeline, err := client.GetTimelineHome(context.Background())
|
2017-04-15 14:52:11 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-04-19 13:52:14 +02:00
|
|
|
u, err := url.Parse(config.Server)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-04-15 14:52:11 +02:00
|
|
|
for i := len(timeline) - 1; i >= 0; i-- {
|
|
|
|
t := timeline[i]
|
2017-04-19 13:52:14 +02:00
|
|
|
if t.Reblog != nil {
|
|
|
|
color.Set(color.FgHiRed)
|
|
|
|
fmt.Fprint(c.App.Writer, acct(t.Account.Acct, u.Host))
|
|
|
|
color.Set(color.Reset)
|
|
|
|
fmt.Fprint(c.App.Writer, " rebloged ")
|
|
|
|
color.Set(color.FgHiBlue)
|
|
|
|
fmt.Fprintln(c.App.Writer, acct(t.Reblog.Account.Acct, u.Host))
|
|
|
|
fmt.Fprintln(c.App.Writer, textContent(t.Reblog.Content))
|
|
|
|
color.Set(color.Reset)
|
|
|
|
} else {
|
|
|
|
color.Set(color.FgHiRed)
|
|
|
|
fmt.Fprintln(c.App.Writer, acct(t.Account.Acct, u.Host))
|
|
|
|
color.Set(color.Reset)
|
|
|
|
fmt.Fprintln(c.App.Writer, textContent(t.Content))
|
|
|
|
}
|
2017-04-15 14:52:11 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|