|
@@ -204,6 +204,13 @@ class default_1 {
|
|
})
|
|
})
|
|
.then(() => sendTweets(cacheId, msg, text, author));
|
|
.then(() => sendTweets(cacheId, msg, text, author));
|
|
}, this.webshotDelay));
|
|
}, this.webshotDelay));
|
|
|
|
+ this.handleRetweet = (tweet) => {
|
|
|
|
+ const retweetRef = (tweet.data.referenced_tweets || []).find(ref => ref.type === 'retweeted');
|
|
|
|
+ if (retweetRef)
|
|
|
|
+ return this.client.v2.singleTweet(retweetRef.id, v2SingleParams)
|
|
|
|
+ .then(({ data: { referenced_tweets }, includes: { media } }) => (Object.assign(Object.assign({}, tweet), { data: Object.assign(Object.assign({}, tweet.data), { referenced_tweets: [retweetRef, ...(referenced_tweets || [])] }), includes: Object.assign(Object.assign({}, tweet.includes), { media }) })));
|
|
|
|
+ return Promise.resolve(tweet);
|
|
|
|
+ };
|
|
this.getTweet = (id, sender, refresh = false) => ((this.redis && !refresh) ?
|
|
this.getTweet = (id, sender, refresh = false) => ((this.redis && !refresh) ?
|
|
this.redis.waitForProcess(`webshot/${id}`, this.webshotDelay * 4)
|
|
this.redis.waitForProcess(`webshot/${id}`, this.webshotDelay * 4)
|
|
.then(() => this.redis.getContent(`webshot/${id}`))
|
|
.then(() => this.redis.getContent(`webshot/${id}`))
|
|
@@ -218,10 +225,7 @@ class default_1 {
|
|
.then((tweet) => {
|
|
.then((tweet) => {
|
|
if (tweet.data.text) {
|
|
if (tweet.data.text) {
|
|
logger.debug(`api returned tweet ${JSON.stringify(tweet)} for query id=${id}`);
|
|
logger.debug(`api returned tweet ${JSON.stringify(tweet)} for query id=${id}`);
|
|
- const retweetRef = (tweet.data.referenced_tweets || []).find(ref => ref.type === 'retweeted');
|
|
|
|
- if (retweetRef)
|
|
|
|
- return this.client.v2.singleTweet(retweetRef.id, v2SingleParams)
|
|
|
|
- .then(({ includes: { media } }) => (Object.assign(Object.assign({}, tweet), { includes: Object.assign(Object.assign({}, tweet.includes), { media }) })));
|
|
|
|
|
|
+ return this.handleRetweet(tweet);
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
logger.debug(`skipped querying api as this tweet has been cached`);
|
|
logger.debug(`skipped querying api as this tweet has been cached`);
|
|
@@ -289,13 +293,7 @@ class default_1 {
|
|
users: [includes.author(tweet)]
|
|
users: [includes.author(tweet)]
|
|
}
|
|
}
|
|
})))
|
|
})))
|
|
- .then(tweets => Promise.all(tweets.map(tweet => {
|
|
|
|
- const retweetRef = (tweet.data.referenced_tweets || []).find(ref => ref.type === 'retweeted');
|
|
|
|
- if (retweetRef)
|
|
|
|
- return this.client.v2.singleTweet(retweetRef.id, v2SingleParams)
|
|
|
|
- .then(({ includes: { media } }) => (Object.assign(Object.assign({}, tweet), { includes: Object.assign(Object.assign({}, tweet.includes), { media }) })));
|
|
|
|
- return tweet;
|
|
|
|
- })));
|
|
|
|
|
|
+ .then(tweets => Promise.all(tweets.map(this.handleRetweet)));
|
|
};
|
|
};
|
|
this.work = () => {
|
|
this.work = () => {
|
|
const lock = this.lock;
|
|
const lock = this.lock;
|