From d5c3ea086203d5872e657b1e9d0d830b7a7fb377 Mon Sep 17 00:00:00 2001
From: chylex <contact@chylex.com>
Date: Mon, 28 Aug 2017 19:55:10 +0200
Subject: [PATCH] 'View detail' errors now ask user if they want to open the
 tweet in a browser

---
 Core/FormBrowser.cs                       |  4 ++--
 Core/Notification/FormNotificationBase.cs |  2 +-
 Resources/Scripts/code.js                 | 13 +++++++++----
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/Core/FormBrowser.cs b/Core/FormBrowser.cs
index 3cc2c7a1..38b47e6f 100644
--- a/Core/FormBrowser.cs
+++ b/Core/FormBrowser.cs
@@ -543,7 +543,7 @@ public bool ProcessBrowserKey(Keys key){
             return false;
         }
 
-        public void ShowTweetDetail(string columnKey, string chirpId){
+        public void ShowTweetDetail(string columnKey, string chirpId, string fallbackUrl){
             Activate();
 
             using(IFrame frame = browser.GetBrowser().MainFrame){
@@ -554,7 +554,7 @@ public void ShowTweetDetail(string columnKey, string chirpId){
             }
 
             notification.FinishCurrentNotification();
-            browser.ExecuteScriptAsync("window.TDGF_showTweetDetail", columnKey, chirpId);
+            browser.ExecuteScriptAsync("window.TDGF_showTweetDetail", columnKey, chirpId, fallbackUrl);
         }
 
         public void OnTweetScreenshotReady(string html, int width, int height){
diff --git a/Core/Notification/FormNotificationBase.cs b/Core/Notification/FormNotificationBase.cs
index af0f7498..464d15e7 100644
--- a/Core/Notification/FormNotificationBase.cs
+++ b/Core/Notification/FormNotificationBase.cs
@@ -197,7 +197,7 @@ protected virtual void UpdateTitle(){
         }
 
         public void ShowTweetDetail(){
-            owner.ShowTweetDetail(currentNotification.ColumnKey, currentNotification.ChirpId);
+            owner.ShowTweetDetail(currentNotification.ColumnKey, currentNotification.ChirpId, currentNotification.TweetUrl);
         }
 
         public void MoveToVisibleLocation(){
diff --git a/Resources/Scripts/code.js b/Resources/Scripts/code.js
index e0b75d12..b961b700 100644
--- a/Resources/Scripts/code.js
+++ b/Resources/Scripts/code.js
@@ -221,11 +221,14 @@
       $(document).trigger("uiGridClearSelection");
     };
     
-    window.TDGF_showTweetDetail = function(columnKey, chirpId){
-      let column = TD.controller.columnManager.get(columnKey);
+    window.TDGF_showTweetDetail = function(columnKey, chirpId, fallbackUrl){
+      let column = TD.controller.columnManager.get(columnKey); // TODO replace columnKey with something that stays after a reload
       
       if (!column){
-        $TD.alert("error", "The column which contained the tweet no longer exists.");
+        if (confirm("error|The column which contained the tweet no longer exists. Would you like to open the tweet in your browser instead?")){
+          $TD.openBrowser(fallbackUrl);
+        }
+        
         return;
       }
       
@@ -238,7 +241,9 @@
         TD.controller.clients.getPreferredClient().show(chirpId, function(chirp){
           showTweetDetailInternal(column, chirp);
         }, function(){
-          $TD.alert("error", "Could not retrieve the requested tweet.");
+          if (confirm("error|Could not retrieve the requested tweet. Would you like to open the tweet in your browser instead?")){
+            $TD.openBrowser(fallbackUrl);
+          }
         });
       }
     };