From bb7cbde38ff61aced92920fb953c3f969af2553f Mon Sep 17 00:00:00 2001
From: chylex <contact@chylex.com>
Date: Wed, 10 Jan 2018 22:47:50 +0100
Subject: [PATCH] Make 'Show this thread' in notification open tweet detail

Closes #191
---
 Core/Bridge/TweetDeckBridge.cs    |  4 ++++
 Resources/Scripts/code.js         |  7 +++++++
 Resources/Scripts/notification.js | 13 +++++++++++++
 3 files changed, 24 insertions(+)

diff --git a/Core/Bridge/TweetDeckBridge.cs b/Core/Bridge/TweetDeckBridge.cs
index 9d4be560..2831786f 100644
--- a/Core/Bridge/TweetDeckBridge.cs
+++ b/Core/Bridge/TweetDeckBridge.cs
@@ -113,6 +113,10 @@ public void LoadNextNotification(){
             notification.InvokeAsyncSafe(notification.FinishCurrentNotification);
         }
 
+        public void ShowNotificationTweetDetail(){
+            notification.InvokeAsyncSafe(notification.ShowTweetDetail);
+        }
+
         public void ScreenshotTweet(string html, int width, int height){
             form.InvokeAsyncSafe(() => form.OnTweetScreenshotReady(html, width, height));
         }
diff --git a/Resources/Scripts/code.js b/Resources/Scripts/code.js
index 3352a143..b89d362a 100644
--- a/Resources/Scripts/code.js
+++ b/Resources/Scripts/code.js
@@ -182,6 +182,12 @@
           this.outerHTML = this.innerHTML;
         });
         
+        html.find("p.link-complex-target").filter(function(){
+          return $(this).text() === "Show this thread";
+        }).first().each(function(){
+          this.id = "tduck-show-thread";
+        });
+        
         let type = tweet.getChirpType();
         
         if (type === "follow"){
@@ -286,6 +292,7 @@
       tags.push(".tweet-context .nbfc { text-overflow: ellipsis !important; white-space: nowrap !important }"); // force ellipsis on long usernames
       tags.push(".activity-header { align-items: center !important; margin-bottom: 4px !important }"); // tweak alignment of avatar and text in notifications
       tags.push(".activity-header .tweet-timestamp { line-height: unset !important }"); // fix timestamp position in notifications
+      tags.push("#tduck-show-thread { display: inline-block !important; cursor: pointer }");
       
       if (fontSizeName === "smallest"){
         tags.push(".badge-verified:before { width: 13px !important; height: 13px !important; background-position: -223px -98px !important }"); // fix cut off badge icon
diff --git a/Resources/Scripts/notification.js b/Resources/Scripts/notification.js
index dcf6b123..125e921d 100644
--- a/Resources/Scripts/notification.js
+++ b/Resources/Scripts/notification.js
@@ -106,6 +106,19 @@
     window.setTimeout($TD.fixClipboard, 0);
   });
   
+  //
+  // Block: Setup a handler for 'Show this thread'.
+  //
+  (function(){
+    var btn = document.getElementById("tduck-show-thread");
+    return if !btn;
+    
+    btn.addEventListener("click", function(){
+      $TD.showNotificationTweetDetail();
+    });
+  })();
+  
+  //
   // Block: Setup a skip button.
   //
   if (!document.body.hasAttribute("td-example-notification")){