diff --git a/internal/client/accounts.go b/internal/client/accounts.go index e2700bf..dfa417c 100644 --- a/internal/client/accounts.go +++ b/internal/client/accounts.go @@ -273,3 +273,40 @@ func (g *Client) UnmuteAccount(accountID string) error { 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 +} diff --git a/internal/executor/flags.go b/internal/executor/flags.go index 1d73ff6..61a5a80 100644 --- a/internal/executor/flags.go +++ b/internal/executor/flags.go @@ -22,6 +22,8 @@ const ( flagEnableLikes = "enable-likes" flagEnableReplies = "enable-replies" flagEnableReposts = "enable-reposts" + flagExcludeBoosts = "exclude-boosts" + flagExcludeReplies = "exclude-replies" flagFrom = "from" flagFromFile = "from-file" flagFull = "full" @@ -36,6 +38,9 @@ const ( flagMuteDuration = "mute-duration" flagMuteNotifications = "mute-notifications" flagNotify = "notify" + flagOnlyMedia = "only-media" + flagOnlyPinned = "only-pinned" + flagOnlyPublic = "only-public" flagPollAllowsMultipleChoices = "poll-allows-multiple-choices" flagPollExpiresIn = "poll-expires-in" flagPollHidesVoteCounts = "poll-hides-vote-counts" @@ -45,6 +50,7 @@ const ( flagSkipRelationship = "skip-relationship" flagShowPreferences = "show-preferences" flagShowReposts = "show-reposts" + flagShowStatuses = "show-statuses" flagSpoilerText = "spoiler-text" flagStatusID = "status-id" flagTag = "tag" diff --git a/internal/executor/show.go b/internal/executor/show.go index 6d2cb3c..6d564d0 100644 --- a/internal/executor/show.go +++ b/internal/executor/show.go @@ -23,9 +23,15 @@ type ShowExecutor struct { printer *printer.Printer config *config.Config myAccount bool - skipAccountRelationship bool - showUserPreferences bool + excludeBoosts bool + excludeReplies bool + onlyMedia bool + onlyPinned bool + onlyPublic bool showInBrowser bool + showUserPreferences bool + showStatuses bool + skipAccountRelationship bool resourceType string accountName 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.showUserPreferences, flagShowPreferences, false, "Show your preferences") 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.accountName, flagAccountName, "", "Specify the account name in full (username@domain)") 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 ( relationship *model.AccountRelationship preferences *model.Preferences + statuses *model.StatusList ) 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 } diff --git a/internal/printer/account.go b/internal/printer/account.go index 1ffef82..daf26e7 100644 --- a/internal/printer/account.go +++ b/internal/printer/account.go @@ -11,7 +11,12 @@ import ( "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 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)) } + if statuses != nil { + builder.WriteString("\n\n" + p.statusList(*statuses)) + } + builder.WriteString("\n\n") p.print(builder.String()) diff --git a/internal/printer/status.go b/internal/printer/status.go index e33dc67..0dc7692 100644 --- a/internal/printer/status.go +++ b/internal/printer/status.go @@ -77,6 +77,10 @@ func (p Printer) PrintStatus(status model.Status) { } func (p Printer) PrintStatusList(list model.StatusList) { + p.print(p.statusList(list)) +} + +func (p Printer) statusList(list model.StatusList) string { var builder strings.Builder builder.WriteString(p.headerFormat(list.Name) + "\n") @@ -170,5 +174,5 @@ func (p Printer) PrintStatusList(list model.StatusList) { builder.WriteString("\n" + p.statusSeparator + "\n") } - p.print(builder.String()) + return builder.String() }