Skip to content

Commit

Permalink
fix(route/twitter/web-api): excludeReplies=1 (DIYgod#14290)
Browse files Browse the repository at this point in the history
Fixes DIYgod#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>
  • Loading branch information
Rongronggg9 authored and HumXC committed Jan 22, 2024
1 parent 4a1b6e9 commit e3d6299
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/v2/twitter/web-api/twitter-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e3d6299

Please sign in to comment.