display acct in followers command

This commit is contained in:
Yasuhiro Matsumoto 2017-04-19 23:32:23 +09:00
parent 18d207636a
commit adca356db1
3 changed files with 15 additions and 12 deletions

View File

@ -10,6 +10,8 @@ import (
func cmdFollowers(c *cli.Context) error {
client := c.App.Metadata["client"].(*mastodon.Client)
config := c.App.Metadata["config"].(*mastodon.Config)
account, err := client.GetAccountCurrentUser(context.Background())
if err != nil {
return err
@ -18,8 +20,9 @@ func cmdFollowers(c *cli.Context) error {
if err != nil {
return err
}
s := newScreen(config)
for _, follower := range followers {
fmt.Fprintf(c.App.Writer, "%v,%v\n", follower.ID, follower.Acct)
fmt.Fprintf(c.App.Writer, "%v,%v\n", follower.ID, s.acct(follower.Acct))
}
return nil
}

View File

@ -17,7 +17,7 @@ func TestCmdFollowers(t *testing.T) {
fmt.Fprintln(w, `{"id": 123}`)
return
case "/api/v1/accounts/123/followers":
fmt.Fprintln(w, `[{"id": 234, "username": "zzz"}]`)
fmt.Fprintln(w, `[{"id": 234, "username": "ZZZ", "acct": "zzz"}]`)
return
}
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)

View File

@ -262,13 +262,6 @@ func makeApp() *cli.App {
return app
}
func acct(acct, host string) string {
if !strings.Contains(acct, "@") {
acct += "@" + host
}
return acct
}
type screen struct {
host string
}
@ -282,6 +275,13 @@ func newScreen(config *mastodon.Config) *screen {
return &screen{host}
}
func (s *screen) acct(a string) string {
if !strings.Contains(a, "@") {
a += "@" + s.host
}
return a
}
func (s *screen) displayError(w io.Writer, e error) {
color.Set(color.FgYellow)
fmt.Fprintln(w, e.Error())
@ -291,16 +291,16 @@ func (s *screen) displayError(w io.Writer, e error) {
func (s *screen) displayStatus(w io.Writer, t *mastodon.Status) {
if t.Reblog != nil {
color.Set(color.FgHiRed)
fmt.Fprint(w, acct(t.Account.Acct, s.host))
fmt.Fprint(w, s.acct(t.Account.Acct))
color.Set(color.Reset)
fmt.Fprint(w, " reblogged ")
color.Set(color.FgHiBlue)
fmt.Fprintln(w, acct(t.Reblog.Account.Acct, s.host))
fmt.Fprintln(w, s.acct(t.Reblog.Account.Acct))
fmt.Fprintln(w, textContent(t.Reblog.Content))
color.Set(color.Reset)
} else {
color.Set(color.FgHiRed)
fmt.Fprintln(w, acct(t.Account.Acct, s.host))
fmt.Fprintln(w, s.acct(t.Account.Acct))
color.Set(color.Reset)
fmt.Fprintln(w, textContent(t.Content))
}