git ssb

30+

cel / git-ssb-web



Commit 0f3a2da46013c06b66c331606f6732f60f4386cb

Factor out adding author name to messages

Charles Lehner committed on 3/26/2016, 6:42:19 PM
Parent: 38f058f88ea3d8eb9e4f8ea5f16fb622289b3d88

Files changed

index.jschanged
index.jsView
@@ -151,8 +151,17 @@
151151 }
152152 }, cb)
153153 }
154154
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+
155164 var hasOwnProp = Object.prototype.hasOwnProperty
156165
157166 function getContentType(filename) {
158167 var ext = filename.split('.').pop()
@@ -397,24 +406,22 @@
397406 return msg.value.content.type in msgTypes &&
398407 msg.value.timestamp < Date.now()
399408 }),
400409 pull.take(20),
410+ addAuthorName(about),
401411 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+ }
409416 })
410417 )
411418 }
412419
413- function renderRepoCreated(msg, authorName, cb) {
420+ function renderRepoCreated(msg, cb) {
414421 var msgLink = link([msg.key],
415422 new Date(msg.value.timestamp).toLocaleString())
416- var authorLink = link([msg.value.author], authorName)
423+ var authorLink = link([msg.value.author], msg.authorName)
417424 var author = msg.value.author
418425 getRepoName(about, author, msg.key, function (err, repoName) {
419426 if (err) return cb(err)
420427 var repoLink = link([msg.key], repoName)
@@ -422,12 +429,12 @@
422429 authorLink + ' created repo ' + repoLink + '</section>')
423430 })
424431 }
425432
426- function renderUpdate(msg, authorName, cb) {
433+ function renderUpdate(msg, cb) {
427434 var msgLink = link([msg.key],
428435 new Date(msg.value.timestamp).toLocaleString())
429- var authorLink = link([msg.value.author], authorName)
436+ var authorLink = link([msg.value.author], msg.authorName)
430437 var repoId = msg.value.content.repo
431438 var author = msg.value.author
432439 getRepoName(about, author, repoId, function (err, repoName) {
433440 if (err) return cb(err)

Built with git-ssb-web