var client = require('ssb-client'); var pull = require('pull-stream'); var moment = require('moment'); var app = require('koa')(); var router = require('koa-router')(); var views = require('co-views'); var port = 1337; var me = '@8Qee0I/DwI5DHSCi3p5fsl6FyLGArrnDz3ox9qZr5Qc=.ed25519' var message = 'I said nothing'; client(function (err, sbot) { if (err) { throw err; } pull(sbot.createUserStream({ id: me, limit: 1, reverse: true }), pull.drain(function printMessage(msg) { date = moment(msg.value.timestamp).fromNow() if (msg.value.content.type === 'post') { message = (msg.value.content.text) } else if (msg.value.content.type === 'vote') { message = ('I dug ' + msg.value.content.vote.link) } else if (msg.value.content.type === 'about') { message = ('I identified ' + msg.value.content.about + ' as ' + msg.value.content.name) } else if (msg.value.content.type === 'git-update') { message = ('I pushed a commit ') } else { message = ('I sent a private message ') } })); app.use(router.routes()) app.use(router.allowedMethods()) var render = views(__dirname, { ext: 'jade'}); router.get('/', function *(next) { this.body = yield render('index', {title: 'sdash', message, date}); }); app.listen(port); });