diff --git a/renderer/model.go b/renderer/model.go index 1dcb404..a89b379 100644 --- a/renderer/model.go +++ b/renderer/model.go @@ -14,6 +14,7 @@ type Context struct { CSRFToken string UserID string AntiDopamineMode bool + Referrer string } type NavData struct { diff --git a/service/service.go b/service/service.go index 088bcf4..01306d0 100644 --- a/service/service.go +++ b/service/service.go @@ -58,9 +58,11 @@ func NewService(clientName string, func getRendererContext(c *client) *renderer.Context { var settings model.Settings var session model.Session + var referrer string if c != nil { settings = c.Session.Settings session = c.Session + referrer = c.url() } else { settings = *model.NewSettings() } @@ -73,6 +75,7 @@ func getRendererContext(c *client) *renderer.Context { CSRFToken: session.CSRFToken, UserID: session.UserID, AntiDopamineMode: settings.AntiDopamineMode, + Referrer: referrer, } } @@ -545,7 +548,7 @@ func (s *service) UserSearchPage(c *client, if len(results.Statuses) == 20 { offset += 20 - nextLink = fmt.Sprintf("/usersearch/%s?q=%s&offset=%d", id, + nextLink = fmt.Sprintf("/usersearch/%s?q=%s&offset=%d", id, url.QueryEscape(q), offset) } @@ -608,7 +611,7 @@ func (s *service) SearchPage(c *client, if (qType == "accounts" && len(results.Accounts) == 20) || (qType == "statuses" && len(results.Statuses) == 20) { offset += 20 - nextLink = fmt.Sprintf("/search?q=%s&type=%s&offset=%d", + nextLink = fmt.Sprintf("/search?q=%s&type=%s&offset=%d", url.QueryEscape(q), qType, offset) } @@ -721,7 +724,7 @@ func (s *service) NewSession(instance string) (rurl string, sid string, err erro return } -func (s *service) Signin(c *client, code string) (token string, +func (s *service) Signin(c *client, code string) (token string, userID string, err error) { if len(code) < 1 { @@ -747,7 +750,7 @@ func (s *service) Signout(c *client) (err error) { return } -func (s *service) Post(c *client, content string, replyToID string, +func (s *service) Post(c *client, content string, replyToID string, format string, visibility string, isNSFW bool, files []*multipart.FileHeader) (id string, err error) { diff --git a/service/transport.go b/service/transport.go index 7ba52a4..882a351 100644 --- a/service/transport.go +++ b/service/transport.go @@ -46,6 +46,10 @@ type client struct { Session model.Session } +func (c *client) url() string { + return c.Req.URL.RequestURI() +} + func setSessionCookie(w http.ResponseWriter, sid string, exp time.Duration) { http.SetCookie(w, &http.Cookie{ Name: "session_id", @@ -301,7 +305,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { return err } - location := c.Req.Header.Get("Referer") + location := c.Req.FormValue("referrer") if len(replyToID) > 0 { location = "/thread/" + replyToID + "#status-" + id } @@ -319,7 +323,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if len(rid) > 0 { id = rid } - redirect(c, c.Req.Header.Get("Referer")+"#status-"+id) + redirect(c, c.Req.FormValue("referrer")+"#status-"+id) return nil }, CSRF, HTML) @@ -333,7 +337,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if len(rid) > 0 { id = rid } - redirect(c, c.Req.Header.Get("Referer")+"#status-"+id) + redirect(c, c.Req.FormValue("referrer")+"#status-"+id) return nil }, CSRF, HTML) @@ -347,7 +351,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if len(rid) > 0 { id = rid } - redirect(c, c.Req.Header.Get("Referer")+"#status-"+id) + redirect(c, c.Req.FormValue("referrer")+"#status-"+id) return nil }, CSRF, HTML) @@ -361,7 +365,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if len(rid) > 0 { id = rid } - redirect(c, c.Req.Header.Get("Referer")+"#status-"+id) + redirect(c, c.Req.FormValue("referrer")+"#status-"+id) return nil }, CSRF, HTML) @@ -373,7 +377,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")+"#status-"+statusID) + redirect(c, c.Req.FormValue("referrer")+"#status-"+statusID) return nil }, CSRF, HTML) @@ -389,7 +393,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")) + redirect(c, c.Req.FormValue("referrer")) return nil }, CSRF, HTML) @@ -399,7 +403,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")) + redirect(c, c.Req.FormValue("referrer")) return nil }, CSRF, HTML) @@ -409,7 +413,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")) + redirect(c, c.Req.FormValue("referrer")) return nil }, CSRF, HTML) @@ -419,7 +423,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")) + redirect(c, c.Req.FormValue("referrer")) return nil }, CSRF, HTML) @@ -429,7 +433,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")) + redirect(c, c.Req.FormValue("referrer")) return nil }, CSRF, HTML) @@ -439,7 +443,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")) + redirect(c, c.Req.FormValue("referrer")) return nil }, CSRF, HTML) @@ -449,7 +453,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")) + redirect(c, c.Req.FormValue("referrer")) return nil }, CSRF, HTML) @@ -459,7 +463,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")) + redirect(c, c.Req.FormValue("referrer")) return nil }, CSRF, HTML) @@ -469,7 +473,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")) + redirect(c, c.Req.FormValue("referrer")) return nil }, CSRF, HTML) @@ -479,7 +483,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")) + redirect(c, c.Req.FormValue("referrer")) return nil }, CSRF, HTML) @@ -522,7 +526,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")) + redirect(c, c.Req.FormValue("referrer")) return nil }, CSRF, HTML) @@ -532,7 +536,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")) + redirect(c, c.Req.FormValue("referrer")) return nil }, CSRF, HTML) @@ -542,7 +546,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")) + redirect(c, c.Req.FormValue("referrer")) return nil }, CSRF, HTML) @@ -553,7 +557,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")) + redirect(c, c.Req.FormValue("referrer")) return nil }, CSRF, HTML) @@ -567,7 +571,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if len(rid) > 0 { id = rid } - redirect(c, c.Req.Header.Get("Referer")+"#status-"+id) + redirect(c, c.Req.FormValue("referrer")+"#status-"+id) return nil }, CSRF, HTML) @@ -581,7 +585,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if len(rid) > 0 { id = rid } - redirect(c, c.Req.Header.Get("Referer")+"#status-"+id) + redirect(c, c.Req.FormValue("referrer")+"#status-"+id) return nil }, CSRF, HTML) diff --git a/templates/nav.tmpl b/templates/nav.tmpl index 97898c8..fdff885 100644 --- a/templates/nav.tmpl +++ b/templates/nav.tmpl @@ -25,6 +25,7 @@ settings
diff --git a/templates/notification.tmpl b/templates/notification.tmpl index 567bcf0..4eed61b 100644 --- a/templates/notification.tmpl +++ b/templates/notification.tmpl @@ -11,6 +11,7 @@ {{if .ReadID}} {{end}} @@ -57,11 +58,13 @@ - diff --git a/templates/postform.tmpl b/templates/postform.tmpl index f00c300..b81126c 100644 --- a/templates/postform.tmpl +++ b/templates/postform.tmpl @@ -1,6 +1,7 @@ {{with .Data}} - diff --git a/templates/settings.tmpl b/templates/settings.tmpl index baeb64d..4a72b6a 100644 --- a/templates/settings.tmpl +++ b/templates/settings.tmpl @@ -4,6 +4,7 @@