mirror of
https://gitea.phreedom.club/localhost_frssoft/bloat.git
synced 2024-11-26 17:03:01 +00:00
Add unreact and reaction count; added mark self reactions as "*"
This commit is contained in:
parent
4e79142c93
commit
927bd6127c
@ -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) {
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
@ -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: {{range .Accounts}}{{.Acct}} {{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}}
|
||||
|
Loading…
Reference in New Issue
Block a user