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

Added a circular buffer for storing updates; display the buffer index next to each.

parent cfa2620a
let lastId = 0;
const maxId = 25 * 25 * 10;
const dictLetters = "abcdefghijkmnopqrstuvwxyz";
const dictNumbers = "0123456789";
let buffer = {};
function idToString(id) {
return (
dictLetters[ Math.floor(id / 250) % 25 ] +
dictLetters[ Math.floor(id / 10) % 25 ] +
dictNumbers[ id % 10 ]
);
}
// function stringToId(str) {
//
// }
export function get(str) {
return buffer[str];
}
export function push(data) {
let str = idToString(lastId++ % maxId);
buffer[str] = data;
return str;
}
......@@ -63,7 +63,7 @@ class MastodonAccount extends Account {
for (let i=msgs.length-1; i>=0; i--) {
this._normalizeAndEmitNotification('notifications', msgs[i]);
// vorpal.log('timelines/home', msgs);
// vorpal.log('timelines/notifications', msgs);
}
});
......@@ -77,42 +77,42 @@ class MastodonAccount extends Account {
/* A update msg looks like:
{ event: 'update',
data:
{ id: 2133504,
created_at: '2017-04-10T08:36:36.000Z',
in_reply_to_id: null,
in_reply_to_account_id: null,
sensitive: false,
spoiler_text: '',
visibility: 'public',
application: null,
account:
{ id: 52132,
username: 'Milady_Oscar',
acct: 'Milady_Oscar@oc.todon.fr',
display_name: 'Lady Oscar ',
locked: false,
created_at: '2017-04-05T15:18:04.424Z',
note: 'Un peu de vous et beaucoup de n\'importe moi, des trucs de filles, des blagues de mecs, et des fraises tagada.\nSur Twitter avec le même @ ',
url: 'https://oc.todon.fr/@Milady_Oscar',
avatar: 'https://files.mastodon.social/accounts/avatars/000/052/132/original/5d55de1a7e19b927.PNG?1491405483',
header: 'https://files.mastodon.social/accounts/headers/000/052/132/original/6e2afd6a5009629b.PNG?1491405483',
followers_count: 22,
following_count: 15,
statuses_count: 686
},
media_attachments: [],
mentions: [],
tags: [],
uri: 'tag:oc.todon.fr,2017-04-10:objectId=160722:objectType=Status',
content: '<p>Je sens bien le barbecue aujourd\'hui. Mais j\'ai pas acheté de charbon de bois. J\'ai envie de prendre Marine Le Pen à la place.</p>',
url: 'https://oc.todon.fr/users/Milady_Oscar/updates/11367',
reblogs_count: 0,
favourites_count: 0,
reblog: null
}
}
{ event: 'update',
data:
{ id: 2133504,
created_at: '2017-04-10T08:36:36.000Z',
in_reply_to_id: null,
in_reply_to_account_id: null,
sensitive: false,
spoiler_text: '',
visibility: 'public',
application: null,
account:
{ id: 52132,
username: 'Milady_Oscar',
acct: 'Milady_Oscar@oc.todon.fr',
display_name: 'Lady Oscar ',
locked: false,
created_at: '2017-04-05T15:18:04.424Z',
note: 'Un peu de vous et beaucoup de n\'importe moi, des trucs de filles, des blagues de mecs, et des fraises tagada.\nSur Twitter avec le même @ ',
url: 'https://oc.todon.fr/@Milady_Oscar',
avatar: 'https://files.mastodon.social/accounts/avatars/000/052/132/original/5d55de1a7e19b927.PNG?1491405483',
header: 'https://files.mastodon.social/accounts/headers/000/052/132/original/6e2afd6a5009629b.PNG?1491405483',
followers_count: 22,
following_count: 15,
statuses_count: 686
},
media_attachments: [],
mentions: [],
tags: [],
uri: 'tag:oc.todon.fr,2017-04-10:objectId=160722:objectType=Status',
content: '<p>Je sens bien le barbecue aujourd\'hui. Mais j\'ai pas acheté de charbon de bois. J\'ai envie de prendre Marine Le Pen à la place.</p>',
url: 'https://oc.todon.fr/users/Milady_Oscar/updates/11367',
reblogs_count: 0,
favourites_count: 0,
reblog: null
}
}
*/
......
......@@ -2,6 +2,7 @@
// import Clock from './platforms/clock';
import * as platforms from './platforms/index'
import * as circularBuffer from './circularBuffer'
import Vorpal from 'vorpal';
import inquirer from 'inquirer';
......@@ -36,6 +37,9 @@ function handle(account, data, metadata) {
let { str, channel, realtime, timestamp } = data;
data.account = account;
let id = circularBuffer.push(data);
if (timestamp === undefined) {
timestamp = Date.now();
}
......@@ -57,6 +61,7 @@ function handle(account, data, metadata) {
vorpal.log(
'[' + chalk.foreground(timestampColour)(timestampString) + '] ' +
id + '> ' +
chalk.foreground(badgeColour)(badge + '/' + channel) +
(sender ? (' <' + chalk.bold(sender) + '>') : '') +
': ' + chalk.foreground(updateColour)(str)
......
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