aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-12-24 11:47:06 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-12-24 12:19:27 -1000
commit6646ec3620bff75ffca314d5c0eb5019ea7c52e1 (patch)
treef3b7bdcf3670ae916979a3a4cd0f067efae963bb /lib
parent079499f482a67c8007cea211c9000eb90aa4e67a (diff)
downloadpatchfoo-6646ec3620bff75ffca314d5c0eb5019ea7c52e1.tar.gz
patchfoo-6646ec3620bff75ffca314d5c0eb5019ea7c52e1.zip
Render talenet messages
Diffstat (limited to 'lib')
-rw-r--r--lib/app.js29
-rw-r--r--lib/render-msg.js133
2 files changed, 162 insertions, 0 deletions
diff --git a/lib/app.js b/lib/app.js
index 4068530..1c3647b 100644
--- a/lib/app.js
+++ b/lib/app.js
@@ -53,6 +53,7 @@ function App(sbot, config) {
this.getBlobSize = memo({cache: this.blobSizeCache = lru(100)},
sbot.blobs.size.bind(sbot.blobs))
this.getVotes = memo({cache: lru(100)}, this._getVotes.bind(this))
+ this.getIdeaTitle = memo({cache: lru(100)}, this.getIdeaTitle)
this.unboxMsg = this.unboxMsg.bind(this)
@@ -776,3 +777,31 @@ App.prototype.getAddresses = function (id) {
pull.unique()
)
}
+
+App.prototype.getIdeaTitle = function (id, cb) {
+ pull(
+ this.sbot.backlinks.read({
+ reverse: true,
+ query: [
+ {$filter: {
+ dest: id,
+ value: {
+ content: {
+ type: 'talenet-idea-update',
+ ideaKey: id,
+ title: {$truthy: true}
+ }
+ }
+ }},
+ {$map: ['value', 'content', 'title']}
+ ]
+ }),
+ pull.take(1),
+ pull.collect(function (err, titles) {
+ if (err) return cb(err)
+ var title = titles && titles[0]
+ || (String(id).substr(0, 8) + '…')
+ cb(null, title)
+ })
+ )
+}
diff --git a/lib/render-msg.js b/lib/render-msg.js
index a7b7339..f84b0ae 100644
--- a/lib/render-msg.js
+++ b/lib/render-msg.js
@@ -277,6 +277,14 @@ RenderMsg.prototype.message = function (cb) {
case 'macaco_maluco-sombrio-score': return this.sombrioScore(cb)
case 'blog': return this.blog(cb)
case 'image-map': return this.imageMap(cb)
+ case 'talenet-identity-skill_assignment': return this.identitySkillAssign(cb)
+ case 'talenet-idea-skill_assignment': return this.ideaSkillAssign(cb)
+ case 'talenet-idea-create': return this.ideaCreate(cb)
+ case 'talenet-idea-association': return this.ideaAssocate(cb)
+ case 'talenet-skill-create': return this.skillCreate(cb)
+ case 'talenet-idea-hat': return this.ideaHat(cb)
+ case 'talenet-idea-update': return this.ideaUpdate(cb)
+ case 'talenet-idea-comment': return this.ideaComment(cb)
default: return this.object(cb)
}
}
@@ -400,6 +408,10 @@ RenderMsg.prototype.title1 = function (cb) {
self.chessInviteTitle(cb)
else if (self.c.type === 'bookclub')
self.bookclubTitle(cb)
+ else if (self.c.type === 'talenet-skill-create')
+ cb(null, title(self.c.name))
+ else if (self.c.type === 'talenet-idea-create')
+ self.app.getIdeaTitle(self.msg.key, cb)
else
self.app.getAbout(self.msg.key, function (err, about) {
if (err) return cb(err)
@@ -1479,3 +1491,124 @@ RenderMsg.prototype.imageMap = function (cb) {
}) : ''
]), cb)
}
+
+RenderMsg.prototype.skillCreate = function (cb) {
+ var self = this
+ self.wrapMini(h('span',
+ ' created skill ',
+ h('ins', self.c.name)
+ ), cb)
+}
+
+RenderMsg.prototype.ideaCreate = function (cb) {
+ var self = this
+ self.wrapMini(h('span',
+ ' has an idea'
+ ), cb)
+}
+
+RenderMsg.prototype.identitySkillAssign = function (cb) {
+ var self = this
+ self.link(self.c.skillKey, function (err, a) {
+ self.wrapMini(h('span',
+ self.c.action === 'assign' ? 'has '
+ : h('code', self.c.action), ' ',
+ 'skill ', a
+ ), cb)
+ })
+}
+
+RenderMsg.prototype.ideaSkillAssign = function (cb) {
+ var self = this
+ var done = multicb({pluck: 1, spread: true})
+ self.link(self.c.skillKey, done())
+ self.link(self.c.ideaKey, done())
+ done(function (err, skillA, ideaA) {
+ self.wrapMini(h('span',
+ self.c.action === 'assign' ? 'needs '
+ : h('code', self.c.action), ' ',
+ 'skill ', skillA,
+ ' for idea ',
+ ideaA
+ ), cb)
+ })
+}
+
+RenderMsg.prototype.ideaAssocate = function (cb) {
+ var self = this
+ self.link(self.c.ideaKey, function (err, a) {
+ self.wrapMini(h('span',
+ self.c.action === 'associate' ? 'likes '
+ : h('code', self.c.action), ' ',
+ 'idea ', a
+ ), cb)
+ })
+}
+
+RenderMsg.prototype.ideaHat = function (cb) {
+ var self = this
+ self.link(self.c.ideaKey, function (err, a) {
+ self.wrapMini(h('span',
+ self.c.action === 'take' ? 'takes '
+ : h('code', self.c.action), ' ',
+ 'idea ', a
+ ), cb)
+ })
+}
+
+RenderMsg.prototype.ideaUpdate = function (cb) {
+ var self = this
+ var done = multicb({pluck: 1, spread: true})
+ var props = {}
+ for (var k in self.c) {
+ if (k !== 'ideaKey' && k !== 'type' && k !== 'talenet-version') {
+ props[k] = self.c[k]
+ }
+ }
+ var keys = Object.keys(props).sort().join()
+
+ if (keys === 'title') {
+ return self.wrapMini(h('span',
+ 'titles idea ',
+ h('a', {href: self.toUrl(self.c.ideaKey)}, props.title)
+ ), cb)
+ }
+
+ if (keys === 'description') {
+ return self.link(self.c.ideaKey, function (err, a) {
+ self.wrap(h('div',
+ 'describes idea ', a, ':',
+ h('blockquote', {innerHTML: self.render.markdown(props.description)})
+ ), cb)
+ })
+ }
+
+ if (keys === 'description,title') {
+ return self.wrap(h('div',
+ 'describes idea ',
+ h('a', {href: self.toUrl(self.c.ideaKey)}, props.title),
+ ':',
+ h('blockquote', {innerHTML: self.render.markdown(props.description)})
+ ), cb)
+ }
+
+ self.link(self.c.ideaKey, done())
+ var table = self.valueTable(props, 1, done())
+ done(function (err, ideaA) {
+ self.wrap(h('div', [
+ 'updates idea ', ideaA,
+ table
+ ]), cb)
+ })
+}
+
+RenderMsg.prototype.ideaComment = function (cb) {
+ var self = this
+ self.link(self.c.ideaKey, function (err, ideaA) {
+ self.wrap(h('div', [
+ h('div', h('small', h('span.symbol', '→'), ' idea ', ideaA)),
+ self.c.text ?
+ h('div', {innerHTML: self.render.markdown(self.c.text)}) : ''
+ ]), cb)
+ })
+}