diff --git a/mastodon/status.go b/mastodon/status.go index 67f5ee8..c6cb99e 100644 --- a/mastodon/status.go +++ b/mastodon/status.go @@ -11,8 +11,8 @@ import ( ) type StatusPleroma struct { - InReplyToAccountAcct string `json:"in_reply_to_account_acct"` - Reactions []*ReactionsPleroma `json:"emoji_reactions"` + InReplyToAccountAcct string `json:"in_reply_to_account_acct"` + Reactions []*ReactionsPleroma `json:"emoji_reactions"` } type ReactionsPleroma struct { @@ -186,6 +186,15 @@ func (c *Client) PutReaction(ctx context.Context, id string, emoji string) (*Sta return &status, nil } +// UnReaction is unreaction on status with unicode emoji (Pleroma) +func (c *Client) UnReaction(ctx context.Context, id string, emoji string) (*Status, error) { + var status Status + err := c.doAPI(ctx, http.MethodDelete, fmt.Sprintf("/api/v1/pleroma/statuses/%s/reactions/%s", id, emoji), nil, &status, nil) + if err != nil { + return nil, err + } + return &status, nil +} // Reblog is reblog the toot of id and return status of reblog. func (c *Client) Reblog(ctx context.Context, id string) (*Status, error) { diff --git a/service/service.go b/service/service.go index 5fb57b4..d2cd944 100644 --- a/service/service.go +++ b/service/service.go @@ -1012,6 +1012,15 @@ func (s *service) PutReact(c *client, id string, emoji string) (count int64, err return } +func (s *service) UnReact(c *client, id string, emoji string) (count int64, err error) { + st, err := c.UnReaction(c.ctx, id, emoji) + if err != nil { + return + } + count = st.FavouritesCount + return +} + func (s *service) Retweet(c *client, id string) (count int64, err error) { st, err := c.Reblog(c.ctx, id) if err != nil { diff --git a/service/transport.go b/service/transport.go index 7f57c83..d7006ad 100644 --- a/service/transport.go +++ b/service/transport.go @@ -337,6 +337,18 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { return nil }, CSRF, HTML) + unreact := handle(func(c *client) error { + q := c.r.URL.Query() + emoji := q.Get("emoji") + id, _ := mux.Vars(c.r)["id"] + _, err := s.UnReact(c, id, emoji) + if err != nil { + return err + } + redirect(c, c.r.FormValue("referrer")+"#status-"+id) + return nil + }, CSRF, HTML) + retweet := handle(func(c *client) error { id, _ := mux.Vars(c.r)["id"] @@ -751,6 +763,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { r.HandleFunc("/like/{id}", like).Methods(http.MethodPost) r.HandleFunc("/unlike/{id}", unlike).Methods(http.MethodPost) r.HandleFunc("/react-with/{id}", putreact).Methods(http.MethodPost) + r.HandleFunc("/unreact-with/{id}", unreact).Methods(http.MethodPost) r.HandleFunc("/retweet/{id}", retweet).Methods(http.MethodPost) r.HandleFunc("/unretweet/{id}", unretweet).Methods(http.MethodPost) r.HandleFunc("/vote/{id}", vote).Methods(http.MethodPost) diff --git a/templates/status.tmpl b/templates/status.tmpl index 7a4d7a5..69dafe3 100644 --- a/templates/status.tmpl +++ b/templates/status.tmpl @@ -101,11 +101,19 @@ {{if .Pleroma.Reactions}}
{{range .Pleroma.Reactions}} -
+ {{if .Me}} + - +
+ {{else}} +
+ + + +
+ {{end}} {{end}}
{{end}}