actual feed getter
This commit is contained in:
parent
782c2b9160
commit
45df3ddb1e
1 changed files with 27 additions and 12 deletions
|
|
@ -9,6 +9,20 @@ const R = require('ramda')
|
||||||
const Follows = require('./follows')
|
const Follows = require('./follows')
|
||||||
const Wall = require('./wall')
|
const Wall = require('./wall')
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {number} numberOfPublicKeyGroups
|
||||||
|
* @param {number} pageRequested
|
||||||
|
*/
|
||||||
|
const calculateFeedPage = (numberOfPublicKeyGroups, pageRequested) => {
|
||||||
|
// thanks to sebassdc
|
||||||
|
|
||||||
|
return [
|
||||||
|
((pageRequested - 1) % numberOfPublicKeyGroups) + 1,
|
||||||
|
Math.ceil(pageRequested / numberOfPublicKeyGroups)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} page
|
* @param {number} page
|
||||||
* @throws {TypeError}
|
* @throws {TypeError}
|
||||||
|
|
@ -38,25 +52,26 @@ const getFeedPage = async page => {
|
||||||
// page 3: page 2 from first 10 public keys
|
// page 3: page 2 from first 10 public keys
|
||||||
// page 4: page 2 from first 10 public keys
|
// page 4: page 2 from first 10 public keys
|
||||||
// etc
|
// etc
|
||||||
|
// thanks to sebassdc (github)
|
||||||
|
|
||||||
const pagedPublicKeys = R.splitEvery(10, shuffle(subbedPublicKeys))
|
const pagedPublicKeys = R.splitEvery(10, shuffle(subbedPublicKeys))
|
||||||
|
|
||||||
if (pagedPublicKeys.length === 1) {
|
const [publicKeyGroupIdx, pageToRequest] = calculateFeedPage(
|
||||||
const [publicKeys] = pagedPublicKeys
|
pagedPublicKeys.length,
|
||||||
|
page
|
||||||
|
)
|
||||||
|
|
||||||
const fetchedPages = await Promise.all(
|
const publicKeys = pagedPublicKeys[publicKeyGroupIdx]
|
||||||
publicKeys.map(pk => Wall.getWallPage(page, pk))
|
|
||||||
)
|
|
||||||
|
|
||||||
const allPosts = fetchedPages.map(fp => Object.values(fp.posts))
|
const fetchedPages = await Promise.all(
|
||||||
const posts = R.flatten(allPosts)
|
publicKeys.map(pk => Wall.getWallPage(pageToRequest, pk))
|
||||||
// @ts-ignore
|
)
|
||||||
const sorted = R.sortBy((a, b) => b.date - a.date, posts)
|
|
||||||
|
|
||||||
return sorted
|
const fetchedPostsGroups = fetchedPages.map(wp => Object.values(wp.posts))
|
||||||
}
|
const fetchedPosts = R.flatten(fetchedPostsGroups)
|
||||||
|
const sortered = R.sort((a, b) => b.date - a.date, fetchedPosts)
|
||||||
|
|
||||||
return []
|
return sortered
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue