diff --git a/mastodon/accounts.go b/mastodon/accounts.go index 19b1714..acf1d04 100644 --- a/mastodon/accounts.go +++ b/mastodon/accounts.go @@ -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) diff --git a/renderer/model.go b/renderer/model.go index a92bae7..a65371f 100644 --- a/renderer/model.go +++ b/renderer/model.go @@ -109,6 +109,11 @@ type UserData struct { NextLink string } +type UserEditData struct { + *CommonData + User *mastodon.Account +} + type UserSearchData struct { *CommonData User *mastodon.Account diff --git a/renderer/renderer.go b/renderer/renderer.go index a4b69f8..a224d43 100644 --- a/renderer/renderer.go +++ b/renderer/renderer.go @@ -34,6 +34,7 @@ const ( RetweetedByPage = "retweetedby.tmpl" SearchPage = "search.tmpl" SettingsPage = "settings.tmpl" + UserEditPage = "useredit.tmpl" FiltersPage = "filters.tmpl" ) diff --git a/service/service.go b/service/service.go index d5ef73f..d057886 100644 --- a/service/service.go +++ b/service/service.go @@ -858,6 +858,19 @@ func (s *service) SearchPage(c *client, return s.renderer.Render(c.rctx, c.w, renderer.SearchPage, data) } +func (s *service) UserEditPage(c *client) (err error) { + cdata := s.cdata(c, "useredit", 0, 0, "") + u, err := c.GetAccountCurrentUser(c.ctx) + if err != nil { + return + } + data := &renderer.UserEditData{ + CommonData: cdata, + User: u, + } + return s.renderer.Render(c.rctx, c.w, renderer.UserEditPage, data) +} + func (s *service) SettingsPage(c *client) (err error) { cdata := s.cdata(c, "settings", 0, 0, "") data := &renderer.SettingsData{ @@ -1141,6 +1154,11 @@ func (s *service) SaveSettings(c *client, settings *model.Settings) (err error) return s.sessionRepo.Add(sess) } +func (s *service) UserSave(c *client, usersettings mastodon.Profile) (err error) { + _, err = c.AccountUpdate(c.ctx, &usersettings) + return +} + func (s *service) MuteConversation(c *client, id string) (err error) { _, err = c.MuteConversation(c.ctx, id) return diff --git a/service/transport.go b/service/transport.go index abc6152..a2dbb6f 100644 --- a/service/transport.go +++ b/service/transport.go @@ -243,6 +243,43 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { return s.SearchPage(c, sq, qType, offset) }, SESSION, HTML) + userEditPage := handle(func(c *client) error { + return s.UserEditPage(c) + }, SESSION, HTML) + + userEdit := handle(func(c *client) error { + displayName := c.r.FormValue("display-name") + note := c.r.FormValue("note") + locked := c.r.FormValue("locked") == "true" + bot := c.r.FormValue("bot") == "true" + acceptsChatMessages := c.r.FormValue("accepts-chat-messages") == "true" + hideFavourites := c.r.FormValue("hide-favourites") == "true" + + pleromaProfile := mastodon.ProfilePleroma{ + AcceptsChatMessages: &acceptsChatMessages, + HideFavourites: &hideFavourites, + } + + usersettings := mastodon.Profile{ + DisplayName: &displayName, + Note: ¬e, + Locked: &locked, + Fields: nil, + Source: nil, + Avatar: "", + Header: "", + Bot: &bot, + Pleroma: &pleromaProfile, + } + + err := s.UserSave(c, usersettings) + if err != nil { + return err + } + redirect(c, "/user/"+c.r.FormValue("id")) + return nil + }, SESSION, HTML) + settingsPage := handle(func(c *client) error { return s.SettingsPage(c) }, SESSION, HTML) @@ -790,6 +827,8 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { r.HandleFunc("/aboutinstance", aboutInstance).Methods(http.MethodGet) r.HandleFunc("/emojis", emojisPage).Methods(http.MethodGet) r.HandleFunc("/search", searchPage).Methods(http.MethodGet) + r.HandleFunc("/useredit", userEditPage).Methods(http.MethodGet) + r.HandleFunc("/useredit", userEdit).Methods(http.MethodPost) r.HandleFunc("/settings", settingsPage).Methods(http.MethodGet) r.HandleFunc("/filters", filtersPage).Methods(http.MethodGet) r.HandleFunc("/signin", signin).Methods(http.MethodPost) diff --git a/templates/user.tmpl b/templates/user.tmpl index 53bf7a0..bdaf974 100644 --- a/templates/user.tmpl +++ b/templates/user.tmpl @@ -125,6 +125,7 @@ - mutes - blocks {{if .User.Locked}}- requests {{end}} + - edit {{end}}