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

Pretty display of RTs/boosts/quotes

parent 04d3f88c
......@@ -168,17 +168,24 @@ class MastodonAccount extends Account {
}
// 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) {
// see the same data from different platforms)
_normalize(channel, msg) {
// console.log('normalizing: ', msg);
this.emit({
/// FIXME!!!
if (msg.spoiler_text) {
this._vorpal.log('Spoiler: ', msg.spoiler_text);
}
return({
sender: msg.account.acct,
str: this._cleanString(msg.content),
str: msg.reblog ? '' : 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);
timestamp: Date.parse(msg.created_at),
echoed: msg.reblog && this._normalize(channel, msg.reblog)
});
// if (msg.mentions) {
// vorpal.log('Mentions: ', msg.mentions);
......@@ -190,18 +197,20 @@ class MastodonAccount extends Account {
// vorpal.log('Tags: ', msg.tags);
// }
/// 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);
// }
}
_normalizeAndEmitUpdate(channel, msg) {
let normalized = this._normalize(channel, msg);
if (msg.reblog) {
this._vorpal.log('FIXME: This is a boost of another status');
this._normalizeAndEmitUpdate(channel, msg.reblog);
if (normalized) {
this.emit(normalized, msg);
}
}
_normalizeAndEmitNotification(channel, msg) {
if (msg.type === 'follow') {
......
......@@ -220,18 +220,30 @@ class TwitterAccount extends Account {
}
}
// Get a Twitter update, normalizes some stuff (to make different platforms
// see the same data from different platforms), and emits the update.
_normalizeAndEmitUpdate(msg) {
// Get a Twitter update, OR a part of an update (such a retweeted_status or a
// quoted_status), and normalize some stuff (to make different platforms
// see the same data from different platforms)
_normalize(msg) {
if (('id_str' in msg) && ('contributors' in msg) && ('text' in msg)) {
// This looks like a tweet
// console.log('tweet is truncated: ', msg.truncated);
// console.log(msg.entities.urls);
if (msg.extended_tweet) {
return this._normalize(msg.extended_tweet);
}
if (msg.retweeted_status) {
msg.text = msg.retweeted_status.text;
return ({
sender: msg.user.screen_name,
str: '',
channel: 'home',
media: [],
timestamp: Date.parse(msg.created_at),
echoed: this._normalize(msg.retweeted_status)
});
// msg.text = msg.retweeted_status.text;
}
let allEntities = Object.assign(
......@@ -246,19 +258,31 @@ class TwitterAccount extends Account {
let str = this._cleanString(msg.text, allEntities);
this.emit({
return({
sender: msg.user.screen_name,
str: str,
// str: msg.text,
channel: 'home',
// realtime: true,
// realtime: true,
// media: msg.media_attachments.map(i=>i.text_url || i.remote_url),
media: allMedia,
timestamp: Date.parse(msg.created_at)
}, msg);
timestamp: Date.parse(msg.created_at),
quoted: msg.quoted_status && this._normalize(msg.quoted_status)
});
} else {
this._vorpal.log(chalk.red(''));
}
}
// Get a Twitter update, normalizes some stuff (to make different platforms
// see the same data from different platforms), and emits the update.
_normalizeAndEmitUpdate(msg) {
let normalized = this._normalize(msg);
if (normalized) {
this.emit(normalized, msg);
}
// /// FIXME!!!
// if (msg.spoiler_text) {
......
......@@ -9,7 +9,8 @@ export default function stringify(conf, item) {
let { str, channel, realtime, timestamp, account } = item;
let sender = item.sender;
let quotedStr = '';
let echoedStr = '';
const updateColour = conf.get('global.colours.updates');
const mediaColour = conf.get('global.colours.media');
......@@ -22,10 +23,25 @@ export default function stringify(conf, item) {
// }
}
// This is an echo (RT/boost/share) of some other status
if (item.echoed) {
echoedStr = 'R' + stringify(conf, item.echoed);
formattedMedia = '';
}
// This is a quote (RT with comments) of some other status
if (item.quoted) {
quotedStr = '\n ' + stringify(conf, item.quoted);
}
let formatted =
(sender ? (' <' + chalk.bold(sender) + '>') : '') +
' ' + chalk.foreground(updateColour)(str) +
formattedMedia;
echoedStr +
formattedMedia +
quotedStr;
/// TODO: handle quotes (by recursive call)
/// TODO: handle echoes/boosts/RT (by recursive call)
......
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