mirror of
https://git.phreedom.club/localhost_frssoft/bloat.git
synced 2024-11-22 12:01:27 +00:00
Add account {,un}subscribe
This commit is contained in:
parent
ccdb5ef051
commit
04af1b93dc
|
@ -191,6 +191,7 @@ type Relationship struct {
|
||||||
Blocking bool `json:"blocking"`
|
Blocking bool `json:"blocking"`
|
||||||
Muting bool `json:"muting"`
|
Muting bool `json:"muting"`
|
||||||
MutingNotifications bool `json:"muting_notifications"`
|
MutingNotifications bool `json:"muting_notifications"`
|
||||||
|
Subscribing bool `json:"subscribing"`
|
||||||
Requested bool `json:"requested"`
|
Requested bool `json:"requested"`
|
||||||
DomainBlocking bool `json:"domain_blocking"`
|
DomainBlocking bool `json:"domain_blocking"`
|
||||||
ShowingReblogs bool `json:"showing_reblogs"`
|
ShowingReblogs bool `json:"showing_reblogs"`
|
||||||
|
@ -328,3 +329,23 @@ func (c *Client) GetMutes(ctx context.Context, pg *Pagination) ([]*Account, erro
|
||||||
}
|
}
|
||||||
return accounts, nil
|
return accounts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Subscribe to receive notifications for all statuses posted by a user
|
||||||
|
func (c *Client) Subscribe(ctx context.Context, id string) (*Relationship, error) {
|
||||||
|
var relationship *Relationship
|
||||||
|
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/pleroma/accounts/%s/subscribe", url.PathEscape(id)), nil, &relationship, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return relationship, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnSubscribe to stop receiving notifications from user statuses
|
||||||
|
func (c *Client) UnSubscribe(ctx context.Context, id string) (*Relationship, error) {
|
||||||
|
var relationship *Relationship
|
||||||
|
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/pleroma/accounts/%s/unsubscribe", url.PathEscape(id)), nil, &relationship, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return relationship, nil
|
||||||
|
}
|
||||||
|
|
|
@ -364,6 +364,30 @@ func (s *as) UnBlock(ctx context.Context, c *model.Client, id string) (err error
|
||||||
return s.Service.UnBlock(ctx, c, id)
|
return s.Service.UnBlock(ctx, c, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *as) Subscribe(ctx context.Context, c *model.Client, id string) (err error) {
|
||||||
|
err = s.authenticateClient(ctx, c)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = checkCSRF(ctx, c)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return s.Service.Subscribe(ctx, c, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *as) UnSubscribe(ctx context.Context, c *model.Client, id string) (err error) {
|
||||||
|
err = s.authenticateClient(ctx, c)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = checkCSRF(ctx, c)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return s.Service.UnSubscribe(ctx, c, id)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *as) SaveSettings(ctx context.Context, c *model.Client, settings *model.Settings) (err error) {
|
func (s *as) SaveSettings(ctx context.Context, c *model.Client, settings *model.Settings) (err error) {
|
||||||
err = s.authenticateClient(ctx, c)
|
err = s.authenticateClient(ctx, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -269,6 +269,22 @@ func (s *ls) UnBlock(ctx context.Context, c *model.Client, id string) (err error
|
||||||
return s.Service.UnBlock(ctx, c, id)
|
return s.Service.UnBlock(ctx, c, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ls) Subscribe(ctx context.Context, c *model.Client, id string) (err error) {
|
||||||
|
defer func(begin time.Time) {
|
||||||
|
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
||||||
|
"Subscribe", id, time.Since(begin), err)
|
||||||
|
}(time.Now())
|
||||||
|
return s.Service.Subscribe(ctx, c, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ls) UnSubscribe(ctx context.Context, c *model.Client, id string) (err error) {
|
||||||
|
defer func(begin time.Time) {
|
||||||
|
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
||||||
|
"UnSubscribe", id, time.Since(begin), err)
|
||||||
|
}(time.Now())
|
||||||
|
return s.Service.UnSubscribe(ctx, c, id)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *ls) SaveSettings(ctx context.Context, c *model.Client, settings *model.Settings) (err error) {
|
func (s *ls) SaveSettings(ctx context.Context, c *model.Client, settings *model.Settings) (err error) {
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, took=%v, err=%v\n",
|
||||||
|
|
|
@ -52,6 +52,8 @@ type Service interface {
|
||||||
UnMute(ctx context.Context, c *model.Client, id string) (err error)
|
UnMute(ctx context.Context, c *model.Client, id string) (err error)
|
||||||
Block(ctx context.Context, c *model.Client, id string) (err error)
|
Block(ctx context.Context, c *model.Client, id string) (err error)
|
||||||
UnBlock(ctx context.Context, c *model.Client, id string) (err error)
|
UnBlock(ctx context.Context, c *model.Client, id string) (err error)
|
||||||
|
Subscribe(ctx context.Context, c *model.Client, id string) (err error)
|
||||||
|
UnSubscribe(ctx context.Context, c *model.Client, id string) (err error)
|
||||||
SaveSettings(ctx context.Context, c *model.Client, settings *model.Settings) (err error)
|
SaveSettings(ctx context.Context, c *model.Client, settings *model.Settings) (err error)
|
||||||
MuteConversation(ctx context.Context, c *model.Client, id string) (err error)
|
MuteConversation(ctx context.Context, c *model.Client, id string) (err error)
|
||||||
UnMuteConversation(ctx context.Context, c *model.Client, id string) (err error)
|
UnMuteConversation(ctx context.Context, c *model.Client, id string) (err error)
|
||||||
|
@ -839,6 +841,16 @@ func (svc *service) UnBlock(ctx context.Context, c *model.Client, id string) (er
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (svc *service) Subscribe(ctx context.Context, c *model.Client, id string) (err error) {
|
||||||
|
_, err = c.Subscribe(ctx, id)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (svc *service) UnSubscribe(ctx context.Context, c *model.Client, id string) (err error) {
|
||||||
|
_, err = c.UnSubscribe(ctx, id)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (svc *service) SaveSettings(ctx context.Context, c *model.Client,
|
func (svc *service) SaveSettings(ctx context.Context, c *model.Client,
|
||||||
settings *model.Settings) (err error) {
|
settings *model.Settings) (err error) {
|
||||||
|
|
||||||
|
|
|
@ -549,6 +549,38 @@ func NewHandler(s Service, staticDir string) http.Handler {
|
||||||
w.WriteHeader(http.StatusFound)
|
w.WriteHeader(http.StatusFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
subscribe := func(w http.ResponseWriter, req *http.Request) {
|
||||||
|
c := newClient(w)
|
||||||
|
ctx := newCtxWithSesionCSRF(req, req.FormValue("csrf_token"))
|
||||||
|
id, _ := mux.Vars(req)["id"]
|
||||||
|
|
||||||
|
err := s.Subscribe(ctx, c, id)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
s.ServeErrorPage(ctx, c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Add("Location", req.Header.Get("Referer"))
|
||||||
|
w.WriteHeader(http.StatusFound)
|
||||||
|
}
|
||||||
|
|
||||||
|
unSubscribe := func(w http.ResponseWriter, req *http.Request) {
|
||||||
|
c := newClient(w)
|
||||||
|
ctx := newCtxWithSesionCSRF(req, req.FormValue("csrf_token"))
|
||||||
|
id, _ := mux.Vars(req)["id"]
|
||||||
|
|
||||||
|
err := s.UnSubscribe(ctx, c, id)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
s.ServeErrorPage(ctx, c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Add("Location", req.Header.Get("Referer"))
|
||||||
|
w.WriteHeader(http.StatusFound)
|
||||||
|
}
|
||||||
|
|
||||||
settings := func(w http.ResponseWriter, req *http.Request) {
|
settings := func(w http.ResponseWriter, req *http.Request) {
|
||||||
c := newClient(w)
|
c := newClient(w)
|
||||||
ctx := newCtxWithSesionCSRF(req, req.FormValue("csrf_token"))
|
ctx := newCtxWithSesionCSRF(req, req.FormValue("csrf_token"))
|
||||||
|
@ -762,6 +794,8 @@ func NewHandler(s Service, staticDir string) http.Handler {
|
||||||
r.HandleFunc("/unmute/{id}", unMute).Methods(http.MethodPost)
|
r.HandleFunc("/unmute/{id}", unMute).Methods(http.MethodPost)
|
||||||
r.HandleFunc("/block/{id}", block).Methods(http.MethodPost)
|
r.HandleFunc("/block/{id}", block).Methods(http.MethodPost)
|
||||||
r.HandleFunc("/unblock/{id}", unBlock).Methods(http.MethodPost)
|
r.HandleFunc("/unblock/{id}", unBlock).Methods(http.MethodPost)
|
||||||
|
r.HandleFunc("/subscribe/{id}", subscribe).Methods(http.MethodPost)
|
||||||
|
r.HandleFunc("/unsubscribe/{id}", unSubscribe).Methods(http.MethodPost)
|
||||||
r.HandleFunc("/settings", settings).Methods(http.MethodPost)
|
r.HandleFunc("/settings", settings).Methods(http.MethodPost)
|
||||||
r.HandleFunc("/muteconv/{id}", muteConversation).Methods(http.MethodPost)
|
r.HandleFunc("/muteconv/{id}", muteConversation).Methods(http.MethodPost)
|
||||||
r.HandleFunc("/unmuteconv/{id}", unMuteConversation).Methods(http.MethodPost)
|
r.HandleFunc("/unmuteconv/{id}", unMuteConversation).Methods(http.MethodPost)
|
||||||
|
|
|
@ -38,6 +38,18 @@
|
||||||
<input type="submit" value="cancel request" class="btn-link">
|
<input type="submit" value="cancel request" class="btn-link">
|
||||||
</form>
|
</form>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
-
|
||||||
|
{{if .User.Pleroma.Relationship.Subscribing}}
|
||||||
|
<form class="d-inline" action="/unsubscribe/{{.User.ID}}" method="post">
|
||||||
|
<input type="hidden" name="csrf_token" value="{{$.Ctx.CSRFToken}}">
|
||||||
|
<input type="submit" value="unsubscribe" class="btn-link">
|
||||||
|
</form>
|
||||||
|
{{else}}
|
||||||
|
<form class="d-inline" action="/subscribe/{{.User.ID}}" method="post">
|
||||||
|
<input type="hidden" name="csrf_token" value="{{$.Ctx.CSRFToken}}">
|
||||||
|
<input type="submit" value="subscribe" class="btn-link">
|
||||||
|
</form>
|
||||||
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
{{if .User.Pleroma.Relationship.Blocking}}
|
{{if .User.Pleroma.Relationship.Blocking}}
|
||||||
|
|
Loading…
Reference in a new issue