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

Minor cosmetic upgrade to the media displaying

parent c45446ee
......@@ -27,6 +27,8 @@ class MastodonAccount extends Account {
api_url: opts.api_url
});
this._vorpal = vorpal;
this._masto.get('accounts/verify_credentials')
/*.then(response=>response.json()).*/
.then(json=> {
......@@ -43,36 +45,15 @@ class MastodonAccount extends Account {
// Hackishly listen to the public timeline
let userListener = this._masto.stream('streaming/user');
userListener.on('message', msg => {
if (msg.event === 'update') {
this.emit({
sender: msg.data.account.acct,
str: this._cleanString(msg.data.content),
channel: 'user',
realtime: true,
}, msg);
} else {
vorpal.log(chalk.green(msg));
}
userListener.on('message', this._getOnStreamMessage('user'));
userListener.on('error', err => {
vorpal.log(chalk.red.bold(err));
});
let publicListener = this._masto.stream('streaming/public');
publicListener.on('message', msg => {
if (msg.event === 'update') {
this.emit({
sender: msg.data.account.acct,
str: this._cleanString(msg.data.content),
channel: 'public',
realtime: true,
}, msg);
vorpal.log('Mentions: ', msg.data.mentions);
vorpal.log('Media: ', msg.data.media_attachments);
vorpal.log('Tags: ', msg.data.tags);
vorpal.log('Spoiler: ', msg.data.spoiler_text);
} else {
vorpal.log(chalk.green(msg));
}
publicListener.on('message', this._getOnStreamMessage('public'));
publicListener.on('error', err => {
vorpal.log(chalk.red.bold(err));
});
/* A update msg looks like:
......@@ -114,26 +95,15 @@ class MastodonAccount extends Account {
}
*/
publicListener.on('error', err => {
vorpal.log(chalk.red.bold(err));
});
});
return super.constructor(callback, opts);
}
listen(channel) {
/*
let delay = Number(channel) * 1000;
......@@ -181,7 +151,37 @@ class MastodonAccount extends Account {
return striptags( he.decode( str.replace('</p><p>', ' // ') ) );
}
// Given a stream descriptor, return a function that handles messages from the stream
_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);
// }
// if (msg.data.media_attachments.length) {
// this._vorpal.log('Media: ', msg.data.media_attachments);
// }
// if (msg.data.tags) {
// vorpal.log('Tags: ', msg.data.tags);
// }
if (msg.data.spoiler_text) {
this._vorpal.log('Spoiler: ', msg.data.spoiler_text);
}
} else {
this._vorpal.log(chalk.green(msg));
}
}
}
}
......
......@@ -61,6 +61,10 @@ function handle(account, data, metadata) {
(sender ? (' <' + chalk.bold(sender) + '>') : '') +
': ' + chalk.foreground(updateColour)(str)
);
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