From ca711e62ec85a763f1b17c9443125579a0f0be7a Mon Sep 17 00:00:00 2001 From: r Date: Sun, 5 Jan 2020 18:55:37 +0000 Subject: Fix duplicate status ids Use retweeted_by_id to focus target tweet --- service/service.go | 1 + service/transport.go | 40 ++++++++++++++++++++++++++++++++-------- 2 files changed, 33 insertions(+), 8 deletions(-) (limited to 'service') diff --git a/service/service.go b/service/service.go index f8a4aed..47e3de9 100644 --- a/service/service.go +++ b/service/service.go @@ -282,6 +282,7 @@ func (svc *service) ServeTimelinePage(ctx context.Context, client io.Writer, statuses[i].ThreadInNewTab = c.Session.Settings.ThreadInNewTab statuses[i].MaskNSFW = c.Session.Settings.MaskNSFW if statuses[i].Reblog != nil { + statuses[i].Reblog.RetweetedByID = statuses[i].ID statuses[i].Reblog.ThreadInNewTab = c.Session.Settings.ThreadInNewTab statuses[i].Reblog.MaskNSFW = c.Session.Settings.MaskNSFW } diff --git a/service/transport.go b/service/transport.go index d481b21..041330d 100644 --- a/service/transport.go +++ b/service/transport.go @@ -159,52 +159,76 @@ func NewHandler(s Service, staticDir string) http.Handler { r.HandleFunc("/like/{id}", func(w http.ResponseWriter, req *http.Request) { ctx := getContextWithSession(context.Background(), req) id, _ := mux.Vars(req)["id"] - err := s.Like(ctx, w, nil, id) + retweetedByID := req.FormValue("retweeted_by_id") + + _, err := s.Like(ctx, w, nil, id) if err != nil { s.ServeErrorPage(ctx, w, err) return } - w.Header().Add("Location", req.Header.Get("Referer")+"#status-"+id) + rID := id + if len(retweetedByID) > 0 { + rID = retweetedByID + } + w.Header().Add("Location", req.Header.Get("Referer")+"#status-"+rID) w.WriteHeader(http.StatusFound) }).Methods(http.MethodPost) r.HandleFunc("/unlike/{id}", func(w http.ResponseWriter, req *http.Request) { ctx := getContextWithSession(context.Background(), req) id, _ := mux.Vars(req)["id"] - err := s.UnLike(ctx, w, nil, id) + retweetedByID := req.FormValue("retweeted_by_id") + + _, err := s.UnLike(ctx, w, nil, id) if err != nil { s.ServeErrorPage(ctx, w, err) return } - w.Header().Add("Location", req.Header.Get("Referer")+"#status-"+id) + rID := id + if len(retweetedByID) > 0 { + rID = retweetedByID + } + w.Header().Add("Location", req.Header.Get("Referer")+"#status-"+rID) w.WriteHeader(http.StatusFound) }).Methods(http.MethodPost) r.HandleFunc("/retweet/{id}", func(w http.ResponseWriter, req *http.Request) { ctx := getContextWithSession(context.Background(), req) id, _ := mux.Vars(req)["id"] - err := s.Retweet(ctx, w, nil, id) + retweetedByID := req.FormValue("retweeted_by_id") + + _, err := s.Retweet(ctx, w, nil, id) if err != nil { s.ServeErrorPage(ctx, w, err) return } - w.Header().Add("Location", req.Header.Get("Referer")+"#status-"+id) + rID := id + if len(retweetedByID) > 0 { + rID = retweetedByID + } + w.Header().Add("Location", req.Header.Get("Referer")+"#status-"+rID) w.WriteHeader(http.StatusFound) }).Methods(http.MethodPost) r.HandleFunc("/unretweet/{id}", func(w http.ResponseWriter, req *http.Request) { ctx := getContextWithSession(context.Background(), req) id, _ := mux.Vars(req)["id"] - err := s.UnRetweet(ctx, w, nil, id) + retweetedByID := req.FormValue("retweeted_by_id") + + _, err := s.UnRetweet(ctx, w, nil, id) if err != nil { s.ServeErrorPage(ctx, w, err) return } - w.Header().Add("Location", req.Header.Get("Referer")+"#status-"+id) + rID := id + if len(retweetedByID) > 0 { + rID = retweetedByID + } + w.Header().Add("Location", req.Header.Get("Referer")+"#status-"+rID) w.WriteHeader(http.StatusFound) }).Methods(http.MethodPost) -- cgit v1.2.3