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

WIP display of media links, retrieval of last bits of timeline

parent ffd6bf47
......@@ -50,12 +50,31 @@ class MastodonAccount extends Account {
vorpal.log(chalk.red.bold(err));
});
let publicListener = this._masto.stream('streaming/public');
publicListener.on('message', this._getOnStreamMessage('public'));
publicListener.on('error', err => {
vorpal.log(chalk.red.bold(err));
this._masto.get('timelines/home', (err, msgs, response) =>{
for (let i=msgs.length-1; i>=0; i--) {
this._normalizeAndEmitUpdate('home', msgs[i]);
// vorpal.log('timelines/home', msgs);
}
});
this._masto.get('notifications', (err, msgs, response) =>{
// vorpal.log('notifications', err, msgs/*, response*/);
// vorpal.log(response.toJSON());
for (let i=msgs.length-1; i>=0; i--) {
this._normalizeAndEmitNotification('notifications', msgs[i]);
// vorpal.log('timelines/home', msgs);
}
});
// let publicListener = this._masto.stream('streaming/public');
// publicListener.on('message', this._getOnStreamMessage('public'));
// publicListener.on('error', err => {
// vorpal.log(chalk.red.bold(err));
// });
/* A update msg looks like:
{ event: 'update',
data:
......@@ -155,32 +174,77 @@ class MastodonAccount extends Account {
_getOnStreamMessage(stream) {
return (msg)=>{
if (msg.event === 'update') {
this.emit({
sender: msg.data.account.acct,
str: this._cleanString(msg.data.content),
channel: stream,
realtime: true,
media: msg.data.media_attachments.map(i=>i.text_url || i.remote_url)
}, msg);
// if (msg.data.mentions) {
// vorpal.log('Mentions: ', msg.data.mentions);
this._normalizeAndEmitUpdate(stream, msg.data);
} else {
this._vorpal.log(chalk.green(msg));
}
}
}
// Get a Mastodon update, normalizes some stuff (to make different platforms
// see the same data from different platforms), and emits the update.
_normalizeAndEmitUpdate(channel, msg) {
// console.log('normalizing: ', msg);
this.emit({
sender: msg.account.acct,
str: this._cleanString(msg.content),
channel: channel,
// realtime: true,
media: msg.media_attachments.map(i=>i.text_url || i.remote_url),
timestamp: Date.parse(msg.created_at)
}, msg);
// if (msg.mentions) {
// vorpal.log('Mentions: ', msg.mentions);
// }
// if (msg.data.media_attachments.length) {
// this._vorpal.log('Media: ', msg.data.media_attachments);
// if (msg.media_attachments.length) {
// this._vorpal.log('Media: ', msg.media_attachments);
// }
// if (msg.data.tags) {
// vorpal.log('Tags: ', msg.data.tags);
// if (msg.tags) {
// vorpal.log('Tags: ', msg.tags);
// }
if (msg.data.spoiler_text) {
this._vorpal.log('Spoiler: ', msg.data.spoiler_text);
}
} else {
this._vorpal.log(chalk.green(msg));
}
/// FIXME!!!
if (msg.spoiler_text) {
this._vorpal.log('Spoiler: ', msg.spoiler_text);
}
if (msg.reblog) {
this._vorpal.log('FIXME: This is a boost of another status');
this._normalizeAndEmitUpdate(channel, msg.reblog);
}
}
_normalizeAndEmitNotification(channel, msg) {
if (msg.type === 'follow') {
this.emit({
str: chalk.bold(msg.account.acct) + ' started following you.',
channel: channel,
timestamp: Date.parse(msg.created_at)
});
} else if (msg.type === 'reblog') {
this.emit({
str: chalk.bold(msg.account.acct) + ' echoed your update: ' + this._cleanString(msg.status.content),
channel: channel,
timestamp: Date.parse(msg.created_at)
});
} else if (msg.type === 'favourite') {
this.emit({
str: chalk.bold(msg.account.acct) + ' favourited your update: ' + this._cleanString(msg.status.content),
channel: channel,
timestamp: Date.parse(msg.created_at)
});
} else if (msg.type === 'mention') {
this.emit({
str: chalk.bold(msg.account.acct) + ' mentioned you ' + this._cleanString(msg.status.content),
channel: channel,
timestamp: Date.parse(msg.created_at)
});
} else {
this._vorpal.log('channel', msg);
}
}
}
......
......@@ -62,8 +62,10 @@ function handle(account, data, metadata) {
': ' + chalk.foreground(updateColour)(str)
);
for(let i=0, l=data.media.length; i<l; i++) {
vorpal.log(chalk.blue('Media:'), data.media[i]);
if (data.media) {
for(let i=0, l=data.media.length; i<l; i++) {
vorpal.log(chalk.blue('Media:'), data.media[i]);
}
}
}
......
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