feat: show user preferences
Optionally show the user's preferences when viewing account.
This commit is contained in:
parent
de5cf65aa8
commit
a77f3741a0
4 changed files with 84 additions and 19 deletions
|
@ -28,6 +28,8 @@ const (
|
|||
toAccountFlag = "to-account"
|
||||
showRepostsFlag = "show-reposts"
|
||||
notifyFlag = "notify"
|
||||
showAccountRelationshipFlag = "show-account-relationship"
|
||||
showUserPreferencesFlag = "show-preferences"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -13,6 +13,7 @@ type showCommand struct {
|
|||
*flag.FlagSet
|
||||
myAccount bool
|
||||
showAccountRelationship bool
|
||||
showUserPreferences bool
|
||||
resourceType string
|
||||
account string
|
||||
accountID string
|
||||
|
@ -29,7 +30,8 @@ func newShowCommand(name, summary string) *showCommand {
|
|||
}
|
||||
|
||||
command.BoolVar(&command.myAccount, myAccountFlag, false, "set to true to lookup your account")
|
||||
command.BoolVar(&command.showAccountRelationship, "show-account-relationship", false, "show your relationship to the specified account")
|
||||
command.BoolVar(&command.showAccountRelationship, showAccountRelationshipFlag, false, "show your relationship to the specified account")
|
||||
command.BoolVar(&command.showUserPreferences, showUserPreferencesFlag, false, "show your preferences")
|
||||
command.StringVar(&command.resourceType, resourceTypeFlag, "", "specify the type of resource to display")
|
||||
command.StringVar(&command.account, accountFlag, "", "specify the account URI to lookup")
|
||||
command.StringVar(&command.accountID, accountIDFlag, "", "specify the account ID")
|
||||
|
@ -109,7 +111,7 @@ func (c *showCommand) showAccount(gts *client.Client) error {
|
|||
|
||||
fmt.Println(account)
|
||||
|
||||
if c.showAccountRelationship {
|
||||
if !c.myAccount && c.showAccountRelationship {
|
||||
relationship, err := gts.GetAccountRelationship(account.ID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to retrieve the relationship to this account; %w", err)
|
||||
|
@ -118,6 +120,15 @@ func (c *showCommand) showAccount(gts *client.Client) error {
|
|||
fmt.Println(relationship)
|
||||
}
|
||||
|
||||
if c.myAccount && c.showUserPreferences {
|
||||
preferences, err := gts.GetUserPreferences()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to retrieve the user preferences; %w", err)
|
||||
}
|
||||
|
||||
fmt.Println(preferences)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
20
internal/client/preferences.go
Normal file
20
internal/client/preferences.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/model"
|
||||
)
|
||||
|
||||
func (g *Client) GetUserPreferences() (model.Preferences, error) {
|
||||
url := g.Authentication.Instance + "/api/v1/preferences"
|
||||
|
||||
var preferences model.Preferences
|
||||
|
||||
if err := g.sendRequest(http.MethodGet, url, nil, &preferences); err != nil {
|
||||
return model.Preferences{}, fmt.Errorf("received an error after sending the request to get the user preferences; %w", err)
|
||||
}
|
||||
|
||||
return preferences, nil
|
||||
}
|
32
internal/model/preferences.go
Normal file
32
internal/model/preferences.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/utilities"
|
||||
)
|
||||
|
||||
type Preferences struct {
|
||||
PostingDefaultVisibility string `json:"posting:default:visibility"`
|
||||
PostingDefaultSensitive bool `json:"posting:default:sensitive"`
|
||||
PostingDefaultLanguage string `json:"posting:default:language"`
|
||||
ReadingExpandMedia string `json:"reading:expand:media"`
|
||||
ReadingExpandSpoilers bool `json:"reading:expand:spoilers"`
|
||||
ReadingAutoplayGifs bool `json:"reading:autoplay:gifs"`
|
||||
}
|
||||
|
||||
func (p Preferences) String() string {
|
||||
format := `
|
||||
%s
|
||||
%s: %s
|
||||
%s: %s
|
||||
%s: %t`
|
||||
|
||||
return fmt.Sprintf(
|
||||
format,
|
||||
utilities.HeaderFormat("YOUR PREFERENCES:"),
|
||||
utilities.FieldFormat("Default post language"), p.PostingDefaultLanguage,
|
||||
utilities.FieldFormat("Default post visibility"), p.PostingDefaultVisibility,
|
||||
utilities.FieldFormat("Mark posts as sensitive by default"), p.PostingDefaultSensitive,
|
||||
)
|
||||
}
|
Loading…
Reference in a new issue