mirror of
https://gitea.phreedom.club/localhost_frssoft/bloat.git
synced 2024-12-24 14:39:48 +00:00
FEATURE: Pleroma reactions implemented partially
This commit is contained in:
parent
0cd239b8aa
commit
f452fab462
@ -12,6 +12,14 @@ import (
|
||||
|
||||
type StatusPleroma struct {
|
||||
InReplyToAccountAcct string `json:"in_reply_to_account_acct"`
|
||||
Reactions []*ReactionsPleroma
|
||||
}
|
||||
|
||||
type ReactionsPleroma struct {
|
||||
Accounts []Account `json:"accounts"`
|
||||
Count int `json:"count"`
|
||||
Me bool `json:"me"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type ReplyInfo struct {
|
||||
@ -158,14 +166,24 @@ func (c *Client) GetFavouritedBy(ctx context.Context, id string, pg *Pagination)
|
||||
return accounts, nil
|
||||
}
|
||||
|
||||
// GetReactionBy returns the account list of the user who reacted the toot of id. (Pleroma)
|
||||
func (c *Client) GetReactedBy(ctx context.Context, id string, pg *Pagination) ([]*Account, error) {
|
||||
var accounts []*Account
|
||||
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/pleroma/statuses/%s/reactions", id), nil, &accounts, pg)
|
||||
// GetReactionBy returns the reactions list of the user who reacted the toot of id. (Pleroma)
|
||||
func (c *Client) GetReactedBy(ctx context.Context, id string) ([]*ReactionsPleroma, error) {
|
||||
var reactions []*ReactionsPleroma
|
||||
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/pleroma/statuses/%s/reactions", id), nil, &reactions, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return accounts, nil
|
||||
return reactions, nil
|
||||
}
|
||||
|
||||
// PutReaction is reaction on status with unicode emoji (Pleroma)
|
||||
func (c *Client) PutReaction(ctx context.Context, id string, emoji string) (*Status, error) {
|
||||
var status Status
|
||||
err := c.doAPI(ctx, http.MethodPut, fmt.Sprintf("/api/v1/pleroma/statuses/%s/reactions/%s", id, emoji), nil, &status, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &status, nil
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
@ -107,6 +107,10 @@ body {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.pleroma-reactions form {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.status-action a {
|
||||
display: inline-block;
|
||||
}
|
||||
|
@ -97,6 +97,18 @@
|
||||
{{StatusContentFilter .Content .Emojis .Mentions | Raw}}
|
||||
</div>
|
||||
{{end}}
|
||||
{{$st_id := .ID}}
|
||||
{{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}}">
|
||||
<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">
|
||||
</form>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
{{if .MediaAttachments}}
|
||||
<div class="status-media-container">
|
||||
{{range .MediaAttachments}}
|
||||
|
Loading…
Reference in New Issue
Block a user