From 16a3027dc258d934ce38f4ab143c41246a5c1862 Mon Sep 17 00:00:00 2001 From: cel Date: Tue, 9 May 2017 15:17:00 -1000 Subject: Add another way to lookup names --- lib/render.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'lib/render.js') diff --git a/lib/render.js b/lib/render.js index aa2a6da..ea94329 100644 --- a/lib/render.js +++ b/lib/render.js @@ -257,3 +257,36 @@ Render.prototype.renderFeeds = function (opts) { self.renderMsg(msg, opts, cb) }, 4) } + +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)) + }) +} -- cgit v1.2.3