From 7bbe33adabcc5bcfbe2322f38eb52d7111515dd4 Mon Sep 17 00:00:00 2001 From: Andre Staltz Date: Fri, 16 Apr 2021 18:31:32 +0300 Subject: [PATCH 1/2] refactor templates that have ssb uri links --- web/assets/{login-events.js => auth-withssb-uri.js} | 0 web/assets/{autoredirect.js => invite-uri.js} | 9 +++++---- web/i18n/defaults/active.en.toml | 10 +++++++--- web/templates/auth/withssb_server_start.tmpl | 2 +- web/templates/invite/facade-fallback.tmpl | 4 ++-- web/templates/invite/facade.tmpl | 7 +++---- 6 files changed, 18 insertions(+), 14 deletions(-) rename web/assets/{login-events.js => auth-withssb-uri.js} (100%) rename web/assets/{autoredirect.js => invite-uri.js} (66%) diff --git a/web/assets/login-events.js b/web/assets/auth-withssb-uri.js similarity index 100% rename from web/assets/login-events.js rename to web/assets/auth-withssb-uri.js diff --git a/web/assets/autoredirect.js b/web/assets/invite-uri.js similarity index 66% rename from web/assets/autoredirect.js rename to web/assets/invite-uri.js index 67c02fef..e7d83493 100644 --- a/web/assets/autoredirect.js +++ b/web/assets/invite-uri.js @@ -9,11 +9,12 @@ window.addEventListener('focus', () => { const waitingElem = document.getElementById('waiting'); const anchorElem = document.getElementById('join-room-uri'); anchorElem.onclick = function handleURI(ev) { - const ssbUri = ev.target.dataset.href; - const fallbackUrl = ev.target.dataset.hrefFallback; + ev.preventDefault(); + const ssbUri = anchorElem.href; + const fallbackUrl = anchorElem.dataset.hrefFallback; waitingElem.classList.remove('hidden'); setTimeout(function () { - if (hasFocus) window.location = fallbackUrl; + if (hasFocus) window.location.replace(fallbackUrl); }, 5000); - window.location = ssbUri; + window.location.replace(ssbUri); }; diff --git a/web/i18n/defaults/active.en.toml b/web/i18n/defaults/active.en.toml index 3cf0d879..91a29d4a 100644 --- a/web/i18n/defaults/active.en.toml +++ b/web/i18n/defaults/active.en.toml @@ -152,11 +152,8 @@ InviteFacadeTitle = "Join Room" InviteFacadeWelcome = "You have permission to become a member of this room because someone has shared this invite with you." InviteFacadeInstruct = "To claim the invite, press the button below which will open a compatible SSB app, if it's installed." InviteFacadeJoin = "Join this room" -InviteFacadeWaiting = "Opening SSB app" InviteFacadeInstructQR = "If your SSB app is on another device, you can scan the following QR code to claim your invite on that device:" -InviteFacadeFallbackWelcome = "Are you new to SSB? It seems you don't have an SSB app capable of understanding that link. You can install one of these apps:" -InviteFacadeFallbackManyverse = "Install Manyverse" InviteFacadeFallbackInsertID = "Insert SSB ID" InviteInsertWelcome = "You can claim your invite by inserting your SSB ID below. After that, you'll be able to connect to the room in your SSB app." @@ -164,6 +161,13 @@ InviteInsertWelcome = "You can claim your invite by inserting your SSB ID below. InviteConsumedTitle = "Invite accepted!" InviteConsumedWelcome = "You are now a member of this room. If you need a multiserver address to connect to the room, you can copy-paste the one below:" +# ssb uri links +############### + +SSBURIOpening = "Opening SSB app" +SSBURIFailureWelcome = "Are you new to SSB? It seems you don't have an SSB app capable of understanding that link. You can install one of these apps:" +SSBURIFailureInstallManyverse = "Install Manyverse" + # notices (mini-CMS) #################### diff --git a/web/templates/auth/withssb_server_start.tmpl b/web/templates/auth/withssb_server_start.tmpl index 15a942da..6a1e4102 100644 --- a/web/templates/auth/withssb_server_start.tmpl +++ b/web/templates/auth/withssb_server_start.tmpl @@ -34,6 +34,6 @@ {{if not .IsSolvingRemotely}} - + {{end}} {{end}} \ No newline at end of file diff --git a/web/templates/invite/facade-fallback.tmpl b/web/templates/invite/facade-fallback.tmpl index 46de43c9..29ea43c7 100644 --- a/web/templates/invite/facade-fallback.tmpl +++ b/web/templates/invite/facade-fallback.tmpl @@ -1,13 +1,13 @@ {{ define "title" }}{{ i18n "InviteFacadeTitle" }}{{ end }} {{ define "content" }}
-

{{i18n "InviteFacadeFallbackWelcome"}}

+

{{i18n "SSBURIFailureWelcome"}}

{{i18n "InviteFacadeFallbackManyverse"}} + >{{i18n "SSBURIFailureInstallManyverse"}}

diff --git a/web/templates/invite/facade.tmpl b/web/templates/invite/facade.tmpl index f4b41f00..9cd8cff1 100644 --- a/web/templates/invite/facade.tmpl +++ b/web/templates/invite/facade.tmpl @@ -6,13 +6,12 @@ {{i18n "InviteFacadeJoin"}} - +
@@ -27,6 +26,6 @@ class="mt-8" /> - +
{{ end }} \ No newline at end of file From 0f119565e9a82c80fe81c8e80cb5c984d02c6455 Mon Sep 17 00:00:00 2001 From: Andre Staltz Date: Fri, 16 Apr 2021 18:38:13 +0300 Subject: [PATCH 2/2] update tests --- web/handlers/auth_test.go | 2 +- web/handlers/invites_test.go | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/web/handlers/auth_test.go b/web/handlers/auth_test.go index 3cfd68fb..b6948348 100644 --- a/web/handlers/auth_test.go +++ b/web/handlers/auth_test.go @@ -424,7 +424,7 @@ func TestAuthWithSSBServerInitHappyPath(t *testing.T) { jsFile, has := html.Find("script").Attr("src") a.True(has, "should have client code") - a.Equal("/assets/login-events.js", jsFile) + a.Equal("/assets/auth-withssb-uri.js", jsFile) serverChallenge, has := html.Find("#challenge").Attr("data-sc") a.True(has, "should have server challenge") diff --git a/web/handlers/invites_test.go b/web/handlers/invites_test.go index d7599a53..790d7409 100644 --- a/web/handlers/invites_test.go +++ b/web/handlers/invites_test.go @@ -76,11 +76,6 @@ func TestInviteShowAcceptForm(t *testing.T) { {"title", "InviteFacadeTitle"}, }) - // Empty href - joinHref, ok := doc.Find("#join-room-uri").Attr("href") - a.Equal("#", joinHref) - a.True(ok) - // Fallback URL in data-href-fallback fallbackURL := ts.URLTo(router.CompleteInviteFacadeFallback, "token", testToken) want := fallbackURL.Path + "?" + fallbackURL.RawQuery @@ -88,8 +83,8 @@ func TestInviteShowAcceptForm(t *testing.T) { a.Equal(want, joinDataHrefFallback) a.True(ok) - // ssb-uri in data-href - joinDataHref, ok := doc.Find("#join-room-uri").Attr("data-href") + // ssb-uri in href + joinDataHref, ok := doc.Find("#join-room-uri").Attr("href") a.True(ok) joinURI, err := url.Parse(joinDataHref) r.NoError(err)