aboutsummaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2020-02-08 10:49:06 +0000
committerr <r@freesoftwareextremist.com>2020-02-08 10:49:06 +0000
commit1e44d5d3d50c850505065ef16bc513a207c0656c (patch)
tree3f530fb102ff60075446c76b16bf28d97ecbad9d /service
parent9d2e24a7dedc311862f6c0b5c20e9f6eff221caf (diff)
downloadbloat-1e44d5d3d50c850505065ef16bc513a207c0656c.tar.gz
bloat-1e44d5d3d50c850505065ef16bc513a207c0656c.zip
Add account muting and blocking
Diffstat (limited to 'service')
-rw-r--r--service/auth.go48
-rw-r--r--service/logging.go32
-rw-r--r--service/service.go26
-rw-r--r--service/transport.go68
4 files changed, 173 insertions, 1 deletions
diff --git a/service/auth.go b/service/auth.go
index dac0338..6c71439 100644
--- a/service/auth.go
+++ b/service/auth.go
@@ -274,6 +274,54 @@ func (s *as) UnFollow(ctx context.Context, c *model.Client, id string) (err erro
return s.Service.UnFollow(ctx, c, id)
}
+func (s *as) Mute(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.Mute(ctx, c, id)
+}
+
+func (s *as) UnMute(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.UnMute(ctx, c, id)
+}
+
+func (s *as) Block(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.Block(ctx, c, id)
+}
+
+func (s *as) UnBlock(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.UnBlock(ctx, c, id)
+}
+
func (s *as) SaveSettings(ctx context.Context, c *model.Client, settings *model.Settings) (err error) {
err = s.authenticateClient(ctx, c)
if err != nil {
diff --git a/service/logging.go b/service/logging.go
index 86aa1cb..e429fac 100644
--- a/service/logging.go
+++ b/service/logging.go
@@ -205,6 +205,38 @@ func (s *ls) UnFollow(ctx context.Context, c *model.Client, id string) (err erro
return s.Service.UnFollow(ctx, c, id)
}
+func (s *ls) Mute(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",
+ "Mute", id, time.Since(begin), err)
+ }(time.Now())
+ return s.Service.Mute(ctx, c, id)
+}
+
+func (s *ls) UnMute(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",
+ "UnMute", id, time.Since(begin), err)
+ }(time.Now())
+ return s.Service.UnMute(ctx, c, id)
+}
+
+func (s *ls) Block(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",
+ "Block", id, time.Since(begin), err)
+ }(time.Now())
+ return s.Service.Block(ctx, c, id)
+}
+
+func (s *ls) UnBlock(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",
+ "UnBlock", id, time.Since(begin), err)
+ }(time.Now())
+ return s.Service.UnBlock(ctx, c, id)
+}
+
func (s *ls) SaveSettings(ctx context.Context, c *model.Client, settings *model.Settings) (err error) {
defer func(begin time.Time) {
s.logger.Printf("method=%v, took=%v, err=%v\n",
diff --git a/service/service.go b/service/service.go
index c9511f9..c05097b 100644
--- a/service/service.go
+++ b/service/service.go
@@ -34,7 +34,7 @@ type Service interface {
ServeUserSearchPage(ctx context.Context, c *model.Client, id string, q string, offset int) (err error)
ServeSettingsPage(ctx context.Context, c *model.Client) (err error)
NewSession(ctx context.Context, instance string) (redirectUrl string, sessionID string, err error)
- Signin(ctx context.Context, c *model.Client, sessionID string,
+ Signin(ctx context.Context, c *model.Client, sessionID string,
code string) (token string, userID string, err error)
Post(ctx context.Context, c *model.Client, content string, replyToID string, format string,
visibility string, isNSFW bool, files []*multipart.FileHeader) (id string, err error)
@@ -44,6 +44,10 @@ type Service interface {
UnRetweet(ctx context.Context, c *model.Client, id string) (count int64, err error)
Follow(ctx context.Context, c *model.Client, id string) (err error)
UnFollow(ctx context.Context, c *model.Client, id string) (err error)
+ Mute(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)
+ UnBlock(ctx context.Context, c *model.Client, id string) (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)
UnMuteConversation(ctx context.Context, c *model.Client, id string) (err error)
@@ -848,6 +852,26 @@ func (svc *service) UnFollow(ctx context.Context, c *model.Client, id string) (e
return
}
+func (svc *service) Mute(ctx context.Context, c *model.Client, id string) (err error) {
+ _, err = c.AccountMute(ctx, id)
+ return
+}
+
+func (svc *service) UnMute(ctx context.Context, c *model.Client, id string) (err error) {
+ _, err = c.AccountUnmute(ctx, id)
+ return
+}
+
+func (svc *service) Block(ctx context.Context, c *model.Client, id string) (err error) {
+ _, err = c.AccountBlock(ctx, id)
+ return
+}
+
+func (svc *service) UnBlock(ctx context.Context, c *model.Client, id string) (err error) {
+ _, err = c.AccountUnblock(ctx, id)
+ return
+}
+
func (svc *service) SaveSettings(ctx context.Context, c *model.Client,
settings *model.Settings) (err error) {
diff --git a/service/transport.go b/service/transport.go
index 6316748..81af4fa 100644
--- a/service/transport.go
+++ b/service/transport.go
@@ -451,6 +451,70 @@ func NewHandler(s Service, staticDir string) http.Handler {
w.WriteHeader(http.StatusFound)
}
+ mute := func(w http.ResponseWriter, req *http.Request) {
+ c := newClient(w)
+ ctx := newCtxWithSesionCSRF(req, req.FormValue("csrf_token"))
+ id, _ := mux.Vars(req)["id"]
+
+ err := s.Mute(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)
+ }
+
+ unMute := func(w http.ResponseWriter, req *http.Request) {
+ c := newClient(w)
+ ctx := newCtxWithSesionCSRF(req, req.FormValue("csrf_token"))
+ id, _ := mux.Vars(req)["id"]
+
+ err := s.UnMute(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)
+ }
+
+ block := func(w http.ResponseWriter, req *http.Request) {
+ c := newClient(w)
+ ctx := newCtxWithSesionCSRF(req, req.FormValue("csrf_token"))
+ id, _ := mux.Vars(req)["id"]
+
+ err := s.Block(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)
+ }
+
+ unBlock := func(w http.ResponseWriter, req *http.Request) {
+ c := newClient(w)
+ ctx := newCtxWithSesionCSRF(req, req.FormValue("csrf_token"))
+ id, _ := mux.Vars(req)["id"]
+
+ err := s.UnBlock(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) {
c := newClient(w)
ctx := newCtxWithSesionCSRF(req, req.FormValue("csrf_token"))
@@ -635,6 +699,10 @@ func NewHandler(s Service, staticDir string) http.Handler {
r.HandleFunc("/unretweet/{id}", unretweet).Methods(http.MethodPost)
r.HandleFunc("/follow/{id}", follow).Methods(http.MethodPost)
r.HandleFunc("/unfollow/{id}", unfollow).Methods(http.MethodPost)
+ r.HandleFunc("/mute/{id}", mute).Methods(http.MethodPost)
+ r.HandleFunc("/unmute/{id}", unMute).Methods(http.MethodPost)
+ r.HandleFunc("/block/{id}", block).Methods(http.MethodPost)
+ r.HandleFunc("/unblock/{id}", unBlock).Methods(http.MethodPost)
r.HandleFunc("/settings", settings).Methods(http.MethodPost)
r.HandleFunc("/muteconv/{id}", muteConversation).Methods(http.MethodPost)
r.HandleFunc("/unmuteconv/{id}", unMuteConversation).Methods(http.MethodPost)