Files
Superalgos/Network/Queries/ProfileFollowing.js
T

62 lines
1.8 KiB
JavaScript

exports.newProfileFollowing = function newProfileFollowing() {
let thisObject = {
profile: undefined,
initialIndex: undefined,
amountRequested: undefined,
direction: undefined,
execute: execute,
initialize: initialize,
finalize: finalize
}
const DIRECTION_FUTURE = 'Future'
const DIRECTION_PAST = 'Past'
return thisObject
function finalize() {
thisObject.profile = undefined
}
function initialize(queryReceived) {
NT.utilities.queriesValidations.profilesValidations(queryReceived, thisObject)
NT.utilities.queriesValidations.arrayValidations(queryReceived, thisObject)
}
function execute() {
let response = []
let array = Array.from(thisObject.profile.following)
switch (thisObject.direction) {
case DIRECTION_FUTURE: {
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
let arrayItem = array[i]
if (arrayItem === undefined) { break }
addToResponse(arrayItem)
}
break
}
case DIRECTION_PAST: {
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
let arrayItem = array[i]
if (arrayItem === undefined) { break }
addToResponse(arrayItem)
}
break
}
}
return response
function addToResponse(arrayItem) {
let postResponse = {
emitterUserProfileId: arrayItem.emitterUserProfileId,
emitterBotProfileId: arrayItem.emitterBotProfileId
}
response.push(postResponse)
}
}
}