aboutsummaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2022-09-23 17:22:54 +0000
committerr <r@freesoftwareextremist.com>2022-09-23 17:22:54 +0000
commitf55595ddb63bd8afb4c85945b82aa1f174050e6b (patch)
tree3e9f909097c026b065365846ca8143295097a09f /service
parentb8c0133bcd5e7f1d4063ad992949cc19d18e7aad (diff)
parent68698a9e1afce43ef807d6b5f892ca1c0f905b8a (diff)
downloadbloat-absolute_fluoride.tar.gz
bloat-absolute_fluoride.zip
Merge branch 'master' into absolute_fluorideabsolute_fluoride
Diffstat (limited to 'service')
-rw-r--r--service/service.go110
-rw-r--r--service/transport.go76
2 files changed, 176 insertions, 10 deletions
diff --git a/service/service.go b/service/service.go
index c56114c..8bccd45 100644
--- a/service/service.go
+++ b/service/service.go
@@ -163,8 +163,8 @@ func (s *service) NavPage(c *client) (err error) {
return s.renderer.Render(c.rctx, c.w, renderer.NavPage, data)
}
-func (s *service) TimelinePage(c *client, tType string, instance string,
- maxID string, minID string) (err error) {
+func (s *service) TimelinePage(c *client, tType, instance, listId, maxID,
+ minID string) (err error) {
var nextLink, prevLink, title string
var statuses []*mastodon.Status
@@ -179,24 +179,46 @@ func (s *service) TimelinePage(c *client, tType string, instance string,
return errInvalidArgument
case "home":
statuses, err = c.GetTimelineHome(c.ctx, &pg)
+ if err != nil {
+ return err
+ }
title = "Timeline"
case "direct":
statuses, err = c.GetTimelineDirect(c.ctx, &pg)
+ if err != nil {
+ return err
+ }
title = "Direct Timeline"
case "local":
statuses, err = c.GetTimelinePublic(c.ctx, true, "", &pg)
+ if err != nil {
+ return err
+ }
title = "Local Timeline"
case "remote":
if len(instance) > 0 {
statuses, err = c.GetTimelinePublic(c.ctx, false, instance, &pg)
+ if err != nil {
+ return err
+ }
}
title = "Remote Timeline"
case "twkn":
statuses, err = c.GetTimelinePublic(c.ctx, false, "", &pg)
+ if err != nil {
+ return err
+ }
title = "The Whole Known Network"
- }
- if err != nil {
- return err
+ case "list":
+ statuses, err = c.GetTimelineList(c.ctx, listId, &pg)
+ if err != nil {
+ return err
+ }
+ list, err := c.GetList(c.ctx, listId)
+ if err != nil {
+ return err
+ }
+ title = "List Timeline - " + list.Title
}
for i := range statuses {
@@ -211,6 +233,9 @@ func (s *service) TimelinePage(c *client, tType string, instance string,
if len(instance) > 0 {
v.Set("instance", instance)
}
+ if len(listId) > 0 {
+ v.Set("list", listId)
+ }
prevLink = "/timeline/" + tType + "?" + v.Encode()
}
@@ -220,6 +245,9 @@ func (s *service) TimelinePage(c *client, tType string, instance string,
if len(instance) > 0 {
v.Set("instance", instance)
}
+ if len(listId) > 0 {
+ v.Set("list", listId)
+ }
nextLink = "/timeline/" + tType + "?" + v.Encode()
}
@@ -252,6 +280,70 @@ func addToReplyMap(m map[string][]mastodon.ReplyInfo, key interface{},
m[keyStr] = append(m[keyStr], mastodon.ReplyInfo{val, number})
}
+func (s *service) ListsPage(c *client) (err error) {
+ lists, err := c.GetLists(c.ctx)
+ if err != nil {
+ return
+ }
+
+ cdata := s.cdata(c, "Lists", 0, 0, "")
+ data := renderer.ListsData{
+ Lists: lists,
+ CommonData: cdata,
+ }
+ return s.renderer.Render(c.rctx, c.w, renderer.ListsPage, data)
+}
+
+func (s *service) AddList(c *client, title string) (err error) {
+ _, err = c.CreateList(c.ctx, title)
+ return err
+}
+
+func (s *service) RemoveList(c *client, id string) (err error) {
+ return c.DeleteList(c.ctx, id)
+}
+
+func (s *service) RenameList(c *client, id, title string) (err error) {
+ _, err = c.RenameList(c.ctx, id, title)
+ return err
+}
+
+func (s *service) ListPage(c *client, id string, q string) (err error) {
+ list, err := c.GetList(c.ctx, id)
+ if err != nil {
+ return
+ }
+ accounts, err := c.GetListAccounts(c.ctx, id)
+ if err != nil {
+ return
+ }
+ var searchAccounts []*mastodon.Account
+ if len(q) > 0 {
+ result, err := c.Search(c.ctx, q, "accounts", 20, true, 0, id, true)
+ if err != nil {
+ return err
+ }
+ searchAccounts = result.Accounts
+ }
+ cdata := s.cdata(c, "List "+list.Title, 0, 0, "")
+ data := renderer.ListData{
+ List: list,
+ Accounts: accounts,
+ Q: q,
+ SearchAccounts: searchAccounts,
+ CommonData: cdata,
+ }
+ return s.renderer.Render(c.rctx, c.w, renderer.ListPage, data)
+}
+
+func (s *service) ListAddUser(c *client, id string, uid string) (err error) {
+ return c.AddToList(c.ctx, id, uid)
+}
+
+func (s *service) ListRemoveUser(c *client, id string, uid string) (err error) {
+ return c.RemoveFromList(c.ctx, id, uid)
+}
+
func (s *service) ThreadPage(c *client, id string, reply bool) (err error) {
var pctx model.PostContext
@@ -616,7 +708,7 @@ func (s *service) UserSearchPage(c *client,
var results *mastodon.Results
if len(q) > 0 {
- results, err = c.Search(c.ctx, q, "statuses", 20, true, offset, id)
+ results, err = c.Search(c.ctx, q, "statuses", 20, true, offset, id, false)
if err != nil {
return err
}
@@ -627,7 +719,7 @@ func (s *service) UserSearchPage(c *client,
if len(results.Statuses) == 20 {
offset += 20
nextLink = fmt.Sprintf("/usersearch/%s?q=%s&offset=%d", id,
- url.QueryEscape(q), offset)
+ q, offset)
}
if len(q) > 0 {
@@ -674,7 +766,7 @@ func (s *service) SearchPage(c *client,
var results *mastodon.Results
if len(q) > 0 {
- results, err = c.Search(c.ctx, q, qType, 20, true, offset, "")
+ results, err = c.Search(c.ctx, q, qType, 20, true, offset, "", false)
if err != nil {
return err
}
@@ -686,7 +778,7 @@ func (s *service) SearchPage(c *client,
(qType == "statuses" && len(results.Statuses) == 20) {
offset += 20
nextLink = fmt.Sprintf("/search?q=%s&type=%s&offset=%d",
- url.QueryEscape(q), qType, offset)
+ q, qType, offset)
}
if len(q) > 0 {
diff --git a/service/transport.go b/service/transport.go
index 02e6106..1fbce99 100644
--- a/service/transport.go
+++ b/service/transport.go
@@ -169,9 +169,10 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
tType, _ := mux.Vars(c.r)["type"]
q := c.r.URL.Query()
instance := q.Get("instance")
+ list := q.Get("list")
maxID := q.Get("max_id")
minID := q.Get("min_id")
- return s.TimelinePage(c, tType, instance, maxID, minID)
+ return s.TimelinePage(c, tType, instance, list, maxID, minID)
}, SESSION, HTML)
defaultTimelinePage := handle(func(c *client) error {
@@ -606,6 +607,72 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
return nil
}, CSRF, HTML)
+ listsPage := handle(func(c *client) error {
+ return s.ListsPage(c)
+ }, SESSION, HTML)
+
+ addList := handle(func(c *client) error {
+ title := c.r.FormValue("title")
+ err := s.AddList(c, title)
+ if err != nil {
+ return err
+ }
+ redirect(c, c.r.FormValue("referrer"))
+ return nil
+ }, CSRF, HTML)
+
+ removeList := handle(func(c *client) error {
+ id, _ := mux.Vars(c.r)["id"]
+ err := s.RemoveList(c, id)
+ if err != nil {
+ return err
+ }
+ redirect(c, c.r.FormValue("referrer"))
+ return nil
+ }, CSRF, HTML)
+
+ renameList := handle(func(c *client) error {
+ id, _ := mux.Vars(c.r)["id"]
+ title := c.r.FormValue("title")
+ err := s.RenameList(c, id, title)
+ if err != nil {
+ return err
+ }
+ redirect(c, c.r.FormValue("referrer"))
+ return nil
+ }, CSRF, HTML)
+
+ listPage := handle(func(c *client) error {
+ id, _ := mux.Vars(c.r)["id"]
+ q := c.r.URL.Query()
+ sq := q.Get("q")
+ return s.ListPage(c, id, sq)
+ }, SESSION, HTML)
+
+ listAddUser := handle(func(c *client) error {
+ id, _ := mux.Vars(c.r)["id"]
+ q := c.r.URL.Query()
+ uid := q.Get("uid")
+ err := s.ListAddUser(c, id, uid)
+ if err != nil {
+ return err
+ }
+ redirect(c, c.r.FormValue("referrer"))
+ return nil
+ }, CSRF, HTML)
+
+ listRemoveUser := handle(func(c *client) error {
+ id, _ := mux.Vars(c.r)["id"]
+ q := c.r.URL.Query()
+ uid := q.Get("uid")
+ err := s.ListRemoveUser(c, id, uid)
+ if err != nil {
+ return err
+ }
+ redirect(c, c.r.FormValue("referrer"))
+ return nil
+ }, CSRF, HTML)
+
signout := handle(func(c *client) error {
s.Signout(c)
setSessionCookie(c.w, "", 0)
@@ -699,6 +766,13 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
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("/lists", listsPage).Methods(http.MethodGet)
+ r.HandleFunc("/list", addList).Methods(http.MethodPost)
+ r.HandleFunc("/list/{id}", listPage).Methods(http.MethodGet)
+ r.HandleFunc("/list/{id}/remove", removeList).Methods(http.MethodPost)
+ r.HandleFunc("/list/{id}/rename", renameList).Methods(http.MethodPost)
+ r.HandleFunc("/list/{id}/adduser", listAddUser).Methods(http.MethodPost)
+ r.HandleFunc("/list/{id}/removeuser", listRemoveUser).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)