mirror of
https://gitea.phreedom.club/localhost_frssoft/bloat.git
synced 2024-11-22 12:49:21 +02:00
FEATURE: Pleroma reactions implemented partially
This commit is contained in:
parent
0cd239b8aa
commit
f452fab462
|
@ -12,6 +12,14 @@ import (
|
||||||
|
|
||||||
type StatusPleroma struct {
|
type StatusPleroma struct {
|
||||||
InReplyToAccountAcct string `json:"in_reply_to_account_acct"`
|
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 {
|
type ReplyInfo struct {
|
||||||
|
@ -158,14 +166,24 @@ func (c *Client) GetFavouritedBy(ctx context.Context, id string, pg *Pagination)
|
||||||
return accounts, nil
|
return accounts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetReactionBy returns the account list of the user who reacted the toot of id. (Pleroma)
|
// GetReactionBy returns the reactions list of the user who reacted the toot of id. (Pleroma)
|
||||||
func (c *Client) GetReactedBy(ctx context.Context, id string, pg *Pagination) ([]*Account, error) {
|
func (c *Client) GetReactedBy(ctx context.Context, id string) ([]*ReactionsPleroma, error) {
|
||||||
var accounts []*Account
|
var reactions []*ReactionsPleroma
|
||||||
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/pleroma/statuses/%s/reactions", id), nil, &accounts, pg)
|
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/pleroma/statuses/%s/reactions", id), nil, &reactions, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -168,6 +168,7 @@ func (s *service) TimelinePage(c *client, tType, instance, listId, maxID,
|
||||||
|
|
||||||
var nextLink, prevLink, title string
|
var nextLink, prevLink, title string
|
||||||
var statuses []*mastodon.Status
|
var statuses []*mastodon.Status
|
||||||
|
var reactions []*mastodon.ReactionsPleroma
|
||||||
var pg = mastodon.Pagination{
|
var pg = mastodon.Pagination{
|
||||||
MaxID: maxID,
|
MaxID: maxID,
|
||||||
MinID: minID,
|
MinID: minID,
|
||||||
|
@ -232,6 +233,17 @@ func (s *service) TimelinePage(c *client, tType, instance, listId, maxID,
|
||||||
if statuses[i].Reblog != nil {
|
if statuses[i].Reblog != nil {
|
||||||
statuses[i].Reblog.RetweetedByID = statuses[i].ID
|
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 {
|
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
|
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) {
|
func (s *service) Retweet(c *client, id string) (count int64, err error) {
|
||||||
st, err := c.Reblog(c.ctx, id)
|
st, err := c.Reblog(c.ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -325,6 +325,19 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
||||||
return nil
|
return nil
|
||||||
}, CSRF, HTML)
|
}, 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 {
|
retweet := handle(func(c *client) error {
|
||||||
id, _ := mux.Vars(c.r)["id"]
|
id, _ := mux.Vars(c.r)["id"]
|
||||||
rid := c.r.FormValue("retweeted_by_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("/post", post).Methods(http.MethodPost)
|
||||||
r.HandleFunc("/like/{id}", like).Methods(http.MethodPost)
|
r.HandleFunc("/like/{id}", like).Methods(http.MethodPost)
|
||||||
r.HandleFunc("/unlike/{id}", unlike).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("/retweet/{id}", retweet).Methods(http.MethodPost)
|
||||||
r.HandleFunc("/unretweet/{id}", unretweet).Methods(http.MethodPost)
|
r.HandleFunc("/unretweet/{id}", unretweet).Methods(http.MethodPost)
|
||||||
r.HandleFunc("/vote/{id}", vote).Methods(http.MethodPost)
|
r.HandleFunc("/vote/{id}", vote).Methods(http.MethodPost)
|
||||||
|
|
|
@ -107,6 +107,10 @@ body {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.pleroma-reactions form {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
.status-action a {
|
.status-action a {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,6 +97,18 @@
|
||||||
{{StatusContentFilter .Content .Emojis .Mentions | Raw}}
|
{{StatusContentFilter .Content .Emojis .Mentions | Raw}}
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{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}}
|
{{if .MediaAttachments}}
|
||||||
<div class="status-media-container">
|
<div class="status-media-container">
|
||||||
{{range .MediaAttachments}}
|
{{range .MediaAttachments}}
|
||||||
|
|
Loading…
Reference in New Issue