cmd/accounts.go
changeset 184 a685b52c2ddf
parent 182 842f6cea448f
child 185 564d92b54b00
equal deleted inserted replaced
183:498d5d188119 184:a685b52c2ddf
    33 	comment               string // For account reports
    33 	comment               string // For account reports
    34 	displayName, note     string // For account update
    34 	displayName, note     string // For account update
    35 	avatar, header        string // For account update
    35 	avatar, header        string // For account update
    36 	locked                bool   // For account update
    36 	locked                bool   // For account update
    37 	muteNotifications     bool   // For account mute
    37 	muteNotifications     bool   // For account mute
       
    38 	following             bool   // For account search
    38 }
    39 }
    39 
    40 
    40 var accountUpdateFlags, accountMuteFlags *flag.FlagSet
    41 var accountUpdateFlags, accountMuteFlags *flag.FlagSet
    41 
    42 
    42 func init() {
    43 func init() {
    62 	accountFollowRequestsSubcommand.Flags().BoolVar(&accountsOpts.list, "list", false, "List pending follow requests")
    63 	accountFollowRequestsSubcommand.Flags().BoolVar(&accountsOpts.list, "list", false, "List pending follow requests")
    63 	accountFollowRequestsSubcommand.Flags().BoolVar(&accountsOpts.acceptFR, "accept", false, "Accept the follow request from the account ID")
    64 	accountFollowRequestsSubcommand.Flags().BoolVar(&accountsOpts.acceptFR, "accept", false, "Accept the follow request from the account ID")
    64 	accountFollowRequestsSubcommand.Flags().BoolVar(&accountsOpts.rejectFR, "reject", false, "Reject the follow request from the account ID")
    65 	accountFollowRequestsSubcommand.Flags().BoolVar(&accountsOpts.rejectFR, "reject", false, "Reject the follow request from the account ID")
    65 
    66 
    66 	accountBlockSubcommand.Flags().BoolVarP(&accountsOpts.unset, "unset", "", false, "Unblock the account")
    67 	accountBlockSubcommand.Flags().BoolVarP(&accountsOpts.unset, "unset", "", false, "Unblock the account")
       
    68 
    67 	accountMuteSubcommand.Flags().BoolVarP(&accountsOpts.unset, "unset", "", false, "Unmute the account")
    69 	accountMuteSubcommand.Flags().BoolVarP(&accountsOpts.unset, "unset", "", false, "Unmute the account")
    68 	accountMuteSubcommand.Flags().BoolVarP(&accountsOpts.muteNotifications, "notifications", "", true, "Mute the notifications")
    70 	accountMuteSubcommand.Flags().BoolVarP(&accountsOpts.muteNotifications, "notifications", "", true, "Mute the notifications")
    69 	accountFollowSubcommand.Flags().BoolVarP(&accountsOpts.unset, "unset", "", false, "Unfollow the account")
    71 	accountFollowSubcommand.Flags().BoolVarP(&accountsOpts.unset, "unset", "", false, "Unfollow the account")
    70 	accountFollowSubcommand.Flags().StringVarP(&accountsOpts.remoteUID, "remote", "r", "", "Follow remote account (user@domain)")
    72 	accountFollowSubcommand.Flags().StringVarP(&accountsOpts.remoteUID, "remote", "r", "", "Follow remote account (user@domain)")
    71 
    73 
    72 	accountRelationshipsSubcommand.Flags().StringVar(&accountsOpts.accountIDs, "account-ids", "", "Comma-separated list of account IDs")
    74 	accountRelationshipsSubcommand.Flags().StringVar(&accountsOpts.accountIDs, "account-ids", "", "Comma-separated list of account IDs")
    73 
    75 
    74 	accountReportsSubcommand.Flags().StringVar(&accountsOpts.statusIDs, "status-ids", "", "Comma-separated list of status IDs")
    76 	accountReportsSubcommand.Flags().StringVar(&accountsOpts.statusIDs, "status-ids", "", "Comma-separated list of status IDs")
    75 	accountReportsSubcommand.Flags().StringVar(&accountsOpts.comment, "comment", "", "Report comment")
    77 	accountReportsSubcommand.Flags().StringVar(&accountsOpts.comment, "comment", "", "Report comment")
    76 	accountReportsSubcommand.Flags().BoolVar(&accountsOpts.list, "list", false, "List current user reports")
    78 	accountReportsSubcommand.Flags().BoolVar(&accountsOpts.list, "list", false, "List current user reports")
       
    79 
       
    80 	accountSearchSubcommand.Flags().BoolVar(&accountsOpts.following, "following", false, "Restrict search to accounts you are following")
    77 
    81 
    78 	accountUpdateSubcommand.Flags().StringVar(&accountsOpts.displayName, "display-name", "", "User display name")
    82 	accountUpdateSubcommand.Flags().StringVar(&accountsOpts.displayName, "display-name", "", "User display name")
    79 	accountUpdateSubcommand.Flags().StringVar(&accountsOpts.note, "note", "", "User note (a.k.a. bio)")
    83 	accountUpdateSubcommand.Flags().StringVar(&accountsOpts.note, "note", "", "User note (a.k.a. bio)")
    80 	accountUpdateSubcommand.Flags().StringVar(&accountsOpts.avatar, "avatar", "", "User avatar image")
    84 	accountUpdateSubcommand.Flags().StringVar(&accountsOpts.avatar, "avatar", "", "User avatar image")
    81 	accountUpdateSubcommand.Flags().StringVar(&accountsOpts.header, "header", "", "User header image")
    85 	accountUpdateSubcommand.Flags().StringVar(&accountsOpts.header, "header", "", "User header image")
   143 		Short:   "Display the user's muted accounts",
   147 		Short:   "Display the user's muted accounts",
   144 		RunE: func(cmd *cobra.Command, args []string) error {
   148 		RunE: func(cmd *cobra.Command, args []string) error {
   145 			return accountSubcommandsRunE(cmd.Name(), args)
   149 			return accountSubcommandsRunE(cmd.Name(), args)
   146 		},
   150 		},
   147 	},
   151 	},
   148 	&cobra.Command{
   152 	accountSearchSubcommand,
   149 		Use:   "search TEXT",
       
   150 		Short: "Search for user accounts",
       
   151 		Long: `Search for user accounts.
       
   152 The server will lookup an account remotely if the search term is in the
       
   153 username@domain format and not yet in the database.`,
       
   154 		RunE: func(cmd *cobra.Command, args []string) error {
       
   155 			return accountSubcommandsRunE(cmd.Name(), args)
       
   156 		},
       
   157 	},
       
   158 	accountStatusesSubcommand,
   153 	accountStatusesSubcommand,
   159 	accountFollowRequestsSubcommand,
   154 	accountFollowRequestsSubcommand,
   160 	accountFollowSubcommand,
   155 	accountFollowSubcommand,
   161 	accountBlockSubcommand,
   156 	accountBlockSubcommand,
   162 	accountMuteSubcommand,
   157 	accountMuteSubcommand,
   163 	accountRelationshipsSubcommand,
   158 	accountRelationshipsSubcommand,
   164 	accountReportsSubcommand,
   159 	accountReportsSubcommand,
   165 	accountUpdateSubcommand,
   160 	accountUpdateSubcommand,
   166 }
   161 }
   167 
   162 
       
   163 var accountSearchSubcommand = &cobra.Command{
       
   164 	Use:   "search TEXT",
       
   165 	Short: "Search for user accounts",
       
   166 	Long: `Search for user accounts.
       
   167 er will lookup an account remotely if the search term is in the
       
   168 @domain format and not yet in the database.`,
       
   169 	RunE: func(cmd *cobra.Command, args []string) error {
       
   170 		return accountSubcommandsRunE(cmd.Name(), args)
       
   171 	},
       
   172 }
       
   173 
   168 var accountStatusesSubcommand = &cobra.Command{
   174 var accountStatusesSubcommand = &cobra.Command{
   169 	Use:     "statuses",
   175 	Use:     "statuses",
   170 	Aliases: []string{"st"},
   176 	Aliases: []string{"st"},
   171 	Short:   "Display the account statuses",
   177 	Short:   "Display the account statuses",
   172 	RunE: func(cmd *cobra.Command, args []string) error {
   178 	RunE: func(cmd *cobra.Command, args []string) error {
   375 			account, err = gClient.GetCurrentAccount()
   381 			account, err = gClient.GetCurrentAccount()
   376 		}
   382 		}
   377 		obj = account
   383 		obj = account
   378 	case "search":
   384 	case "search":
   379 		var accountList []madon.Account
   385 		var accountList []madon.Account
   380 		accountList, err = gClient.SearchAccounts(strings.Join(args, " "), limOpts)
   386 		accountList, err = gClient.SearchAccounts(strings.Join(args, " "), opt.following, limOpts)
   381 		obj = accountList
   387 		obj = accountList
   382 	case "followers":
   388 	case "followers":
   383 		var accountList []madon.Account
   389 		var accountList []madon.Account
   384 		accountList, err = gClient.GetAccountFollowers(opt.accountID, limOpts)
   390 		accountList, err = gClient.GetAccountFollowers(opt.accountID, limOpts)
   385 		if opt.keep > 0 && len(accountList) > int(opt.keep) {
   391 		if opt.keep > 0 && len(accountList) > int(opt.keep) {
   592 		}
   598 		}
   593 	} else {
   599 	} else {
   594 		// Remove leading '@'
   600 		// Remove leading '@'
   595 		user = strings.TrimLeft(user, "@")
   601 		user = strings.TrimLeft(user, "@")
   596 
   602 
   597 		accList, err := gClient.SearchAccounts(user, &madon.LimitParams{Limit: 2})
   603 		accList, err := gClient.SearchAccounts(user, false, &madon.LimitParams{Limit: 2})
   598 		if err != nil {
   604 		if err != nil {
   599 			return 0, err
   605 			return 0, err
   600 		}
   606 		}
   601 		for _, u := range accList {
   607 		for _, u := range accList {
   602 			if u.Acct == user {
   608 			if u.Acct == user {