fix: Do not sort user tweets since it's in reverse-chronological order
This commit is contained in:
@@ -12,8 +12,6 @@ import getUserByUsername from './get-user-by-username';
|
|||||||
|
|
||||||
type IGetUserTweetsOptions = {
|
type IGetUserTweetsOptions = {
|
||||||
currentUser: boolean;
|
currentUser: boolean;
|
||||||
userId?: string;
|
|
||||||
lastInternalId?: string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const getUserTweets = async (
|
const getUserTweets = async (
|
||||||
@@ -39,7 +37,7 @@ const getUserTweets = async (
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
const params: IJSONObject = {
|
const params: IJSONObject = {
|
||||||
since_id: options.lastInternalId,
|
since_id: $.execution.testRun ? null : $.flow.lastInternalId,
|
||||||
pagination_token: response?.data?.meta?.next_token,
|
pagination_token: response?.data?.meta?.next_token,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -63,15 +61,13 @@ const getUserTweets = async (
|
|||||||
response.data.data.forEach((tweet: IJSONObject) => {
|
response.data.data.forEach((tweet: IJSONObject) => {
|
||||||
tweets.data.push({
|
tweets.data.push({
|
||||||
raw: tweet,
|
raw: tweet,
|
||||||
meta: { internalId: tweet.id as string },
|
meta: {
|
||||||
|
internalId: tweet.id as string,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} while (response.data.meta.next_token && options.lastInternalId);
|
} while (response.data.meta.next_token && !$.execution.testRun);
|
||||||
|
|
||||||
tweets.data.sort((tweet, nextTweet) => {
|
|
||||||
return (tweet.raw.id as number) - (nextTweet.raw.id as number);
|
|
||||||
});
|
|
||||||
|
|
||||||
return tweets;
|
return tweets;
|
||||||
};
|
};
|
||||||
|
@@ -20,7 +20,6 @@ export default {
|
|||||||
async run($: IGlobalVariable) {
|
async run($: IGlobalVariable) {
|
||||||
return await getUserTweets($, {
|
return await getUserTweets($, {
|
||||||
currentUser: true,
|
currentUser: true,
|
||||||
lastInternalId: $.flow.lastInternalId,
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@@ -32,8 +32,6 @@ export default {
|
|||||||
async run($: IGlobalVariable) {
|
async run($: IGlobalVariable) {
|
||||||
return await getUserTweets($, {
|
return await getUserTweets($, {
|
||||||
currentUser: false,
|
currentUser: false,
|
||||||
userId: $.step.parameters.username as string,
|
|
||||||
lastInternalId: $.flow.lastInternalId,
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user