mirror of
https://gitea.phreedom.club/localhost_frssoft/bloat.git
synced 2025-05-05 03:18:44 +00:00
Add filters
This commit is contained in:
parent
3ac95ab3b1
commit
4f1425febf
8 changed files with 158 additions and 0 deletions
|
@ -641,6 +641,22 @@ func (s *service) SettingsPage(c *client) (err error) {
|
|||
return s.renderer.Render(rCtx, c, renderer.SettingsPage, data)
|
||||
}
|
||||
|
||||
func (svc *service) FiltersPage(c *client) (err error) {
|
||||
filters, err := c.GetFilters(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
commonData := svc.getCommonData(c, "filters")
|
||||
data := &renderer.FiltersData{
|
||||
CommonData: commonData,
|
||||
Filters: filters,
|
||||
}
|
||||
|
||||
rCtx := getRendererContext(c)
|
||||
return svc.renderer.Render(rCtx, c, renderer.FiltersPage, data)
|
||||
}
|
||||
|
||||
func (s *service) SingleInstance() (instance string, ok bool) {
|
||||
if len(s.singleInstance) > 0 {
|
||||
instance = s.singleInstance
|
||||
|
@ -908,3 +924,12 @@ func (s *service) UnBookmark(c *client, id string) (err error) {
|
|||
_, err = c.Unbookmark(ctx, id)
|
||||
return
|
||||
}
|
||||
|
||||
func (svc *service) Filter(c *client, phrase string, wholeWord bool) (err error) {
|
||||
fctx := []string{"home", "notifications", "public", "thread"}
|
||||
return c.AddFilter(ctx, phrase, fctx, true, wholeWord, nil)
|
||||
}
|
||||
|
||||
func (svc *service) UnFilter(c *client, id string) (err error) {
|
||||
return c.RemoveFilter(ctx, id)
|
||||
}
|
||||
|
|
|
@ -262,6 +262,10 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
|||
return s.SettingsPage(c)
|
||||
}, SESSION, HTML)
|
||||
|
||||
filtersPage := handle(func(c *client) error {
|
||||
return s.FiltersPage(c)
|
||||
}, SESSION, HTML)
|
||||
|
||||
signin := handle(func(c *client) error {
|
||||
instance := c.Req.FormValue("instance")
|
||||
url, sid, err := s.NewSession(instance)
|
||||
|
@ -589,6 +593,27 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
|||
return nil
|
||||
}, CSRF, HTML)
|
||||
|
||||
filter := handle(func(c *client) error {
|
||||
phrase := c.Req.FormValue("phrase")
|
||||
wholeWord := c.Req.FormValue("whole_word") == "true"
|
||||
err := s.Filter(c, phrase, wholeWord)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
redirect(c, c.Req.FormValue("referrer"))
|
||||
return nil
|
||||
}, CSRF, HTML)
|
||||
|
||||
unFilter := handle(func(c *client) error {
|
||||
id, _ := mux.Vars(c.Req)["id"]
|
||||
err := s.UnFilter(c, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
redirect(c, c.Req.FormValue("referrer"))
|
||||
return nil
|
||||
}, CSRF, HTML)
|
||||
|
||||
signout := handle(func(c *client) error {
|
||||
s.Signout(c)
|
||||
setSessionCookie(c, "", 0)
|
||||
|
@ -648,6 +673,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
|||
r.HandleFunc("/emojis", emojisPage).Methods(http.MethodGet)
|
||||
r.HandleFunc("/search", searchPage).Methods(http.MethodGet)
|
||||
r.HandleFunc("/settings", settingsPage).Methods(http.MethodGet)
|
||||
r.HandleFunc("/filters", filtersPage).Methods(http.MethodGet)
|
||||
r.HandleFunc("/signin", signin).Methods(http.MethodPost)
|
||||
r.HandleFunc("/oauth_callback", oauthCallback).Methods(http.MethodGet)
|
||||
r.HandleFunc("/post", post).Methods(http.MethodPost)
|
||||
|
@ -673,6 +699,8 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
|||
r.HandleFunc("/notifications/read", readNotifications).Methods(http.MethodPost)
|
||||
r.HandleFunc("/bookmark/{id}", bookmark).Methods(http.MethodPost)
|
||||
r.HandleFunc("/unbookmark/{id}", unBookmark).Methods(http.MethodPost)
|
||||
r.HandleFunc("/filter", filter).Methods(http.MethodPost)
|
||||
r.HandleFunc("/unfilter/{id}", unFilter).Methods(http.MethodPost)
|
||||
r.HandleFunc("/signout", signout).Methods(http.MethodPost)
|
||||
r.HandleFunc("/fluoride/like/{id}", fLike).Methods(http.MethodPost)
|
||||
r.HandleFunc("/fluoride/unlike/{id}", fUnlike).Methods(http.MethodPost)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue