function asString(val) { return typeof val === 'string' && val } function linkDest(val) { return val ? asString(val) || asString(val.link) : null } function defalsify(val) { return val === 'false' ? false : val } module.exports = function (sbot, id, cb) { var aboutByFeed = {} let values = module.exports.allAbouts[id] for (var key in values) { for (var author in values[key]) { var feedAbout = aboutByFeed[author] || (aboutByFeed[author] = {}) var v = values[key][author][0] if (!v) break; if (key == 'name') feedAbout.name = v.replace(/^@?/, '@') if (key == 'image') feedAbout.image = linkDest(v) if (key == 'description') feedAbout.description = v if (key == 'publicWebHosting' && author === id) feedAbout.publicWebHosting = defalsify(v) } } // Use whatever properties have the most counts. // Usually we would want to handle renames for dead feeds and such, // but for ssb-viewer it is mostly public/archival content anyway, // so we'll let the popular name stand. // Except: prefer the feed's own choices slightly var propValueCounts = {/* prop: {value: count} */} var topValues = {/* prop: value */} var topValueCounts = {/* prop: count */} var about = {} // bias the feed's own choice by 1 aboutByFeed._author = aboutByFeed[id] || {} for (var feed in aboutByFeed) { var feedAbout = aboutByFeed[feed] for (var prop in feedAbout) { var value = feedAbout[prop] var valueCounts = propValueCounts[prop] || (propValueCounts[prop] = {}) var count = (valueCounts[value] || 0) + 1 valueCounts[value] = count if (count > (topValueCounts[prop] || 0)) { topValueCounts[prop] = count topValues[prop] = value } } } if (!topValues.name) topValues.name = String(id).substr(0, 10) + '…' cb(null, topValues) }