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

Remember to deshortify echoes and quotes. Request twitter rate limits on startup.

parent 28df723c
......@@ -29,7 +29,7 @@ export default function deshortify(item) {
let urls = item.str.match(urlRegex);
if (!urls) { return item; }
if (!urls) { urls = []; } // Item itself doesn't have any URLs, but might have an echo/quote
item._deshortifyOriginalUrls = urls;
// console.log('Detected URLs:', urls);
......
......@@ -47,24 +47,40 @@ class TwitterAccount extends Account {
this.emit(-Infinity, initialTimeLock.promise);
// console.log('TW platform locked the main stream on user init');
this._tw.get('account/verify_credentials', {}, (err, json)=>{
Promise.all([
this._getEndpointPromise('account/verify_credentials'),
this._getEndpointPromise('application/rate_limit_status')
]).then(([
credentials,
rateLimits
])=>{
vorpal.log(
chalk.purple('You are logged in the Twitter platform as '),
chalk.cyan(json.screen_name),
chalk.cyan(credentials.screen_name),
// chalk.purple(' in server '),
// chalk.cyan(opts.api_url.replace(/.*:\/\//,'').replace(/\/.*/, '')),
chalk.purple(', account badge is '),
chalk.cyan(opts.badge)
);
this._id = json.screen_name + '@twitter';
vorpal.log(
chalk.purple('Rate limits at start-up time are:'),
chalk.cyan(JSON.stringify(rateLimits))
);
this._id = credentials.screen_name + '@twitter';
this._idStr = json.id_str;
this._idStr = credentials.id_str;
// Hackishly listen to the user's main stream
// TODO: Split this out, set a flag when streaming is working
// TODO: Handle errors when the network connectivity changes
// TODO: Handle errors when receiving a HTTP status response of 420 (connecting too often, or too many clients)
this._stream = this._tw.stream('user', {
// replies: "all", // Should explicitly listen to the "replies" channel
// track: "foo,bar" // Should use this for listening to search terms channels
// track: "foo,bar" // Should use this for listening to search terms channels
stall_warnings: true
}, (stream)=>{
stream.on('data', (ev)=>{
......@@ -136,7 +152,6 @@ class TwitterAccount extends Account {
);
});
});
}
......@@ -165,7 +180,7 @@ class TwitterAccount extends Account {
let replyStatusId = item.raw.id_str;
let replyStatusScreenName = "@" + item.raw.user.screen_name;
if (!str.toLowerCase().indexOf( replyStatusScreenName.toLowerCase() ) === -1) {
if (str.toLowerCase().indexOf( replyStatusScreenName.toLowerCase() ) === -1) {
/// FIXME!!! This will match partial usernames (e.g. searching for @john
/// will match @johnDoe). Should use some kind of regexp here.
......@@ -219,6 +234,14 @@ class TwitterAccount extends Account {
});
}
// A helper to promisify calls to this._tw.get().
_getEndpointPromise(endpoint) {
return new Promise((res, rej)=>{
this._tw.get(endpoint, {}, (err, json)=>{
return err ? rej(err) : res(json);
});
});
}
_cleanString(str, entities, inReplyTo) {
if (entities.urls) {
......
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