|
@@ -427,11 +427,16 @@ export default class {
|
|
|
private get = <T extends 'userTimeline' | 'listTweets'>(
|
|
|
type: T, targetId: string, params: Parameters<typeof this.client.v2[T]>[1]
|
|
|
) => {
|
|
|
+ const {since_id, max_results} = (params as Twitter.TweetV2UserTimelineParams);
|
|
|
const getMore = (res: Twitter.TweetUserTimelineV2Paginator | Twitter.TweetV2ListTweetsPaginator) => {
|
|
|
if (res.errors && res.errors.length > 0) throw res.errors[0];
|
|
|
- if (!res.meta.next_token || res.meta.result_count >= params.max_results) return res;
|
|
|
+ if (!res.meta.next_token || // at last page
|
|
|
+ BigNumOps.compare(res.tweets.slice(-1)[0].id, since_id || '0') !== 1 || // at specified boundary
|
|
|
+ !since_id && res.meta.result_count >= max_results // at specified max count
|
|
|
+ ) return res;
|
|
|
return res.fetchNext().then<typeof res>(getMore);
|
|
|
};
|
|
|
+ if (type === 'listTweets') delete (params as any).since_id;
|
|
|
return this.client.v2[type](targetId, params).then(getMore)
|
|
|
.then(({includes, tweets}) => tweets.map((tweet): Tweet =>
|
|
|
({
|