Commit 0f3a2da46013c06b66c331606f6732f60f4386cb
Factor out adding author name to messages
Charles Lehner committed on 3/26/2016, 6:42:19 PMParent: 38f058f88ea3d8eb9e4f8ea5f16fb622289b3d88
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -151,8 +151,17 @@ | ||
151 | 151 | } |
152 | 152 | }, cb) |
153 | 153 | } |
154 | 154 | |
155 | +function addAuthorName(about) { | |
156 | + return paramap(function (msg, cb) { | |
157 | + about.getName(msg.value.author, function (err, authorName) { | |
158 | + msg.authorName = authorName | |
159 | + cb(err, msg) | |
160 | + }) | |
161 | + }, 8) | |
162 | +} | |
163 | + | |
155 | 164 | var hasOwnProp = Object.prototype.hasOwnProperty |
156 | 165 | |
157 | 166 | function getContentType(filename) { |
158 | 167 | var ext = filename.split('.').pop() |
@@ -397,24 +406,22 @@ | ||
397 | 406 | return msg.value.content.type in msgTypes && |
398 | 407 | msg.value.timestamp < Date.now() |
399 | 408 | }), |
400 | 409 | pull.take(20), |
410 | + addAuthorName(about), | |
401 | 411 | pull.asyncMap(function (msg, cb) { |
402 | - about.getName(msg.value.author, function (err, name) { | |
403 | - if (err) return cb(err) | |
404 | - switch (msg.value.content.type) { | |
405 | - case 'git-repo': return renderRepoCreated(msg, name, cb) | |
406 | - case 'git-update': return renderUpdate(msg, name, cb) | |
407 | - } | |
408 | - }) | |
412 | + switch (msg.value.content.type) { | |
413 | + case 'git-repo': return renderRepoCreated(msg, cb) | |
414 | + case 'git-update': return renderUpdate(msg, cb) | |
415 | + } | |
409 | 416 | }) |
410 | 417 | ) |
411 | 418 | } |
412 | 419 | |
413 | - function renderRepoCreated(msg, authorName, cb) { | |
420 | + function renderRepoCreated(msg, cb) { | |
414 | 421 | var msgLink = link([msg.key], |
415 | 422 | new Date(msg.value.timestamp).toLocaleString()) |
416 | - var authorLink = link([msg.value.author], authorName) | |
423 | + var authorLink = link([msg.value.author], msg.authorName) | |
417 | 424 | var author = msg.value.author |
418 | 425 | getRepoName(about, author, msg.key, function (err, repoName) { |
419 | 426 | if (err) return cb(err) |
420 | 427 | var repoLink = link([msg.key], repoName) |
@@ -422,12 +429,12 @@ | ||
422 | 429 | authorLink + ' created repo ' + repoLink + '</section>') |
423 | 430 | }) |
424 | 431 | } |
425 | 432 | |
426 | - function renderUpdate(msg, authorName, cb) { | |
433 | + function renderUpdate(msg, cb) { | |
427 | 434 | var msgLink = link([msg.key], |
428 | 435 | new Date(msg.value.timestamp).toLocaleString()) |
429 | - var authorLink = link([msg.value.author], authorName) | |
436 | + var authorLink = link([msg.value.author], msg.authorName) | |
430 | 437 | var repoId = msg.value.content.repo |
431 | 438 | var author = msg.value.author |
432 | 439 | getRepoName(about, author, repoId, function (err, repoName) { |
433 | 440 | if (err) return cb(err) |
Built with git-ssb-web