Commit d30f0e1f authored by Iván Sánchez Ortega's avatar Iván Sánchez Ortega

Re-enable logging original tweet. Deshortify echoed and quoted items properly.

parent 31d74465
......@@ -9,7 +9,7 @@
"dependencies": {
"chalk256": "^5.1.0",
"configstore": "^3.0.0",
"deshortify": "^0.1.0",
"deshortify": "^0.1.2",
"flatten-obj": "^3.1.0",
"get-urls": "^7.0.0",
"he": "^1.1.1",
......
......@@ -28,50 +28,61 @@ export default function deshortify(item) {
let urls = getUrls(item.str);
// console.log(urls);
item._deshortifyOriginalUrls = urls;
// console.log('Detected URLs:', urls);
var urlPromises = (Array.from(urls)).map( (url)=>{
var ownUrlPromises = (Array.from(urls)).map( (url)=>{
return deshortifier.deshortify(url)
.then(deshortified=>[url, deshortified])
.catch(err=>console.error(err));
});
let ownItemPromise = Promise.all(ownUrlPromises).then( resolvedUrls=>{
// return Promise.all(urlPromises).then( resolvedUrls=>{
//
// // console.log(resolvedUrls);
// resolvedUrls.forEach(([original, replacement])=>{
// if (original !== replacement) {
// console.log('Replacing: ', original, ' → ', replacement);
// item.str = item.str.replace(original, replacement);
// }
// });
//
// return item;
// } );
item._deshortifyResolvedUrls = urls;
// console.log(resolvedUrls);
resolvedUrls.forEach(([original, replacement])=>{
if (original !== replacement) {
console.log('Replacing: ', original, ' → ', replacement);
item.str = item.str.replace(original, replacement);
}
});
return Promise.race([
Promise.all(urlPromises).then( resolvedUrls=>{
return item;
});
// console.log(resolvedUrls);
resolvedUrls.forEach(([original, replacement])=>{
if (original !== replacement) {
// console.log('Replacing: ', original, ' → ', replacement);
item.str = item.str.replace(original, replacement);
}
});
// Does this item echo another? Then deshortify its URLs too.
if (item.echoed) {
// console.log('Deshortifying also: ', item.echoed);
let echoedItemPromise = deshortify(item.echoed);
return item;
} ),
ownItemPromise = Promise.all([ownItemPromise, echoedItemPromise]).then(([own, echoed])=>{
own.echoed = echoed;
return own;
});
}
new Promise(function (resolve, reject) { setTimeout(reject, 10000) })
// Does this item quote another? Then deshortify its URLs too.
if (item.quoted) {
// console.log('Deshortifying also: ', item.quoted);
let echoedItemPromise = deshortify(item.quoted);
]).catch((err=>{
ownItemPromise = Promise.all([ownItemPromise, echoedItemPromise]).then(([own, quoted])=>{
own.quoted = quoted;
return own;
});
}
console.error('Resolving URLs took too long. URLs were:', urls);
}));
return Promise.race([
ownItemPromise,
new Promise(function (resolve, reject) { setTimeout(reject, 10000) })
]).catch((err=>{
/// FIXME: Should be vorpal + chalk
console.error('Resolving URLs took too long. URLs were:', urls);
return Promise.resolve(item);
}));
}
......
......@@ -84,6 +84,7 @@ class TwitterAccount extends Account {
// Get a few of the last statuses in the main timeline
this._tw.get('statuses/home_timeline', {
count: 100
// count: 10
}, (err, msgs, response)=>{
if (err) {
vorpal.log(chalk.red(err));
......@@ -170,6 +171,14 @@ class TwitterAccount extends Account {
// console.log('tweet is truncated: ', msg.truncated);
// console.log(msg.entities.urls);
// if (msg.truncated) {
// // This is the retweeted part of a RT update.
// /// TODO: Return a promise that fetches the original, untruncated tweet,
// /// and normalizes it.
//
// }
if (msg.extended_tweet) {
// return this._normalize(Object.assign({}, msg.extended_tweet, msg);
msg.text = msg.extended_tweet.full_text;
......@@ -181,12 +190,13 @@ class TwitterAccount extends Account {
return ({
accountNumber: this._accountNumber,
accountId: this._id,
raw: channel && msg,
sender: msg.user.screen_name,
str: '',
channel: channel,
media: [],
timestamp: Date.parse(msg.created_at),
echoed: this._normalize(msg.retweeted_status)
echoed: this._normalize(msg.retweeted_status, null)
});
// msg.text = msg.retweeted_status.text;
}
......@@ -217,11 +227,12 @@ class TwitterAccount extends Account {
sender: msg.user.screen_name,
str: str,
channel: channel,
raw: channel && msg,
// realtime: true,
// media: msg.media_attachments.map(i=>i.text_url || i.remote_url),
media: allMedia,
timestamp: Date.parse(msg.created_at),
quoted: msg.quoted_status && this._normalize(msg.quoted_status)
quoted: msg.quoted_status && this._normalize(msg.quoted_status, null)
});
} else {
this._vorpal.log(chalk.red(''));
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment