From 83a2274f471f39f0425eddeb655bf1f13dc89d4a Mon Sep 17 00:00:00 2001 From: Thorsten Claus Date: Thu, 3 Nov 2022 08:00:19 +0100 Subject: [PATCH] Adding Smart App Banner for insporation on iOS devices --- app/helpers/application_helper.rb | 8 +++++++ app/views/layouts/application.html.haml | 1 + spec/helpers/application_helper_spec.rb | 30 +++++++++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 36cce9bce..dfcc2ea7e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -13,6 +13,14 @@ module ApplicationHelper AppConfig.version.number end + def uri_with_username + if user_signed_in? + AppConfig.pod_uri + "?username=#{current_user.username}" + else + AppConfig.pod_uri + end + end + def changelog_url return AppConfig.settings.changelog_url.get if AppConfig.settings.changelog_url.present? diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 63decb11f..5cb562507 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -6,6 +6,7 @@ %html{lang: I18n.locale.to_s, dir: (rtl? ? "rtl" : "ltr")} %head{prefix: og_prefix} %meta{name: "viewport", content: "width=device-width, initial-scale=1"}/ + %meta{name: "apple-itunes-app", content: "app-id=1538074832, app-argument=#{uri_with_username}"} - content_for :javascript do = javascript_include_tag :main diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 8cfbb0fe6..c72d2fb19 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -165,4 +165,34 @@ describe ApplicationHelper, :type => :helper do expect(pod_version).to match "0.0.1.0" end end + + describe "#uri_with_username" do + attr_reader :current_user + + before do + @current_user = alice + def user_signed_in? + true + end + end + + it "displays the pod uri and username if logged in" do + allow(AppConfig).to receive(:pod_uri) { "https://diaspora.social" } + expect(uri_with_username).to match "https://diaspora.social?username=alice" + end + end + + describe "#uri_with_username without logged in user" do + before do + @current_user = alice + def user_signed_in? + false + end + end + + it "displays the pod uri" do + allow(AppConfig).to receive(:pod_uri) { "https://diaspora.social" } + expect(uri_with_username).to match "https://diaspora.social" + end + end end