diff options
author | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-05-09 15:17:00 -1000 |
---|---|---|
committer | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-05-09 20:14:04 -1000 |
commit | 16a3027dc258d934ce38f4ab143c41246a5c1862 (patch) | |
tree | 5f45bdaef51ee6da9362b97283e21cb1c46a957c /lib/render.js | |
parent | 29f56c3e49c767f75164f57ccd1ac52b389794c0 (diff) | |
download | patchfoo-16a3027dc258d934ce38f4ab143c41246a5c1862.tar.gz patchfoo-16a3027dc258d934ce38f4ab143c41246a5c1862.zip |
Add another way to lookup names
Diffstat (limited to 'lib/render.js')
-rw-r--r-- | lib/render.js | 33 |
1 files changed, 33 insertions, 0 deletions
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)) + }) +} |