mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-01 08:34:11 +02:00
Fix multiple notifications showing for the same tweet in multiple columns
This commit is contained in:
parent
5c7eb0535d
commit
39ae9b8ba0
@ -80,43 +80,76 @@
|
|||||||
//
|
//
|
||||||
// Function: Event callback for a new tweet.
|
// Function: Event callback for a new tweet.
|
||||||
//
|
//
|
||||||
var onNewTweet = function(column, tweet){
|
var onNewTweet = (function(){
|
||||||
if (column.model.getHasNotification()){
|
let recentTweets = new Set();
|
||||||
let html = $(tweet.render({
|
let recentTweetTimer = null;
|
||||||
withFooter: false,
|
|
||||||
withTweetActions: false,
|
let startRecentTweetTimer = () => {
|
||||||
withMediaPreview: true,
|
if (recentTweetTimer){
|
||||||
isMediaPreviewOff: true,
|
window.clearTimeout(recentTweetTimer);
|
||||||
isMediaPreviewSmall: false,
|
|
||||||
isMediaPreviewLarge: false
|
|
||||||
}));
|
|
||||||
|
|
||||||
html.css("border", "0");
|
|
||||||
html.find("footer").last().remove(); // apparently withTweetActions breaks for certain tweets, nice
|
|
||||||
html.find(".js-media").last().remove(); // and quoted tweets still show media previews, nice nice
|
|
||||||
html.find(".js-quote-detail").removeClass("is-actionable"); // prevent quoted tweets from changing the cursor
|
|
||||||
|
|
||||||
html.find("a[href='#']").each(function(){ // remove <a> tags around links that don't lead anywhere (such as account names the tweet replied to)
|
|
||||||
this.outerHTML = this.innerHTML;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (tweet.getChirpType().includes("list_member")){
|
|
||||||
html.find(".activity-header").first().css("margin-top", "2px");
|
|
||||||
html.find(".avatar").first().css("margin-bottom", "0");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let source = tweet.getRelatedTweet();
|
recentTweetTimer = window.setTimeout(() => {
|
||||||
let duration = source ? source.text.length+(source.quotedTweet ? source.quotedTweet.text.length : 0) : tweet.text.length;
|
recentTweetTimer = null;
|
||||||
let tweetUrl = source ? source.getChirpURL() : "";
|
recentTweets.clear();
|
||||||
let quoteUrl = source && source.quotedTweet ? source.quotedTweet.getChirpURL() : "";
|
}, 10000);
|
||||||
|
};
|
||||||
$TD.onTweetPopup(columnTypes[column.getColumnType()] || "", html.html(), duration, tweetUrl, quoteUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (column.model.getHasSound()){
|
let checkRecentTweet = id => {
|
||||||
$TD.onTweetSound();
|
if (recentTweets.size > 50){
|
||||||
}
|
recentTweets.clear();
|
||||||
};
|
}
|
||||||
|
else if (recentTweets.has(id)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
recentTweets.add(id);
|
||||||
|
startRecentTweetTimer();
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
return function(column, tweet){
|
||||||
|
if (checkRecentTweet(tweet.id)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (column.model.getHasNotification()){
|
||||||
|
let html = $(tweet.render({
|
||||||
|
withFooter: false,
|
||||||
|
withTweetActions: false,
|
||||||
|
withMediaPreview: true,
|
||||||
|
isMediaPreviewOff: true,
|
||||||
|
isMediaPreviewSmall: false,
|
||||||
|
isMediaPreviewLarge: false
|
||||||
|
}));
|
||||||
|
|
||||||
|
html.css("border", "0");
|
||||||
|
html.find("footer").last().remove(); // apparently withTweetActions breaks for certain tweets, nice
|
||||||
|
html.find(".js-media").last().remove(); // and quoted tweets still show media previews, nice nice
|
||||||
|
html.find(".js-quote-detail").removeClass("is-actionable"); // prevent quoted tweets from changing the cursor
|
||||||
|
|
||||||
|
html.find("a[href='#']").each(function(){ // remove <a> tags around links that don't lead anywhere (such as account names the tweet replied to)
|
||||||
|
this.outerHTML = this.innerHTML;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (tweet.getChirpType().includes("list_member")){
|
||||||
|
html.find(".activity-header").first().css("margin-top", "2px");
|
||||||
|
html.find(".avatar").first().css("margin-bottom", "0");
|
||||||
|
}
|
||||||
|
|
||||||
|
let source = tweet.getRelatedTweet();
|
||||||
|
let duration = source ? source.text.length+(source.quotedTweet ? source.quotedTweet.text.length : 0) : tweet.text.length;
|
||||||
|
let tweetUrl = source ? source.getChirpURL() : "";
|
||||||
|
let quoteUrl = source && source.quotedTweet ? source.quotedTweet.getChirpURL() : "";
|
||||||
|
|
||||||
|
$TD.onTweetPopup(columnTypes[column.getColumnType()] || "", html.html(), duration, tweetUrl, quoteUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (column.model.getHasSound()){
|
||||||
|
$TD.onTweetSound();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
//
|
//
|
||||||
// Function: Retrieves the tags to be put into <head> for notification HTML code.
|
// Function: Retrieves the tags to be put into <head> for notification HTML code.
|
||||||
|
Loading…
Reference in New Issue
Block a user