fix(route/twitter/web-api): excludeReplies=1 (#14290)

Fixes #14285

The postprocessing that removes replies accidentally removed all tweets
except for the first one after the recent Twitter update.

Signed-off-by: Rongrong <i@rong.moe>
This commit is contained in:
Rongrong 2024-01-21 06:11:01 +00:00 committed by GitHub
parent cd48da470e
commit e8a33d80fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 2 deletions

View File

@ -258,9 +258,12 @@ const getUserTweets = async (cache, id, params = {}) => {
const idSet = new Set();
tweets = tweets
.filter((tweet) => !tweet.in_reply_to_screen_name) // exclude replies
.map((tweet) => (idSet.has(tweet.id_str) ? null : idSet.add(tweet.id_str)) && tweet) // deduplicate
.map((tweet) => {
const id_str = tweet.id_str || tweet.conversation_id_str;
return !idSet.has(id_str) && idSet.add(id_str) && tweet;
}) // deduplicate
.filter(Boolean) // remove null
.sort((a, b) => b.id_str - a.id_str) // desc
.sort((a, b) => (b.id_str || b.conversation_id_str) - (a.id_str || a.conversation_id_str)) // desc
.slice(0, 20);
cache.set(cacheKey, JSON.stringify(tweets));
return tweets;