Add unreact and reaction count; added mark self reactions as "*"

This commit is contained in:
localhost_frssoft 2022-10-19 15:47:31 +03:00
parent 4e79142c93
commit 927bd6127c
4 changed files with 43 additions and 4 deletions

View File

@ -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) {

View File

@ -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 {

View File

@ -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)

View File

@ -101,11 +101,19 @@
{{if .Pleroma.Reactions}}
<div class="pleroma-reactions">
{{range .Pleroma.Reactions}}
<form action="/react-with/{{$st_id}}?emoji={{.Name}}" method="post" target="_self" title="Who reacted:&#10;{{range .Accounts}}{{.Acct}}&#10;{{end}}">
{{if .Me}}
<form action="/unreact-with/{{$st_id}}?emoji={{.Name}}" method="post" target="_self">
<input type="hidden" name="csrf_token" value="{{$.Ctx.CSRFToken}}">
<input type="hidden" name="referrer" value="{{$.Ctx.Referrer}}">
<input type="submit" value="{{.Name}}" class="pleroma-emoji">
<input type="submit" value="{{.Name}}{{.Count}}*" class="pleroma-emoji">
</form>
{{else}}
<form action="/react-with/{{$st_id}}?emoji={{.Name}}" method="post" target="_self">
<input type="hidden" name="csrf_token" value="{{$.Ctx.CSRFToken}}">
<input type="hidden" name="referrer" value="{{$.Ctx.Referrer}}">
<input type="submit" value="{{.Name}}{{.Count}}" class="pleroma-emoji">
</form>
{{end}}
{{end}}
</div>
{{end}}