Editing user profile; Warning! Mastodon compatibility broken and editing may lost your bio

This commit is contained in:
localhost_frssoft 2022-11-04 20:55:42 +03:00
parent 53353c0e64
commit 1160d00ee1
6 changed files with 104 additions and 2 deletions

View file

@ -13,6 +13,9 @@ type AccountPleroma struct {
Relationship Relationship `json:"relationship"`
IsAdmin bool `json:"is_admin"`
IsModerator bool `json:"is_moderator"`
IsConfirmed bool `json:"is_confirmed"`
AcceptsChatMessages bool `json:"accepts_chat_messages"`
HideFavourites *bool `json:"hide_favorites"`
}
// Account hold information for mastodon account.
@ -37,6 +40,7 @@ type Account struct {
Fields []Field `json:"fields"`
Bot bool `json:"bot"`
Pleroma *AccountPleroma `json:"pleroma"`
MastodonAccount bool
}
// Field is a Mastodon account profile field.
@ -60,6 +64,7 @@ func (c *Client) GetAccount(ctx context.Context, id string) (*Account, error) {
var account Account
params := url.Values{}
if account.Pleroma != nil {
account.MastodonAccount = false
params.Set("with_relationships", "1")
}
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/accounts/%s", url.PathEscape(string(id))), params, &account, nil)
@ -73,9 +78,16 @@ func (c *Client) GetAccount(ctx context.Context, id string) (*Account, error) {
}
if len(rs) > 0 {
if account.Pleroma != nil {
account.Pleroma = &AccountPleroma{*rs[0], account.Pleroma.IsAdmin, account.Pleroma.IsModerator}
account.Pleroma = &AccountPleroma{*rs[0],
account.Pleroma.IsAdmin,
account.Pleroma.IsModerator,
account.Pleroma.IsConfirmed,
account.Pleroma.AcceptsChatMessages,
account.Pleroma.HideFavourites,
}
} else {
account.Pleroma = &AccountPleroma{*rs[0], false, false}
account.MastodonAccount = true
account.Pleroma = &AccountPleroma{*rs[0], false, false, false, false, nil}
}
}
}
@ -105,6 +117,23 @@ type Profile struct {
// Set the base64 encoded character string of the image.
Avatar string
Header string
//Other settings
Bot *bool
Pleroma *ProfilePleroma
}
type ProfilePleroma struct {
AcceptsChatMessages *bool
ActorType *string
AllowFollowingMove *bool
Discoverable *bool
HideFavourites *bool
HideFollowers *bool
HideFollows *bool
HideFollowersCount *bool
HideFollowsCount *bool
}
// AccountUpdate updates the information of the current user.
@ -142,6 +171,15 @@ func (c *Client) AccountUpdate(ctx context.Context, profile *Profile) (*Account,
if profile.Header != "" {
params.Set("header", profile.Header)
}
if profile.Bot != nil {
params.Set("bot", strconv.FormatBool(*profile.Bot))
}
if profile.Pleroma != nil {
if profile.Pleroma.AcceptsChatMessages != nil {
params.Set("accepts_chat_messages", strconv.FormatBool(*profile.Pleroma.AcceptsChatMessages))
}
}
var account Account
err := c.doAPI(ctx, http.MethodPatch, "/api/v1/accounts/update_credentials", params, &account, nil)