diff options
author | r <r@freesoftwareextremist.com> | 2020-01-05 18:55:37 +0000 |
---|---|---|
committer | r <r@freesoftwareextremist.com> | 2020-01-05 18:55:37 +0000 |
commit | ca711e62ec85a763f1b17c9443125579a0f0be7a (patch) | |
tree | 869bc00d3acc7638f08e32ca7494c74a9841ef21 | |
parent | 50e58c4e010959955286e4250ebacb3b93f8c525 (diff) | |
download | bloat-ca711e62ec85a763f1b17c9443125579a0f0be7a.tar.gz bloat-ca711e62ec85a763f1b17c9443125579a0f0be7a.zip |
Fix duplicate status ids
Use retweeted_by_id to focus target tweet
-rw-r--r-- | mastodon/status.go | 1 | ||||
-rw-r--r-- | service/service.go | 1 | ||||
-rw-r--r-- | service/transport.go | 40 | ||||
-rw-r--r-- | templates/status.tmpl | 14 |
4 files changed, 43 insertions, 13 deletions
diff --git a/mastodon/status.go b/mastodon/status.go index 6646c60..06fdd20 100644 --- a/mastodon/status.go +++ b/mastodon/status.go @@ -56,6 +56,7 @@ type Status struct { ReplyNumber int `json:"reply_number"` ThreadInNewTab bool `json:"thread_in_new_tab"` MaskNSFW bool `json:"mask_nsfw"` + RetweetedByID string `json:"retweeted_by_id"` } // Context hold information for mastodon context. 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) diff --git a/templates/status.tmpl b/templates/status.tmpl index 1661f58..10b7d40 100644 --- a/templates/status.tmpl +++ b/templates/status.tmpl @@ -1,4 +1,4 @@ -<div id="status-{{if .Reblog}}{{.Reblog.ID}}{{else}}{{.ID}}{{end}}" class="status-container-container"> +<div id="status-{{.ID}}" class="status-container-container"> {{if .Reblog}} <div class="retweet-info"> <a class="img-link" href="/user/{{.Account.ID}}"> @@ -102,11 +102,13 @@ {{else}} {{if .Reblogged}} <form class="status-retweet" action="/unretweet/{{.ID}}" method="post"> - <input type="image" src="/static/icons/retweeted.png" alt="undo retweet" class="icon" title="undo retweet"> + <input type="hidden" name="retweeted_by_id" value="{{.RetweetedByID}}" /> + <input type="image" src="/static/icons/retweeted.png" alt="undo retweet" class="icon" title="undo retweet"> </form> {{else}} <form class="status-retweet" action="/retweet/{{.ID}}" method="post"> - <input type="image" src="/static/icons/retweet.png" alt="retweet" class="icon" title="retweet"> + <input type="hidden" name="retweeted_by_id" value="{{.RetweetedByID}}" /> + <input type="image" src="/static/icons/retweet.png" alt="retweet" class="icon" title="retweet"> </form> {{end}} {{end}} @@ -117,11 +119,13 @@ <div class="status-action"> {{if .Favourited}} <form class="status-like" action="/unlike/{{.ID}}" method="post"> - <input type="image" src="/static/icons/liked.png" alt="unlike" class="icon" title="unlike"> + <input type="hidden" name="retweeted_by_id" value="{{.RetweetedByID}}" /> + <input type="image" src="/static/icons/liked.png" alt="unlike" class="icon" title="unlike"> </form> {{else}} <form class="status-like" action="/like/{{.ID}}" method="post"> - <input type="image" src="/static/icons/star-o.png" alt="like" class="icon" title="like"> + <input type="hidden" name="retweeted_by_id" value="{{.RetweetedByID}}" /> + <input type="image" src="/static/icons/star-o.png" alt="like" class="icon" title="like"> </form> {{end}} <a class="status-action-count" href="/likedby/{{.ID}}" title="click to see the the list"> |