mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2024-11-23 01:55:27 +03:00
[TwitterBridge] Improve timeline processing for username mode (#1946)
This commit is contained in:
parent
65be209a47
commit
76c38332ee
1 changed files with 53 additions and 5 deletions
|
@ -205,10 +205,22 @@ EOD
|
|||
. urlencode($this->getInput('q'))
|
||||
. '&tweet_mode=extended&tweet_search_mode=live';
|
||||
case 'By username':
|
||||
return self::API_URI
|
||||
. '/2/timeline/profile/'
|
||||
. $this->getRestId($this->getInput('u'))
|
||||
. '.json?tweet_mode=extended';
|
||||
// use search endpoint if without replies or without retweets enabled
|
||||
if ($this->getInput('noretweet') || $this->getInput('norep')) {
|
||||
$query = 'from:' . $this->getInput('u');
|
||||
// Twitter's from: search excludes retweets by default
|
||||
if (!$this->getInput('noretweet')) $query .= ' include:nativeretweets';
|
||||
if ($this->getInput('norep')) $query .= ' exclude:replies';
|
||||
return self::API_URI
|
||||
. '/2/search/adaptive.json?q='
|
||||
. urlencode($query)
|
||||
. '&tweet_mode=extended&tweet_search_mode=live';
|
||||
} else {
|
||||
return self::API_URI
|
||||
. '/2/timeline/profile/'
|
||||
. $this->getRestId($this->getInput('u'))
|
||||
. '.json?tweet_mode=extended';
|
||||
}
|
||||
case 'By list':
|
||||
return self::API_URI
|
||||
. '/2/timeline/list.json?list_id='
|
||||
|
@ -260,7 +272,35 @@ EOD
|
|||
}
|
||||
}
|
||||
|
||||
foreach($data->globalObjects->tweets as $tweet) {
|
||||
$tweets = array();
|
||||
|
||||
// Extract tweets from timeline property when in username mode
|
||||
// This fixes number of issues:
|
||||
// * If there's a retweet of a quote tweet, the quoted tweet will not appear in results (since it wasn't retweeted directly)
|
||||
// * Pinned tweets do not get stuck at the bottom
|
||||
if ($this->queriedContext === 'By username') {
|
||||
foreach($data->timeline->instructions[0]->addEntries->entries as $tweet) {
|
||||
if (!isset($tweet->content->item)) continue;
|
||||
$tweetId = $tweet->content->item->content->tweet->id;
|
||||
$selectedTweet = $this->getTweet($tweetId, $data->globalObjects);
|
||||
if (!$selectedTweet) continue;
|
||||
// If this is a retweet, it will contain shorter text and will point to the original full tweet (retweeted_status_id_str).
|
||||
// Let's use the original tweet text.
|
||||
if (isset($selectedTweet->retweeted_status_id_str)) {
|
||||
$tweetId = $selectedTweet->retweeted_status_id_str;
|
||||
$selectedTweet = $this->getTweet($tweetId, $data->globalObjects);
|
||||
if (!$selectedTweet) continue;
|
||||
}
|
||||
// use $tweetId as key to avoid duplicates (e.g. user retweeting their own tweet)
|
||||
$tweets[$tweetId] = $selectedTweet;
|
||||
}
|
||||
} else {
|
||||
foreach($data->globalObjects->tweets as $tweet) {
|
||||
$tweets[] = $tweet;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($tweets as $tweet) {
|
||||
|
||||
/* Debug::log('>>> ' . json_encode($tweet)); */
|
||||
// Skip spurious retweets
|
||||
|
@ -567,4 +607,12 @@ EOD;
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getTweet($tweetId, $apiData) {
|
||||
if (property_exists($apiData->tweets, $tweetId)) {
|
||||
return $apiData->tweets->$tweetId;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue