FIX: improves share/invite behavior on mobile and especially iOS (#7416)

FIX: improves share/invite behavior on mobile and especially iOS (#7416)

diff --git a/app/assets/javascripts/discourse/initializers/topic-footer-buttons.js.es6 b/app/assets/javascripts/discourse/initializers/topic-footer-buttons.js.es6
index 74bbcf4..1bf23f4 100644
--- a/app/assets/javascripts/discourse/initializers/topic-footer-buttons.js.es6
+++ b/app/assets/javascripts/discourse/initializers/topic-footer-buttons.js.es6
@@ -1,5 +1,4 @@
 import showModal from "discourse/lib/show-modal";
-import { nativeShare } from "discourse/lib/pwa-utils";
 import { registerTopicFooterButton } from "discourse/lib/register-topic-footer-button";
 
 export default {
@@ -13,44 +12,40 @@ export default {
       label: "topic.share.title",
       title: "topic.share.help",
       action() {
-        const modal = () => {
-          const panels = [
-            {
-              id: "share",
-              title: "topic.share.extended_title",
-              model: {
-                topic: this.get("topic")
-              }
+        const panels = [
+          {
+            id: "share",
+            title: "topic.share.extended_title",
+            model: {
+              topic: this.get("topic")
             }
-          ];
-
-          if (this.get("canInviteTo") && !this.get("inviteDisabled")) {
-            let invitePanelTitle;
+          }
+        ];
 
-            if (this.get("isPM")) {
-              invitePanelTitle = "topic.invite_private.title";
-            } else if (this.get("invitingToTopic")) {
-              invitePanelTitle = "topic.invite_reply.title";
-            } else {
-              invitePanelTitle = "user.invited.create";
-            }
+        if (this.get("canInviteTo") && !this.get("inviteDisabled")) {
+          let invitePanelTitle;
 
-            panels.push({
-              id: "invite",
-              title: invitePanelTitle,
-              model: {
-                inviteModel: this.get("topic")
-              }
-            });
+          if (this.get("isPM")) {
+            invitePanelTitle = "topic.invite_private.title";
+          } else if (this.get("invitingToTopic")) {
+            invitePanelTitle = "topic.invite_reply.title";
+          } else {
+            invitePanelTitle = "user.invited.create";
           }
 
-          showModal("share-and-invite", {
-            modalClass: "share-and-invite",
-            panels
+          panels.push({
+            id: "invite",
+            title: invitePanelTitle,
+            model: {
+              inviteModel: this.get("topic")
+            }
           });
-        };
+        }
 
-        nativeShare({ url: this.get("topic.shareUrl") }).then(null, modal);
+        showModal("share-and-invite", {
+          modalClass: "share-and-invite",
+          panels
+        });
       },
       dropdown() {
         return this.site.mobileView;
diff --git a/app/assets/javascripts/discourse/lib/pwa-utils.js.es6 b/app/assets/javascripts/discourse/lib/pwa-utils.js.es6
index f44665a..0cbc621 100644
--- a/app/assets/javascripts/discourse/lib/pwa-utils.js.es6
+++ b/app/assets/javascripts/discourse/lib/pwa-utils.js.es6
@@ -8,7 +8,7 @@ export function nativeShare(data) {
         .share(data)
         .then(resolve)
         .catch(e => {
-          if (e.message === "Share canceled") {
+          if (e.name === "AbortError") {
             // closing share panel do nothing
           } else {
             reject();

GitHub sha: d4e788c1

1 Like