From 4df1f096beebb69b0669bdc01239120d9ab3d0ee Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Mon, 31 Oct 2022 15:43:36 +0300 Subject: [PATCH] Added pin\unpin statuses; Status ID in code tag --- mastodon/status.go | 12 +++++++++++- service/service.go | 8 ++++++++ service/transport.go | 22 ++++++++++++++++++++++ templates/status.tmpl | 8 +++++++- 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/mastodon/status.go b/mastodon/status.go index b2553b4..2d4fce7 100644 --- a/mastodon/status.go +++ b/mastodon/status.go @@ -332,15 +332,25 @@ func (c *Client) PostStatus(ctx context.Context, toot *Toot) (*Status, error) { if toot.ContentType != "" { params.Set("content_type", toot.ContentType) } - var status Status err := c.doAPI(ctx, http.MethodPost, "/api/v1/statuses", params, &status, nil) + if err != nil { return nil, err } return &status, nil } +// Pin pin your status. +func (c *Client) Pin(ctx context.Context, id string) error { + return c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/statuses/%s/pin", id), nil, nil, nil) +} + +// UnPin unpin your status. +func (c *Client) UnPin(ctx context.Context, id string) error { + return c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/statuses/%s/unpin", id), nil, nil, nil) +} + // DeleteStatus delete the toot. func (c *Client) DeleteStatus(ctx context.Context, id string) error { return c.doAPI(ctx, http.MethodDelete, fmt.Sprintf("/api/v1/statuses/%s", id), nil, nil, nil) diff --git a/service/service.go b/service/service.go index e30d5fc..fcc034f 100644 --- a/service/service.go +++ b/service/service.go @@ -1150,6 +1150,14 @@ func (s *service) UnMuteConversation(c *client, id string) (err error) { return } +func (s *service) Pin(c *client, id string) (err error) { + return c.Pin(c.ctx, id) +} + +func (s *service) UnPin(c *client, id string) (err error) { + return c.UnPin(c.ctx, id) +} + func (s *service) Delete(c *client, id string) (err error) { return c.DeleteStatus(c.ctx, id) } diff --git a/service/transport.go b/service/transport.go index 9c6d9c1..eecdaf1 100644 --- a/service/transport.go +++ b/service/transport.go @@ -572,6 +572,26 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { return nil }, CSRF, HTML) + pin := handle(func(c *client) error { + id, _ := mux.Vars(c.r)["id"] + err := s.Pin(c, id) + if err != nil { + return err + } + redirect(c, c.r.FormValue("referrer")) + return nil + }, CSRF, HTML) + + unpin := handle(func(c *client) error { + id, _ := mux.Vars(c.r)["id"] + err := s.UnPin(c, id) + if err != nil { + return err + } + redirect(c, c.r.FormValue("referrer")) + return nil + }, CSRF, HTML) + delete := handle(func(c *client) error { id, _ := mux.Vars(c.r)["id"] err := s.Delete(c, id) @@ -794,6 +814,8 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { r.HandleFunc("/settings", settings).Methods(http.MethodPost) r.HandleFunc("/muteconv/{id}", muteConversation).Methods(http.MethodPost) r.HandleFunc("/unmuteconv/{id}", unMuteConversation).Methods(http.MethodPost) + r.HandleFunc("/pin/{id}", pin).Methods(http.MethodPost) + r.HandleFunc("/unpin/{id}", unpin).Methods(http.MethodPost) r.HandleFunc("/delete/{id}", delete).Methods(http.MethodPost) r.HandleFunc("/notifications/read", readNotifications).Methods(http.MethodPost) r.HandleFunc("/bookmark/{id}", bookmark).Methods(http.MethodPost) diff --git a/templates/status.tmpl b/templates/status.tmpl index 2f0323b..9378aba 100644 --- a/templates/status.tmpl +++ b/templates/status.tmpl @@ -29,7 +29,7 @@