FEATURE: Pleroma reactions implemented partially

This commit is contained in:
localhost_frssoft 2022-10-17 20:01:11 +03:00
parent 0cd239b8aa
commit f452fab462
5 changed files with 75 additions and 6 deletions

View file

@ -167,7 +167,8 @@ func (s *service) TimelinePage(c *client, tType, instance, listId, maxID,
minID string, tag string) (err error) {
var nextLink, prevLink, title string
var statuses []*mastodon.Status
var statuses []*mastodon.Status
var reactions []*mastodon.ReactionsPleroma
var pg = mastodon.Pagination{
MaxID: maxID,
MinID: minID,
@ -232,6 +233,17 @@ func (s *service) TimelinePage(c *client, tType, instance, listId, maxID,
if statuses[i].Reblog != nil {
statuses[i].Reblog.RetweetedByID = statuses[i].ID
}
if statuses[i].Pleroma.Reactions == nil && statuses[i].Account.Pleroma != nil {
if statuses[i].Reblog != nil {
reactions, err = c.GetReactedBy(c.ctx, statuses[i].Reblog.ID)
} else {
reactions, err = c.GetReactedBy(c.ctx, statuses[i].ID)
}
if err != nil {
return err
}
statuses[i].Pleroma.Reactions = reactions
}
}
if (len(maxID) > 0 || len(minID) > 0) && len(statuses) > 0 {
@ -991,6 +1003,15 @@ func (s *service) UnLike(c *client, id string) (count int64, err error) {
return
}
func (s *service) PutReact(c *client, id string, emoji string) (count int64, err error) {
st, err := c.PutReaction(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

@ -325,6 +325,19 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
return nil
}, CSRF, HTML)
putreact := handle(func(c *client) error {
q := c.r.URL.Query()
emoji := q.Get("emoji")
id, _ := mux.Vars(c.r)["id"]
_, err := s.PutReact(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"]
rid := c.r.FormValue("retweeted_by_id")
@ -737,6 +750,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
r.HandleFunc("/post", post).Methods(http.MethodPost)
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("/retweet/{id}", retweet).Methods(http.MethodPost)
r.HandleFunc("/unretweet/{id}", unretweet).Methods(http.MethodPost)
r.HandleFunc("/vote/{id}", vote).Methods(http.MethodPost)