diff --git a/mastodon/accounts.go b/mastodon/accounts.go index 76b72b6..b98735f 100644 --- a/mastodon/accounts.go +++ b/mastodon/accounts.go @@ -131,10 +131,7 @@ func RegisterAccount(ctx context.Context, instance string, reason string, userna 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") - } + params.Set("with_relationships", strconv.FormatBool(true)) err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/accounts/%s", url.PathEscape(string(id))), params, &account, nil) if err != nil { return nil, err @@ -361,11 +358,10 @@ func (c *Client) AccountUnblock(ctx context.Context, id string) (*Relationship, } // AccountMute mute the account. -func (c *Client) AccountMute(ctx context.Context, id string, notifications *bool) (*Relationship, error) { +func (c *Client) AccountMute(ctx context.Context, id string, notifications bool, duration int) (*Relationship, error) { params := url.Values{} - if notifications != nil { - params.Set("notifications", strconv.FormatBool(*notifications)) - } + params.Set("notifications", strconv.FormatBool(notifications)) + params.Set("duration", strconv.Itoa(duration)) var relationship Relationship err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/accounts/%s/mute", url.PathEscape(string(id))), params, &relationship, nil) if err != nil { diff --git a/mastodon/status.go b/mastodon/status.go index 1bdb3e9..e148720 100644 --- a/mastodon/status.go +++ b/mastodon/status.go @@ -72,7 +72,6 @@ type Status struct { MediaAttachments []Attachment `json:"media_attachments"` Mentions []Mention `json:"mentions"` Tags []Tag `json:"tags"` - Card *Card `json:"card"` Application Application `json:"application"` Language string `json:"language"` Pinned interface{} `json:"pinned"` @@ -93,22 +92,6 @@ type Context struct { Descendants []*Status `json:"descendants"` } -// Card hold information for mastodon card. -type Card struct { - URL string `json:"url"` - Title string `json:"title"` - Description string `json:"description"` - Image string `json:"image"` - Type string `json:"type"` - AuthorName string `json:"author_name"` - AuthorURL string `json:"author_url"` - ProviderName string `json:"provider_name"` - ProviderURL string `json:"provider_url"` - HTML string `json:"html"` - Width int64 `json:"width"` - Height int64 `json:"height"` -} - // GetFavourites return the favorite list of the current user. func (c *Client) GetFavourites(ctx context.Context, pg *Pagination) ([]*Status, error) { var statuses []*Status @@ -139,16 +122,6 @@ func (c *Client) GetStatusContext(ctx context.Context, id string) (*Context, err return &context, nil } -// GetStatusCard return status specified by id. -func (c *Client) GetStatusCard(ctx context.Context, id string) (*Card, error) { - var card Card - err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/statuses/%s/card", id), nil, &card, nil) - if err != nil { - return nil, err - } - return &card, nil -} - // GetRebloggedBy returns the account list of the user who reblogged the toot of id. func (c *Client) GetRebloggedBy(ctx context.Context, id string, pg *Pagination) ([]*Account, error) { var accounts []*Account diff --git a/renderer/model.go b/renderer/model.go index a65371f..c636571 100644 --- a/renderer/model.go +++ b/renderer/model.go @@ -176,3 +176,8 @@ type FiltersData struct { *CommonData Filters []*mastodon.Filter } + +type MuteData struct { + *CommonData + User *mastodon.Account +} diff --git a/renderer/renderer.go b/renderer/renderer.go index a224d43..3e95a7d 100644 --- a/renderer/renderer.go +++ b/renderer/renderer.go @@ -36,6 +36,7 @@ const ( SettingsPage = "settings.tmpl" UserEditPage = "useredit.tmpl" FiltersPage = "filters.tmpl" + MutePage = "mute.tmpl" ) type TemplateData struct { diff --git a/service/service.go b/service/service.go index c284597..4643dae 100644 --- a/service/service.go +++ b/service/service.go @@ -734,6 +734,19 @@ func (s *service) UserSearchPage(c *client, return s.renderer.Render(c.rctx, c.w, renderer.UserSearchPage, data) } +func (s *service) MutePage(c *client, id string) (err error) { + user, err := c.GetAccount(c.ctx, id) + if err != nil { + return + } + cdata := s.cdata(c, "Mute"+user.DisplayName+" @"+user.Acct, 0, 0, "") + data := &renderer.UserData{ + User: user, + CommonData: cdata, + } + return s.renderer.Render(c.rctx, c.w, renderer.MutePage, data) +} + func (s *service) AboutPage(c *client) (err error) { cdata := s.cdata(c, "about", 0, 0, "") data := &renderer.AboutData{ @@ -1104,8 +1117,8 @@ func (s *service) Reject(c *client, id string) (err error) { return c.FollowRequestReject(c.ctx, id) } -func (s *service) Mute(c *client, id string, notifications *bool) (err error) { - _, err = c.AccountMute(c.ctx, id, notifications) +func (s *service) Mute(c *client, id string, notifications bool, duration int) (err error) { + _, err = c.AccountMute(c.ctx, id, notifications, duration) return } diff --git a/service/transport.go b/service/transport.go index 6b9250c..ccec389 100644 --- a/service/transport.go +++ b/service/transport.go @@ -178,6 +178,11 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { return s.UserSearchPage(c, id, sq, offset) }, SESSION, HTML) + mutePage := handle(func(c *client) error { + id, _ := mux.Vars(c.r)["id"] + return s.MutePage(c, id) + }, SESSION, HTML) + aboutPage := handle(func(c *client) error { return s.AboutPage(c) }, SESSION, HTML) @@ -467,17 +472,13 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { mute := handle(func(c *client) error { id, _ := mux.Vars(c.r)["id"] - q := c.r.URL.Query() - var notifications *bool - if r, ok := q["notifications"]; ok && len(r) > 0 { - notifications = new(bool) - *notifications = r[0] == "true" - } - err := s.Mute(c, id, notifications) + notifications, _ := strconv.ParseBool(c.r.FormValue("notifications")) + duration, _ := strconv.Atoi(c.r.FormValue("duration")) + err := s.Mute(c, id, notifications, duration) if err != nil { return err } - c.redirect(c.r.FormValue("referrer")) + c.redirect("/user/" + id) return nil }, CSRF, HTML) @@ -805,6 +806,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { r.HandleFunc("/user/{id}", userPage).Methods(http.MethodGet) r.HandleFunc("/user/{id}/{type}", userPage).Methods(http.MethodGet) r.HandleFunc("/usersearch/{id}", userSearchPage).Methods(http.MethodGet) + r.HandleFunc("/mute/{id}", mutePage).Methods(http.MethodGet) r.HandleFunc("/about", aboutPage).Methods(http.MethodGet) r.HandleFunc("/aboutinstance", aboutInstance).Methods(http.MethodGet) r.HandleFunc("/emojis", emojisPage).Methods(http.MethodGet) diff --git a/templates/mute.tmpl b/templates/mute.tmpl new file mode 100644 index 0000000..47d0533 --- /dev/null +++ b/templates/mute.tmpl @@ -0,0 +1,29 @@ +{{with .Data}} +{{template "header.tmpl" (WithContext .CommonData $.Ctx)}} +
Mute {{.User.Acct}}
+ +
+ + +
+ + +
+
+ + +
+ +
+ +{{template "footer.tmpl"}} +{{end}} diff --git a/templates/user.tmpl b/templates/user.tmpl index afebd9f..e520405 100644 --- a/templates/user.tmpl +++ b/templates/user.tmpl @@ -81,17 +81,7 @@ {{else}} -
- - - -
- - -
- - - -
+ mute {{end}} {{if .User.Pleroma.Relationship.Following}} - @@ -144,7 +134,7 @@ {{if .User.Fields}}
{{range .User.Fields}} -
{{.Name}} - {{EmojiFilter .Value $.Data.User.Emojis | Raw}}
+
{{EmojiFilter .Name $.Data.User.Emojis | Raw}} - {{EmojiFilter .Value $.Data.User.Emojis | Raw}}
{{end}}
{{end}}