feat: add support for showing statuses from an account #37

Manually merged
dananglin merged 1 commit from show-statuses-from-account into main 2024-08-01 00:29:02 +01:00
6 changed files with 120 additions and 29 deletions

View file

@ -17,8 +17,7 @@ SPDX-License-Identifier: CC-BY-4.0
- [Switch between accounts](#switch-between-accounts) - [Switch between accounts](#switch-between-accounts)
- [See the account that you are currently logged in as](#see-the-account-that-you-are-currently-logged-in-as) - [See the account that you are currently logged in as](#see-the-account-that-you-are-currently-logged-in-as)
- [Accounts](#accounts) - [Accounts](#accounts)
- [View your own account](#view-your-own-account) - [View account information](#view-account-information)
- [View an account](#view-an-account)
- [Follow an account](#follow-an-account) - [Follow an account](#follow-an-account)
- [Unfollow an account](#unfollow-an-account) - [Unfollow an account](#unfollow-an-account)
- [Show an account's followers](#show-an-accounts-followers) - [Show an account's followers](#show-an-accounts-followers)
@ -135,35 +134,41 @@ enbas whoami
## Accounts ## Accounts
### View your own account ### View account information
Prints the information from your own account. - View information from your own account
```
``` enbas show --type account --my-account
enbas show --type account --my-account ```
``` - View information from a local or remote account.
```
enbas show --type account --account-name @name@example.social
```
- View an account and show the public statuses that it has created.
```
enbas show --type account --account-name @name@example.social --show-statuses --only-public
```
| flag | type | required | description | default | | flag | type | required | description | default |
|------|------|----------|-------------|---------| |------|------|----------|-------------|---------|
| `type` | string | true | The resource you want to view. Here this should be `account`. | | | `type` | string | true | The resource you want to view. Here this should be `account`. | |
| `my-account` | boolean | true | Use this flag to view your own account. | | | `my-account` | boolean | true | Set to `true` to view your own account. | |
| `show-preferences` | boolean | false | Show your posting preferences. | false | | `show-preferences` | boolean | false | Show your posting preferences. Only applicable with the `my-account` flag. | false |
| `account-name` | string | false | The name of the account to view. This is not required with the `my-account` flag. | |
### View an account
Prints the information of a local or a remote account.
If the account is unknown by your instance a `404` message will be shown instead.
```
enbas show --type account --account-name @name@example.social
```
| flag | type | required | description | default |
|------|------|----------|-------------|---------|
| `type` | string | true | The resource you want to view. Here this should be `account`. | |
| `account-name` | string | true | The name of the account to view. | |
| `skip-relationship` | boolean | false | Set to `true` to skip viewing your relationship to the account you are viewing (including the private note if you've created one). | false | | `skip-relationship` | boolean | false | Set to `true` to skip viewing your relationship to the account you are viewing (including the private note if you've created one). | false |
Additional flags for viewing an account's statuses.
| flag | type | required | description | default |
|------|------|----------|-------------|---------|
| `show-statuses` | bool | false | Set to `true` to view the statuses created from this account. | false |
| `limit` | integer | false | The maximum amount of statuses to show from this account. | 20 |
| `exclude-replies` | bool | false | Set to `true` to exclude replies. | false |
| `exclude-boosts` | bool | false | Set to `true` to exclude boosts. | false |
| `only-pinned` | bool | false | Set to `true` to view only pinned statuses. | false |
| `only-media` | bool | false | Set to `true` to view only statuses with media attachments. | false |
| `only-public` | bool | false | Set to `true` to view only public statuses. | false |
### Follow an account ### Follow an account
Sends a follow request to the account you want to follow. Sends a follow request to the account you want to follow.

View file

@ -273,3 +273,40 @@ func (g *Client) UnmuteAccount(accountID string) error {
return nil return nil
} }
type GetAccountStatusesForm struct {
AccountID string
Limit int
ExcludeReplies bool
ExcludeReblogs bool
Pinned bool
OnlyMedia bool
OnlyPublic bool
}
func (g *Client) GetAccountStatuses(form GetAccountStatusesForm) (*model.StatusList, error) {
path := baseAccountsPath + "/" + form.AccountID + "/statuses"
query := fmt.Sprintf(
"?limit=%d&exclude_replies=%t&exclude_reblogs=%t&pinned=%t&only_media=%t&only_public=%t",
form.Limit,
form.ExcludeReplies,
form.ExcludeReblogs,
form.Pinned,
form.OnlyMedia,
form.OnlyPublic,
)
url := g.Authentication.Instance + path + query
var statuses []model.Status
if err := g.sendRequest(http.MethodGet, url, nil, &statuses); err != nil {
return nil, fmt.Errorf("received an error after sending the request to get the account's statuses: %w", err)
}
statusList := model.StatusList{
Name: "STATUSES:",
Statuses: statuses,
}
return &statusList, nil
}

View file

@ -22,6 +22,8 @@ const (
flagEnableLikes = "enable-likes" flagEnableLikes = "enable-likes"
flagEnableReplies = "enable-replies" flagEnableReplies = "enable-replies"
flagEnableReposts = "enable-reposts" flagEnableReposts = "enable-reposts"
flagExcludeBoosts = "exclude-boosts"
flagExcludeReplies = "exclude-replies"
flagFrom = "from" flagFrom = "from"
flagFromFile = "from-file" flagFromFile = "from-file"
flagFull = "full" flagFull = "full"
@ -36,6 +38,9 @@ const (
flagMuteDuration = "mute-duration" flagMuteDuration = "mute-duration"
flagMuteNotifications = "mute-notifications" flagMuteNotifications = "mute-notifications"
flagNotify = "notify" flagNotify = "notify"
flagOnlyMedia = "only-media"
flagOnlyPinned = "only-pinned"
flagOnlyPublic = "only-public"
flagPollAllowsMultipleChoices = "poll-allows-multiple-choices" flagPollAllowsMultipleChoices = "poll-allows-multiple-choices"
flagPollExpiresIn = "poll-expires-in" flagPollExpiresIn = "poll-expires-in"
flagPollHidesVoteCounts = "poll-hides-vote-counts" flagPollHidesVoteCounts = "poll-hides-vote-counts"
@ -45,6 +50,7 @@ const (
flagSkipRelationship = "skip-relationship" flagSkipRelationship = "skip-relationship"
flagShowPreferences = "show-preferences" flagShowPreferences = "show-preferences"
flagShowReposts = "show-reposts" flagShowReposts = "show-reposts"
flagShowStatuses = "show-statuses"
flagSpoilerText = "spoiler-text" flagSpoilerText = "spoiler-text"
flagStatusID = "status-id" flagStatusID = "status-id"
flagTag = "tag" flagTag = "tag"

View file

@ -23,9 +23,15 @@ type ShowExecutor struct {
printer *printer.Printer printer *printer.Printer
config *config.Config config *config.Config
myAccount bool myAccount bool
skipAccountRelationship bool excludeBoosts bool
showUserPreferences bool excludeReplies bool
onlyMedia bool
onlyPinned bool
onlyPublic bool
showInBrowser bool showInBrowser bool
showUserPreferences bool
showStatuses bool
skipAccountRelationship bool
resourceType string resourceType string
accountName string accountName string
statusID string statusID string
@ -50,6 +56,12 @@ func NewShowExecutor(printer *printer.Printer, config *config.Config, name, summ
showExe.BoolVar(&showExe.skipAccountRelationship, flagSkipRelationship, false, "Set to true to skip showing your relationship to the specified account") showExe.BoolVar(&showExe.skipAccountRelationship, flagSkipRelationship, false, "Set to true to skip showing your relationship to the specified account")
showExe.BoolVar(&showExe.showUserPreferences, flagShowPreferences, false, "Show your preferences") showExe.BoolVar(&showExe.showUserPreferences, flagShowPreferences, false, "Show your preferences")
showExe.BoolVar(&showExe.showInBrowser, flagBrowser, false, "Set to true to view in the browser") showExe.BoolVar(&showExe.showInBrowser, flagBrowser, false, "Set to true to view in the browser")
showExe.BoolVar(&showExe.showStatuses, flagShowStatuses, false, "Set to true to view the statuses created from the specified account")
showExe.BoolVar(&showExe.excludeReplies, flagExcludeReplies, false, "Set to true to exclude statuses that are a reply to another status")
showExe.BoolVar(&showExe.excludeBoosts, flagExcludeBoosts, false, "Set to true to exclude statuses that are boosts of another status")
showExe.BoolVar(&showExe.onlyPinned, flagOnlyPinned, false, "Set to true to show only the account's pinned statuses")
showExe.BoolVar(&showExe.onlyMedia, flagOnlyMedia, false, "Set to true to show only the statuses with media attachments")
showExe.BoolVar(&showExe.onlyPublic, flagOnlyPublic, false, "Set to true to show only the account's public posts")
showExe.StringVar(&showExe.resourceType, flagType, "", "Specify the type of resource to display") showExe.StringVar(&showExe.resourceType, flagType, "", "Specify the type of resource to display")
showExe.StringVar(&showExe.accountName, flagAccountName, "", "Specify the account name in full (username@domain)") showExe.StringVar(&showExe.accountName, flagAccountName, "", "Specify the account name in full (username@domain)")
showExe.StringVar(&showExe.statusID, flagStatusID, "", "Specify the ID of the status to display") showExe.StringVar(&showExe.statusID, flagStatusID, "", "Specify the ID of the status to display")
@ -147,6 +159,7 @@ func (s *ShowExecutor) showAccount(gtsClient *client.Client) error {
var ( var (
relationship *model.AccountRelationship relationship *model.AccountRelationship
preferences *model.Preferences preferences *model.Preferences
statuses *model.StatusList
) )
if !s.myAccount && !s.skipAccountRelationship { if !s.myAccount && !s.skipAccountRelationship {
@ -163,7 +176,24 @@ func (s *ShowExecutor) showAccount(gtsClient *client.Client) error {
} }
} }
s.printer.PrintAccount(account, relationship, preferences) if s.showStatuses {
form := client.GetAccountStatusesForm{
AccountID: account.ID,
Limit: s.limit,
ExcludeReplies: s.excludeReplies,
ExcludeReblogs: s.excludeBoosts,
Pinned: s.onlyPinned,
OnlyMedia: s.onlyMedia,
OnlyPublic: s.onlyPublic,
}
statuses, err = gtsClient.GetAccountStatuses(form)
if err != nil {
return fmt.Errorf("unable to retrieve the account's statuses: %w", err)
}
}
s.printer.PrintAccount(account, relationship, preferences, statuses)
return nil return nil
} }

View file

@ -11,7 +11,12 @@ import (
"codeflow.dananglin.me.uk/apollo/enbas/internal/model" "codeflow.dananglin.me.uk/apollo/enbas/internal/model"
) )
func (p Printer) PrintAccount(account model.Account, relationship *model.AccountRelationship, preferences *model.Preferences) { func (p Printer) PrintAccount(
account model.Account,
relationship *model.AccountRelationship,
preferences *model.Preferences,
statuses *model.StatusList,
) {
var builder strings.Builder var builder strings.Builder
builder.WriteString("\n" + p.fullDisplayNameFormat(account.DisplayName, account.Acct)) builder.WriteString("\n" + p.fullDisplayNameFormat(account.DisplayName, account.Acct))
@ -45,6 +50,10 @@ func (p Printer) PrintAccount(account model.Account, relationship *model.Account
builder.WriteString(p.userPreferences(preferences)) builder.WriteString(p.userPreferences(preferences))
} }
if statuses != nil {
builder.WriteString("\n\n" + p.statusList(*statuses))
}
builder.WriteString("\n\n") builder.WriteString("\n\n")
p.print(builder.String()) p.print(builder.String())

View file

@ -77,6 +77,10 @@ func (p Printer) PrintStatus(status model.Status) {
} }
func (p Printer) PrintStatusList(list model.StatusList) { func (p Printer) PrintStatusList(list model.StatusList) {
p.print(p.statusList(list))
}
func (p Printer) statusList(list model.StatusList) string {
var builder strings.Builder var builder strings.Builder
builder.WriteString(p.headerFormat(list.Name) + "\n") builder.WriteString(p.headerFormat(list.Name) + "\n")
@ -170,5 +174,5 @@ func (p Printer) PrintStatusList(list model.StatusList) {
builder.WriteString("\n" + p.statusSeparator + "\n") builder.WriteString("\n" + p.statusSeparator + "\n")
} }
p.print(builder.String()) return builder.String()
} }