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

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