git ssb

16+

cel / patchfoo



Commit 6646ec3620bff75ffca314d5c0eb5019ea7c52e1

Render talenet messages

cel committed on 12/24/2017, 10:19:27 PM
Parent: 079499f482a67c8007cea211c9000eb90aa4e67a

Files changed

lib/app.jschanged
lib/render-msg.jschanged
lib/app.jsView
@@ -52,8 +52,9 @@
5252 this.reverseEmojiNameCache = lru(500)
5353 this.getBlobSize = memo({cache: this.blobSizeCache = lru(100)},
5454 sbot.blobs.size.bind(sbot.blobs))
5555 this.getVotes = memo({cache: lru(100)}, this._getVotes.bind(this))
56 + this.getIdeaTitle = memo({cache: lru(100)}, this.getIdeaTitle)
5657
5758 this.unboxMsg = this.unboxMsg.bind(this)
5859
5960 this.render = new Render(this, this.opts)
@@ -775,4 +776,32 @@
775776 }),
776777 pull.unique()
777778 )
778779 }
780 +
781 +App.prototype.getIdeaTitle = function (id, cb) {
782 + pull(
783 + this.sbot.backlinks.read({
784 + reverse: true,
785 + query: [
786 + {$filter: {
787 + dest: id,
788 + value: {
789 + content: {
790 + type: 'talenet-idea-update',
791 + ideaKey: id,
792 + title: {$truthy: true}
793 + }
794 + }
795 + }},
796 + {$map: ['value', 'content', 'title']}
797 + ]
798 + }),
799 + pull.take(1),
800 + pull.collect(function (err, titles) {
801 + if (err) return cb(err)
802 + var title = titles && titles[0]
803 + || (String(id).substr(0, 8) + '…')
804 + cb(null, title)
805 + })
806 + )
807 +}
lib/render-msg.jsView
@@ -276,8 +276,16 @@
276276 case 'macaco_maluco-sombrio-tombstone': return this.sombrioTombstone(cb)
277277 case 'macaco_maluco-sombrio-score': return this.sombrioScore(cb)
278278 case 'blog': return this.blog(cb)
279279 case 'image-map': return this.imageMap(cb)
280 + case 'talenet-identity-skill_assignment': return this.identitySkillAssign(cb)
281 + case 'talenet-idea-skill_assignment': return this.ideaSkillAssign(cb)
282 + case 'talenet-idea-create': return this.ideaCreate(cb)
283 + case 'talenet-idea-association': return this.ideaAssocate(cb)
284 + case 'talenet-skill-create': return this.skillCreate(cb)
285 + case 'talenet-idea-hat': return this.ideaHat(cb)
286 + case 'talenet-idea-update': return this.ideaUpdate(cb)
287 + case 'talenet-idea-comment': return this.ideaComment(cb)
280288 default: return this.object(cb)
281289 }
282290 }
283291
@@ -399,8 +407,12 @@
399407 else if (self.c.type === 'chess_invite')
400408 self.chessInviteTitle(cb)
401409 else if (self.c.type === 'bookclub')
402410 self.bookclubTitle(cb)
411 + else if (self.c.type === 'talenet-skill-create')
412 + cb(null, title(self.c.name))
413 + else if (self.c.type === 'talenet-idea-create')
414 + self.app.getIdeaTitle(self.msg.key, cb)
403415 else
404416 self.app.getAbout(self.msg.key, function (err, about) {
405417 if (err) return cb(err)
406418 var name = about.name || about.title
@@ -1478,4 +1490,125 @@
14781490 usemap: '#' + mapName,
14791491 }) : ''
14801492 ]), cb)
14811493 }
1494 +
1495 +RenderMsg.prototype.skillCreate = function (cb) {
1496 + var self = this
1497 + self.wrapMini(h('span',
1498 + ' created skill ',
1499 + h('ins', self.c.name)
1500 + ), cb)
1501 +}
1502 +
1503 +RenderMsg.prototype.ideaCreate = function (cb) {
1504 + var self = this
1505 + self.wrapMini(h('span',
1506 + ' has an idea'
1507 + ), cb)
1508 +}
1509 +
1510 +RenderMsg.prototype.identitySkillAssign = function (cb) {
1511 + var self = this
1512 + self.link(self.c.skillKey, function (err, a) {
1513 + self.wrapMini(h('span',
1514 + self.c.action === 'assign' ? 'has '
1515 + : h('code', self.c.action), ' ',
1516 + 'skill ', a
1517 + ), cb)
1518 + })
1519 +}
1520 +
1521 +RenderMsg.prototype.ideaSkillAssign = function (cb) {
1522 + var self = this
1523 + var done = multicb({pluck: 1, spread: true})
1524 + self.link(self.c.skillKey, done())
1525 + self.link(self.c.ideaKey, done())
1526 + done(function (err, skillA, ideaA) {
1527 + self.wrapMini(h('span',
1528 + self.c.action === 'assign' ? 'needs '
1529 + : h('code', self.c.action), ' ',
1530 + 'skill ', skillA,
1531 + ' for idea ',
1532 + ideaA
1533 + ), cb)
1534 + })
1535 +}
1536 +
1537 +RenderMsg.prototype.ideaAssocate = function (cb) {
1538 + var self = this
1539 + self.link(self.c.ideaKey, function (err, a) {
1540 + self.wrapMini(h('span',
1541 + self.c.action === 'associate' ? 'likes '
1542 + : h('code', self.c.action), ' ',
1543 + 'idea ', a
1544 + ), cb)
1545 + })
1546 +}
1547 +
1548 +RenderMsg.prototype.ideaHat = function (cb) {
1549 + var self = this
1550 + self.link(self.c.ideaKey, function (err, a) {
1551 + self.wrapMini(h('span',
1552 + self.c.action === 'take' ? 'takes '
1553 + : h('code', self.c.action), ' ',
1554 + 'idea ', a
1555 + ), cb)
1556 + })
1557 +}
1558 +
1559 +RenderMsg.prototype.ideaUpdate = function (cb) {
1560 + var self = this
1561 + var done = multicb({pluck: 1, spread: true})
1562 + var props = {}
1563 + for (var k in self.c) {
1564 + if (k !== 'ideaKey' && k !== 'type' && k !== 'talenet-version') {
1565 + props[k] = self.c[k]
1566 + }
1567 + }
1568 + var keys = Object.keys(props).sort().join()
1569 +
1570 + if (keys === 'title') {
1571 + return self.wrapMini(h('span',
1572 + 'titles idea ',
1573 + h('a', {href: self.toUrl(self.c.ideaKey)}, props.title)
1574 + ), cb)
1575 + }
1576 +
1577 + if (keys === 'description') {
1578 + return self.link(self.c.ideaKey, function (err, a) {
1579 + self.wrap(h('div',
1580 + 'describes idea ', a, ':',
1581 + h('blockquote', {innerHTML: self.render.markdown(props.description)})
1582 + ), cb)
1583 + })
1584 + }
1585 +
1586 + if (keys === 'description,title') {
1587 + return self.wrap(h('div',
1588 + 'describes idea ',
1589 + h('a', {href: self.toUrl(self.c.ideaKey)}, props.title),
1590 + ':',
1591 + h('blockquote', {innerHTML: self.render.markdown(props.description)})
1592 + ), cb)
1593 + }
1594 +
1595 + self.link(self.c.ideaKey, done())
1596 + var table = self.valueTable(props, 1, done())
1597 + done(function (err, ideaA) {
1598 + self.wrap(h('div', [
1599 + 'updates idea ', ideaA,
1600 + table
1601 + ]), cb)
1602 + })
1603 +}
1604 +
1605 +RenderMsg.prototype.ideaComment = function (cb) {
1606 + var self = this
1607 + self.link(self.c.ideaKey, function (err, ideaA) {
1608 + self.wrap(h('div', [
1609 + h('div', h('small', h('span.symbol', '→'), ' idea ', ideaA)),
1610 + self.c.text ?
1611 + h('div', {innerHTML: self.render.markdown(self.c.text)}) : ''
1612 + ]), cb)
1613 + })
1614 +}

Built with git-ssb-web