mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-10 17:34:07 +02:00
Fix 'Save image as...' usernames in quoted tweets & more refactoring
This commit is contained in:
parent
20f0445b10
commit
4f5075ac54
@ -13,13 +13,16 @@ namespace TweetDuck.Core.Bridge{
|
|||||||
sealed class TweetDeckBridge{
|
sealed class TweetDeckBridge{
|
||||||
public static string LastHighlightedTweetUrl = string.Empty;
|
public static string LastHighlightedTweetUrl = string.Empty;
|
||||||
public static string LastHighlightedQuoteUrl = string.Empty;
|
public static string LastHighlightedQuoteUrl = string.Empty;
|
||||||
public static string LastHighlightedTweetAuthor = string.Empty;
|
private static string LastHighlightedTweetAuthors = string.Empty;
|
||||||
public static string[] LastHighlightedTweetImages = StringUtils.EmptyArray;
|
private static string LastHighlightedTweetImages = string.Empty;
|
||||||
public static Dictionary<string, string> SessionData = new Dictionary<string, string>(2);
|
|
||||||
|
public static string[] LastHighlightedTweetAuthorsArray => LastHighlightedTweetAuthors.Split(';');
|
||||||
|
public static string[] LastHighlightedTweetImagesArray => LastHighlightedTweetImages.Split(';');
|
||||||
|
|
||||||
|
private static readonly Dictionary<string, string> SessionData = new Dictionary<string, string>(2);
|
||||||
|
|
||||||
public static void ResetStaticProperties(){
|
public static void ResetStaticProperties(){
|
||||||
LastHighlightedTweetUrl = LastHighlightedQuoteUrl = LastHighlightedTweetAuthor = string.Empty;
|
LastHighlightedTweetUrl = LastHighlightedQuoteUrl = LastHighlightedTweetAuthors = LastHighlightedTweetImages = string.Empty;
|
||||||
LastHighlightedTweetImages = StringUtils.EmptyArray;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RestoreSessionData(IFrame frame){
|
public static void RestoreSessionData(IFrame frame){
|
||||||
@ -59,12 +62,12 @@ public void SetLastRightClickInfo(string type, string link){
|
|||||||
form.InvokeAsyncSafe(() => ContextMenuBase.SetContextInfo(type, link));
|
form.InvokeAsyncSafe(() => ContextMenuBase.SetContextInfo(type, link));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetLastHighlightedTweet(string tweetUrl, string quoteUrl, string author, string imageList){
|
public void SetLastHighlightedTweet(string tweetUrl, string quoteUrl, string authors, string imageList){
|
||||||
form.InvokeAsyncSafe(() => {
|
form.InvokeAsyncSafe(() => {
|
||||||
LastHighlightedTweetUrl = tweetUrl;
|
LastHighlightedTweetUrl = tweetUrl;
|
||||||
LastHighlightedQuoteUrl = quoteUrl;
|
LastHighlightedQuoteUrl = quoteUrl;
|
||||||
LastHighlightedTweetAuthor = author;
|
LastHighlightedTweetAuthors = authors;
|
||||||
LastHighlightedTweetImages = imageList.Split(';');
|
LastHighlightedTweetImages = imageList;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
using TweetDuck.Core.Controls;
|
using TweetDuck.Core.Controls;
|
||||||
using TweetDuck.Core.Utils;
|
using TweetDuck.Core.Utils;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace TweetDuck.Core.Handling{
|
namespace TweetDuck.Core.Handling{
|
||||||
abstract class ContextMenuBase : IContextMenuHandler{
|
abstract class ContextMenuBase : IContextMenuHandler{
|
||||||
@ -38,7 +39,7 @@ private static string GetMediaLink(IContextMenuParams parameters){
|
|||||||
|
|
||||||
private readonly Form form;
|
private readonly Form form;
|
||||||
|
|
||||||
private string lastHighlightedTweetAuthor;
|
private string[] lastHighlightedTweetAuthors;
|
||||||
private string[] lastHighlightedTweetImageList;
|
private string[] lastHighlightedTweetImageList;
|
||||||
|
|
||||||
protected ContextMenuBase(Form form){
|
protected ContextMenuBase(Form form){
|
||||||
@ -47,13 +48,13 @@ protected ContextMenuBase(Form form){
|
|||||||
|
|
||||||
public virtual void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model){
|
public virtual void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model){
|
||||||
if (!TwitterUtils.IsTweetDeckWebsite(frame) || browser.IsLoading){
|
if (!TwitterUtils.IsTweetDeckWebsite(frame) || browser.IsLoading){
|
||||||
lastHighlightedTweetAuthor = string.Empty;
|
lastHighlightedTweetAuthors = StringUtils.EmptyArray;
|
||||||
lastHighlightedTweetImageList = StringUtils.EmptyArray;
|
lastHighlightedTweetImageList = StringUtils.EmptyArray;
|
||||||
ContextInfo = default(KeyValuePair<string, string>);
|
ContextInfo = default(KeyValuePair<string, string>);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
lastHighlightedTweetAuthor = TweetDeckBridge.LastHighlightedTweetAuthor;
|
lastHighlightedTweetAuthors = TweetDeckBridge.LastHighlightedTweetAuthorsArray;
|
||||||
lastHighlightedTweetImageList = TweetDeckBridge.LastHighlightedTweetImages;
|
lastHighlightedTweetImageList = TweetDeckBridge.LastHighlightedTweetImagesArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasTweetImage = IsImage;
|
bool hasTweetImage = IsImage;
|
||||||
@ -124,13 +125,13 @@ public virtual bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser br
|
|||||||
TwitterUtils.DownloadVideo(GetMediaLink(parameters));
|
TwitterUtils.DownloadVideo(GetMediaLink(parameters));
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
TwitterUtils.DownloadImage(GetMediaLink(parameters), lastHighlightedTweetAuthor, ImageQuality);
|
TwitterUtils.DownloadImage(GetMediaLink(parameters), lastHighlightedTweetAuthors.LastOrDefault(), ImageQuality);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MenuSaveTweetImages:
|
case MenuSaveTweetImages:
|
||||||
TwitterUtils.DownloadImages(lastHighlightedTweetImageList, lastHighlightedTweetAuthor, ImageQuality);
|
TwitterUtils.DownloadImages(lastHighlightedTweetImageList, lastHighlightedTweetAuthors.LastOrDefault(), ImageQuality);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MenuOpenDevTools:
|
case MenuOpenDevTools:
|
||||||
|
@ -450,13 +450,13 @@
|
|||||||
return !!highlightedColumnObj;
|
return !!highlightedColumnObj;
|
||||||
};
|
};
|
||||||
|
|
||||||
var updateHighlightedTweet = function(ele, obj, link, embeddedLink, author, imageList){
|
var updateHighlightedTweet = function(ele, obj, tweetUrl, quoteUrl, authors, imageList){
|
||||||
highlightedTweetEle = ele;
|
highlightedTweetEle = ele;
|
||||||
highlightedTweetObj = obj;
|
highlightedTweetObj = obj;
|
||||||
|
|
||||||
if (lastTweet !== link){
|
if (lastTweet !== tweetUrl){
|
||||||
$TD.setLastHighlightedTweet(link, embeddedLink, author, imageList);
|
$TD.setLastHighlightedTweet(tweetUrl, quoteUrl, authors, imageList);
|
||||||
lastTweet = link;
|
lastTweet = tweetUrl;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -480,13 +480,13 @@
|
|||||||
return if !tweet;
|
return if !tweet;
|
||||||
|
|
||||||
if (tweet.chirpType === TD.services.ChirpBase.TWEET){
|
if (tweet.chirpType === TD.services.ChirpBase.TWEET){
|
||||||
let link = tweet.getChirpURL();
|
let tweetUrl = tweet.getChirpURL();
|
||||||
let embedded = tweet.quotedTweet ? tweet.quotedTweet.getChirpURL() : "";
|
let quoteUrl = tweet.quotedTweet ? tweet.quotedTweet.getChirpURL() : "";
|
||||||
let username = tweet.getMainUser().screenName;
|
let authors = tweet.quotedTweet ? [ tweet.getMainUser().screenName, tweet.quotedTweet.getMainUser().screenName ].join(";") : tweet.getMainUser().screenName;
|
||||||
let images = tweet.hasImage() ? tweet.getMedia().filter(item => !item.isAnimatedGif).map(item => item.entity.media_url_https+":small").join(";") : "";
|
let imageList = tweet.hasImage() ? tweet.getMedia().filter(item => !item.isAnimatedGif).map(item => item.entity.media_url_https+":small").join(";") : "";
|
||||||
// TODO maybe handle embedded images too?
|
// TODO maybe handle embedded images too?
|
||||||
|
|
||||||
updateHighlightedTweet(me, tweet, link || "", embedded || "", username, images);
|
updateHighlightedTweet(me, tweet, tweetUrl || "", quoteUrl || "", authors, imageList);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
updateHighlightedTweet(me, tweet, "", "", "", "");
|
updateHighlightedTweet(me, tweet, "", "", "", "");
|
||||||
|
Loading…
Reference in New Issue
Block a user