aboutsummaryrefslogtreecommitdiff
path: root/lib/render.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/render.js')
-rw-r--r--lib/render.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/render.js b/lib/render.js
index 880470a..c1c7edf 100644
--- a/lib/render.js
+++ b/lib/render.js
@@ -313,3 +313,36 @@ Render.prototype.gitCommitBody = function (body) {
? h('div', {innerHTML: this.markdown('\n' + body)})
: h('pre', this.linkify('\n' + body))
}
+
+Render.prototype.getName = function (id, cb) {
+ // TODO: consolidate the get name/link functions
+ var self = this
+ switch (id && id[0]) {
+ case '%':
+ return self.app.getMsgDecrypted(id, function (err, msg) {
+ if (err && err.name == 'NotFoundError')
+ return cb(null, String(id).substring(0, 8) + '…(missing)')
+ if (err) return fallback()
+ new RenderMsg(self, self.app, msg, {wrap: false}).title(cb)
+ })
+ case '@': // fallthrough
+ case '&':
+ return self.app.getAbout(id, function (err, about) {
+ if (err || !about || !about.name) return fallback()
+ cb(null, about.name)
+ })
+ default:
+ return cb(null, String(id))
+ }
+ function fallback() {
+ cb(null, String(id).substr(0, 8) + '…')
+ }
+}
+
+Render.prototype.getNameLink = function (id, cb) {
+ var self = this
+ self.getName(id, function (err, name) {
+ if (err) return cb(err)
+ cb(null, h('a', {href: self.toUrl(id)}, name))
+ })
+}