Permalink
Browse files

discovery: display no more than 2 posts by a single author in a row

  • Loading branch information...
mmckegg committed Nov 6, 2016
1 parent 25984b9 commit 4e9086947b05a0970d0a798d33bd957b6b5d0167
Showing with 20 additions and 3 deletions.
  1. +20 −3 api/index.js
View
@@ -30,7 +30,7 @@ module.exports = function (ssbClient, config) {
id: ssbClient.id,
getDiscoveryFeed (cb) {
checkProfilesLoaded()
return lookupItems(sortedPostIds(concat([profiles.pubFriendPostIds, profiles.localPeerIds])))
return lookupItems(sortedPostIds(profiles.pubFriendPostIds, {maxSameProfile: 2}))
},
getFollowingFeed (cb) {
@@ -179,9 +179,26 @@ module.exports = function (ssbClient, config) {
// scoped
function sortedPostIds (ids) {
function sortedPostIds (ids, opts) {
return computed([ids], function (ids) {
return ids.map(id => profiles.getPost(id)).sort((a, b) => b.timestamp() - a.timestamp()).map(x => x.id)
var sorted = ids.map(id => profiles.getPost(id)).sort((a, b) => b.timestamp() - a.timestamp())
var sameCount = 0
var lastAuthorId = null
var filtered = opts && opts.maxSameProfile ? sorted.filter((post) => {
if (post.author.id === lastAuthorId) {
sameCount += 1
} else {
sameCount = 0
lastAuthorId = post.author.id
}
if (sameCount < opts.maxSameProfile) {
return true
}
}) : sorted
return filtered.map(x => x.id)
}, { nextTick: true })
}

0 comments on commit 4e90869

Please sign in to comment.