fix(route/twitter/user): missing all replies (#12912)

Signed-off-by: Rongrong <i@rong.moe>
This commit is contained in:
Rongrong
2023-07-30 04:51:31 +08:00
committed by GitHub
parent 8eb9b5b71d
commit c5feec07f3
+14 -16
View File
@@ -134,26 +134,21 @@ const tweetDetail = (userId, params) =>
['threaded_conversation_with_injections']
);
function gatherLegacyFromData(entries, filter = 'tweet-') {
function gatherLegacyFromData(entries, filterNested = undefined, userId = undefined) {
const tweets = [];
const filte_entries = [];
const filteredEntries = [];
entries.forEach((entry) => {
const entryId = entry.entryId;
if (entryId) {
if (filter === 'none') {
if (entryId.startsWith('tweet-')) {
filte_entries.push(entry);
} else if (entryId.startsWith('homeConversation-') || entryId.startsWith('conversationthread-')) {
filte_entries.push(...entry.content.items);
}
} else {
if (entryId.startsWith(filter)) {
filte_entries.push(entry);
}
if (entryId.startsWith('tweet-')) {
filteredEntries.push(entry);
}
if (filterNested && filterNested.some((f) => entryId.startsWith(f))) {
filteredEntries.push(...entry.content.items);
}
}
});
filte_entries.forEach((entry) => {
filteredEntries.forEach((entry) => {
if (entry.entryId) {
const content = entry.content || entry.item;
let tweet = content?.itemContent?.tweet_results?.result;
@@ -178,7 +173,9 @@ function gatherLegacyFromData(entries, filter = 'tweet-') {
if (retweet) {
legacy.retweeted_status = retweet.legacy;
}
tweets.push(legacy);
if (userId === undefined || legacy.user_id_str === userId + '') {
tweets.push(legacy);
}
}
}
}
@@ -187,10 +184,11 @@ function gatherLegacyFromData(entries, filter = 'tweet-') {
}
const getUserTweetsByID = async (id, params = {}) => gatherLegacyFromData(await timelineTweets(id, params));
const getUserTweetsAndRepliesByID = async (id, params = {}) => gatherLegacyFromData(await timelineTweetsAndReplies(id, params));
// TODO: show the whole conversation instead of just the reply tweet
const getUserTweetsAndRepliesByID = async (id, params = {}) => gatherLegacyFromData(await timelineTweetsAndReplies(id, params), ['profile-conversation-'], id);
const getUserMediaByID = async (id, params = {}) => gatherLegacyFromData(await timelineMedia(id, params));
const getUserLikesByID = async (id, params = {}) => gatherLegacyFromData(await timelineLikes(id, params));
const getUserTweetByStatus = async (id, params = {}) => gatherLegacyFromData(await tweetDetail(id, params), 'none');
const getUserTweetByStatus = async (id, params = {}) => gatherLegacyFromData(await tweetDetail(id, params), ['homeConversation-', 'conversationthread-']);
const excludeRetweet = function (tweets) {
const excluded = [];