From da22d19fb45b5504f4191ad06d4e7637bfbc3916 Mon Sep 17 00:00:00 2001 From: r Date: Sun, 27 Sep 2020 09:29:17 +0000 Subject: Add bookmarks - Add bookmark/unbookmark link on mouse hover - Add bookmarks section on user profile page --- service/transport.go | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'service/transport.go') 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) -- cgit v1.2.3