aboutsummaryrefslogtreecommitdiff
path: root/service/transport.go
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2020-09-27 09:29:17 +0000
committerr <r@freesoftwareextremist.com>2020-09-27 09:37:15 +0000
commitda22d19fb45b5504f4191ad06d4e7637bfbc3916 (patch)
tree73a44f90ec525caddfe3d01caf688a1b4afdc4af /service/transport.go
parent0b8c41ca7c99f6ab31a3769b16c760fd028f7c2b (diff)
downloadbloat-da22d19fb45b5504f4191ad06d4e7637bfbc3916.tar.gz
bloat-da22d19fb45b5504f4191ad06d4e7637bfbc3916.zip
Add bookmarks
- Add bookmark/unbookmark link on mouse hover - Add bookmarks section on user profile page
Diffstat (limited to 'service/transport.go')
-rw-r--r--service/transport.go44
1 files changed, 43 insertions, 1 deletions
diff --git a/service/transport.go b/service/transport.go
index 7d27a84..4f73c5e 100644
--- a/service/transport.go
+++ b/service/transport.go
@@ -76,7 +76,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
c := newClient(w, req, "")
err := s.ServeRootPage(c)
if err != nil {
- if (err == errInvalidAccessToken) {
+ if err == errInvalidAccessToken {
w.Header().Add("Location", "/signin")
w.WriteHeader(http.StatusFound)
return
@@ -676,6 +676,46 @@ func NewHandler(s Service, staticDir string) http.Handler {
w.WriteHeader(http.StatusFound)
}
+ bookmark := func(w http.ResponseWriter, req *http.Request) {
+ c := newClient(w, req, req.FormValue("csrf_token"))
+ id, _ := mux.Vars(req)["id"]
+ retweetedByID := req.FormValue("retweeted_by_id")
+
+ err := s.Bookmark(c, id)
+ if err != nil {
+ w.WriteHeader(http.StatusInternalServerError)
+ s.ServeErrorPage(c, err)
+ return
+ }
+
+ rID := id
+ if len(retweetedByID) > 0 {
+ rID = retweetedByID
+ }
+ w.Header().Add("Location", req.Header.Get("Referer")+"#status-"+rID)
+ w.WriteHeader(http.StatusFound)
+ }
+
+ unBookmark := func(w http.ResponseWriter, req *http.Request) {
+ c := newClient(w, req, req.FormValue("csrf_token"))
+ id, _ := mux.Vars(req)["id"]
+ retweetedByID := req.FormValue("retweeted_by_id")
+
+ err := s.UnBookmark(c, id)
+ if err != nil {
+ w.WriteHeader(http.StatusInternalServerError)
+ s.ServeErrorPage(c, err)
+ return
+ }
+
+ rID := id
+ if len(retweetedByID) > 0 {
+ rID = retweetedByID
+ }
+ w.Header().Add("Location", req.Header.Get("Referer")+"#status-"+rID)
+ w.WriteHeader(http.StatusFound)
+ }
+
signout := func(w http.ResponseWriter, req *http.Request) {
c := newClient(w, req, req.FormValue("csrf_token"))
@@ -791,6 +831,8 @@ func NewHandler(s Service, staticDir string) http.Handler {
r.HandleFunc("/unmuteconv/{id}", unMuteConversation).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)
+ r.HandleFunc("/unbookmark/{id}", unBookmark).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)