Add support for pasting 'with_replies' links

This commit is contained in:
Alessio 2023-08-27 13:30:02 -03:00
parent f245054fe6
commit 11c94511d5
2 changed files with 9 additions and 1 deletions

View File

@ -37,6 +37,8 @@ func (app *Application) Search(w http.ResponseWriter, r *http.Request) {
maybe_url, err := url.Parse(search_text)
if err == nil && (maybe_url.Host == "twitter.com" || maybe_url.Host == "mobile.twitter.com") {
parts := strings.Split(strings.Trim(maybe_url.Path, "/"), "/")
// Handle tweet links
if len(parts) == 3 && parts[1] == "status" {
id, err := strconv.Atoi(parts[2])
if err == nil {
@ -45,7 +47,8 @@ func (app *Application) Search(w http.ResponseWriter, r *http.Request) {
}
}
if len(parts) == 1 {
// Handle user profile links
if len(parts) == 1 || (len(parts) == 2 && parts[1] == "with_replies") {
http.Redirect(w, r, fmt.Sprintf("/%s", parts[0]), 302)
return
}

View File

@ -242,6 +242,11 @@ func TestSearchRedirectOnUserFeedLink(t *testing.T) {
assert.Equal(resp.StatusCode, 302)
assert.Equal(resp.Header.Get("Location"), "/agsdf")
// "With Replies" page
resp = do_request(httptest.NewRequest("GET", fmt.Sprintf("/search/%s", url.PathEscape("https://twitter.com/agsdf/with_replies")), nil))
assert.Equal(resp.StatusCode, 302)
assert.Equal(resp.Header.Get("Location"), "/agsdf")
// Mobile URL
resp = do_request(httptest.NewRequest("GET", fmt.Sprintf("/search/%s", url.PathEscape("https://mobile.twitter.com/agsdfhh")), nil))
assert.Equal(resp.StatusCode, 302)