Merge pull request #1601 from Luis-Fernando-Molina/develop
Contribution: Superalgos Network: Almost all queries reviewed
This commit is contained in:
14 files changed
+279
-298
No files matched your search
@@ -15,13 +15,13 @@ exports.newBotProfileStats = function newBotProfileStats() {
|
||||
|
||||
function initialize(queryReceived) {
|
||||
/*
|
||||
Validate Bot Profile
|
||||
Validate User Profile
|
||||
*/
|
||||
let userProfile
|
||||
if (queryReceived.targetBotProfileId !== undefined) {
|
||||
if (queryReceived.targetUserProfileId !== undefined) {
|
||||
userProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId)
|
||||
} else {
|
||||
userProfile = NT.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileId)
|
||||
userProfile = NT.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle)
|
||||
}
|
||||
|
||||
if (userProfile === undefined) {
|
||||
@@ -39,13 +39,14 @@ exports.newBotProfileStats = function newBotProfileStats() {
|
||||
function execute() {
|
||||
|
||||
return {
|
||||
"userProfileId": thisObject.profile.userProfileId,
|
||||
"botProfileId": thisObject.profile.botProfileId,
|
||||
"botProfileHandle": thisObject.profile.botProfileHandle,
|
||||
"followingCount": thisObject.profile.followingCount,
|
||||
"followersCount": thisObject.profile.followersCount,
|
||||
"followingCount": thisObject.profile.following.size,
|
||||
"followersCount": thisObject.profile.followers.size,
|
||||
"postsCount": thisObject.profile.posts.size,
|
||||
"emitterEventsCount": thisObject.profile.emitterEventsCount,
|
||||
"targetEventsCount": thisObject.profile.targetEventsCount,
|
||||
"postsCount": thisObject.profile.postsCount
|
||||
"targetEventsCount": thisObject.profile.targetEventsCount
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,13 +10,6 @@ exports.newEvents = function newEvents() {
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
const INITIAL_EVENT_INDEX_FIRST = 'First'
|
||||
const INITIAL_EVENT_INDEX_LAST = 'Last'
|
||||
const MIN_AMOUNT_REQUESTED = 1
|
||||
const MAX_AMOUNT_REQUESTED = 100
|
||||
const DIRECTION_FUTURE = 'Future'
|
||||
const DIRECTION_PAST = 'Past'
|
||||
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
@@ -43,11 +36,11 @@ exports.newEvents = function newEvents() {
|
||||
throw ('Initial Index Undefined.')
|
||||
}
|
||||
|
||||
if (queryReceived.initialIndex === INITIAL_EVENT_INDEX_LAST) {
|
||||
if (queryReceived.initialIndex === NT.globals.constants.queries.INITIAL_INDEX_LAST) {
|
||||
queryReceived.initialIndex = thisObject.profile.posts.length - 1
|
||||
}
|
||||
|
||||
if (queryReceived.initialIndex === INITIAL_EVENT_INDEX_FIRST) {
|
||||
if (queryReceived.initialIndex === NT.globals.constants.queries.INITIAL_INDEX_FIRST) {
|
||||
queryReceived.initialIndex = 0
|
||||
}
|
||||
|
||||
@@ -67,11 +60,11 @@ exports.newEvents = function newEvents() {
|
||||
throw ('Amount Requested Is Not a Number.')
|
||||
}
|
||||
|
||||
if (queryReceived.amountRequested < MIN_AMOUNT_REQUESTED) {
|
||||
if (queryReceived.amountRequested < NT.globals.constants.queries.MIN_AMOUNT_REQUESTED) {
|
||||
throw ('Amount Requested Below Min.')
|
||||
}
|
||||
|
||||
if (queryReceived.amountRequested > MAX_AMOUNT_REQUESTED) {
|
||||
if (queryReceived.amountRequested > NT.globals.constants.queries.MAX_AMOUNT_REQUESTED) {
|
||||
throw ('Amount Requested Above Max.')
|
||||
}
|
||||
/*
|
||||
@@ -81,7 +74,7 @@ exports.newEvents = function newEvents() {
|
||||
throw ('Direction Undefined.')
|
||||
}
|
||||
|
||||
if (queryReceived.direction !== DIRECTION_FUTURE && queryReceived.direction !== DIRECTION_PAST) {
|
||||
if (queryReceived.direction !== NT.globals.constants.queries.DIRECTION_FUTURE && queryReceived.direction !== NT.globals.constants.queries.DIRECTION_PAST) {
|
||||
throw ('Direction Not Supported.')
|
||||
}
|
||||
|
||||
@@ -92,7 +85,7 @@ exports.newEvents = function newEvents() {
|
||||
function execute() {
|
||||
let response = []
|
||||
switch (thisObject.direction) {
|
||||
case DIRECTION_FUTURE: {
|
||||
case NT.globals.constants.queries.DIRECTION_FUTURE: {
|
||||
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
|
||||
let event = NT.memory.arrays.EVENTS[i]
|
||||
if (event === undefined) { break }
|
||||
@@ -100,7 +93,7 @@ exports.newEvents = function newEvents() {
|
||||
}
|
||||
break
|
||||
}
|
||||
case DIRECTION_PAST: {
|
||||
case NT.globals.constants.queries.DIRECTION_PAST: {
|
||||
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
|
||||
let event = NT.memory.arrays.EVENTS[i]
|
||||
if (event === undefined) { break }
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
exports.newPostReplies = function newPostReplies() {
|
||||
|
||||
/*
|
||||
Each Post regardless if it is authored by a User or Bot Profile,
|
||||
can have replies. This query is designed for Network Clients to
|
||||
fetch the posts metadata that are replies to a certain post.
|
||||
*/
|
||||
let thisObject = {
|
||||
profile: undefined,
|
||||
post: undefined,
|
||||
initialIndex: undefined,
|
||||
amountRequested: undefined,
|
||||
@@ -10,97 +15,40 @@ exports.newPostReplies = function newPostReplies() {
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
const INITIAL_REPLY_INDEX_FIRST = 'First'
|
||||
const INITIAL_REPLY_INDEX_LAST = 'Last'
|
||||
const MIN_AMOUNT_REQUESTED = 1
|
||||
const MAX_AMOUNT_REQUESTED = 100
|
||||
const DIRECTION_FUTURE = 'Future'
|
||||
const DIRECTION_PAST = 'Past'
|
||||
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
thisObject.profile = undefined
|
||||
thisObject.post = undefined
|
||||
}
|
||||
|
||||
function initialize(queryReceived) {
|
||||
/*
|
||||
Validate Post
|
||||
*/
|
||||
thisObject.post = NT.memory.maps.POSTS.get(queryReceived.targetPostHash)
|
||||
|
||||
if (thisObject.post === undefined) {
|
||||
throw ('Target Post Not Found.')
|
||||
}
|
||||
/*
|
||||
Validate Initial Index
|
||||
*/
|
||||
if (queryReceived.initialIndex === undefined) {
|
||||
throw ('Initial Index Undefined.')
|
||||
}
|
||||
|
||||
if (queryReceived.initialIndex === INITIAL_REPLY_INDEX_LAST) {
|
||||
queryReceived.initialIndex = thisObject.poat.replies.length - 1
|
||||
}
|
||||
|
||||
if (queryReceived.initialIndex === INITIAL_REPLY_INDEX_FIRST) {
|
||||
queryReceived.initialIndex = 0
|
||||
}
|
||||
|
||||
if (isNaN(queryReceived.initialIndex) === true) {
|
||||
throw ('Initial Reply Is Not a Number.')
|
||||
}
|
||||
|
||||
thisObject.initialIndex = queryReceived.initialIndex
|
||||
/*
|
||||
Validate Amount Requested
|
||||
*/
|
||||
if (queryReceived.amountRequested === undefined) {
|
||||
throw ('Amount Requested Undefined.')
|
||||
}
|
||||
|
||||
if (isNaN(queryReceived.amountRequested) === true) {
|
||||
throw ('Amount Requested Is Not a Number.')
|
||||
}
|
||||
|
||||
if (queryReceived.amountRequested < MIN_AMOUNT_REQUESTED) {
|
||||
throw ('Amount Requested Below Min.')
|
||||
}
|
||||
|
||||
if (queryReceived.amountRequested > MAX_AMOUNT_REQUESTED) {
|
||||
throw ('Amount Requested Above Max.')
|
||||
}
|
||||
/*
|
||||
Validate Direction
|
||||
*/
|
||||
if (queryReceived.direction === undefined) {
|
||||
throw ('Direction Undefined.')
|
||||
}
|
||||
|
||||
if (queryReceived.direction !== DIRECTION_FUTURE && queryReceived.direction !== DIRECTION_PAST) {
|
||||
throw ('Direction Not Supported.')
|
||||
}
|
||||
|
||||
thisObject.direction = queryReceived.direction
|
||||
NT.utilities.queriesValidations.profilesValidations(queryReceived, thisObject)
|
||||
NT.utilities.queriesValidations.postValidations(queryReceived, thisObject)
|
||||
NT.utilities.queriesValidations.arrayValidations(queryReceived, thisObject)
|
||||
|
||||
}
|
||||
|
||||
function execute() {
|
||||
|
||||
let response = []
|
||||
let array = Array.from(thisObject.post.replies)
|
||||
|
||||
switch (thisObject.direction) {
|
||||
case DIRECTION_FUTURE: {
|
||||
case NT.globals.constants.queries.DIRECTION_FUTURE: {
|
||||
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
|
||||
let post = thisObject.post.replies[i]
|
||||
let arrayItem = array[i]
|
||||
if (post === undefined) { break }
|
||||
addToResponse(post)
|
||||
addToResponse(arrayItem)
|
||||
}
|
||||
break
|
||||
}
|
||||
case DIRECTION_PAST: {
|
||||
case NT.globals.constants.queries.DIRECTION_PAST: {
|
||||
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
|
||||
let post = thisObject.post.replies[i]
|
||||
let arrayItem = array[i]
|
||||
if (post === undefined) { break }
|
||||
addToResponse(post)
|
||||
addToResponse(arrayItem)
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -111,11 +59,13 @@ exports.newPostReplies = function newPostReplies() {
|
||||
let postResponse = {
|
||||
emitterUserProfileId: post.emitterUserProfileId,
|
||||
targetUserProfileId: post.targetUserProfileId,
|
||||
emitterBotProfileId: post.emitterBotProfileId,
|
||||
targetBotProfileId: post.targetBotProfileId,
|
||||
emitterPostHash: post.emitterPostHash,
|
||||
targetPostHash: post.targetPostHash,
|
||||
postType: post.postType,
|
||||
timestamp: post.timestamp,
|
||||
repliesCount: post.replies.length,
|
||||
repliesCount: post.replies.size,
|
||||
reactions: Array.from(post.reactions)
|
||||
}
|
||||
response.push(postResponse)
|
||||
|
||||
@@ -10,13 +10,6 @@ exports.newProfileFollowers = function newProfileFollowers() {
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
const INITIAL_POST_INDEX_FIRST = 'First'
|
||||
const INITIAL_POST_INDEX_LAST = 'Last'
|
||||
const MIN_AMOUNT_REQUESTED = 1
|
||||
const MAX_AMOUNT_REQUESTED = 100
|
||||
const DIRECTION_FUTURE = 'Future'
|
||||
const DIRECTION_PAST = 'Past'
|
||||
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
@@ -24,94 +17,29 @@ exports.newProfileFollowers = function newProfileFollowers() {
|
||||
}
|
||||
|
||||
function initialize(queryReceived) {
|
||||
/*
|
||||
Validate User Profile
|
||||
*/
|
||||
if (queryReceived.targetUserProfileId !== undefined) {
|
||||
thisObject.profile = NT.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId)
|
||||
} else {
|
||||
thisObject.profile = NT.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle)
|
||||
}
|
||||
|
||||
if (thisObject.profile === undefined) {
|
||||
throw ('Target User Profile Not Found.')
|
||||
}
|
||||
/*
|
||||
Validate Bot Profile
|
||||
*/
|
||||
if (queryReceived.targetBotProfileId !== undefined) {
|
||||
thisObject.profile = thisObject.profile.bots.get(queryReceived.targetBotProfileId)
|
||||
if (thisObject.profile === undefined) {
|
||||
throw ('Target Bot Profile Not Found.')
|
||||
}
|
||||
}
|
||||
/*
|
||||
Validate Initial Index
|
||||
*/
|
||||
if (queryReceived.initialIndex === undefined) {
|
||||
throw ('Initial Index Undefined.')
|
||||
}
|
||||
|
||||
if (queryReceived.initialIndex === INITIAL_POST_INDEX_LAST) {
|
||||
queryReceived.initialIndex = thisObject.profile.posts.length - 1
|
||||
}
|
||||
|
||||
if (queryReceived.initialIndex === INITIAL_POST_INDEX_FIRST) {
|
||||
queryReceived.initialIndex = 0
|
||||
}
|
||||
|
||||
if (isNaN(queryReceived.initialIndex) === true) {
|
||||
throw ('Initial Post Is Not a Number.')
|
||||
}
|
||||
|
||||
thisObject.initialIndex = queryReceived.initialIndex
|
||||
/*
|
||||
Validate Amount Requested
|
||||
*/
|
||||
if (queryReceived.amountRequested === undefined) {
|
||||
throw ('Amount Requested Undefined.')
|
||||
}
|
||||
|
||||
if (isNaN(queryReceived.amountRequested) === true) {
|
||||
throw ('Amount Requested Is Not a Number.')
|
||||
}
|
||||
|
||||
if (queryReceived.amountRequested < MIN_AMOUNT_REQUESTED) {
|
||||
throw ('Amount Requested Below Min.')
|
||||
}
|
||||
|
||||
if (queryReceived.amountRequested > MAX_AMOUNT_REQUESTED) {
|
||||
throw ('Amount Requested Above Max.')
|
||||
}
|
||||
/*
|
||||
Validate Direction
|
||||
*/
|
||||
if (queryReceived.direction === undefined) {
|
||||
throw ('Direction Undefined.')
|
||||
}
|
||||
|
||||
if (queryReceived.direction !== DIRECTION_FUTURE && queryReceived.direction !== DIRECTION_PAST) {
|
||||
throw ('Direction Not Supported.')
|
||||
}
|
||||
|
||||
thisObject.direction = queryReceived.direction
|
||||
NT.utilities.queriesValidations.profilesValidations(queryReceived, thisObject)
|
||||
NT.utilities.queriesValidations.arrayValidations(queryReceived, thisObject)
|
||||
|
||||
}
|
||||
|
||||
function execute() {
|
||||
|
||||
let response = []
|
||||
let array = Array.from(thisObject.profile.followers)
|
||||
|
||||
switch (thisObject.direction) {
|
||||
case DIRECTION_FUTURE: {
|
||||
case NT.globals.constants.queries.DIRECTION_FUTURE: {
|
||||
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
|
||||
let arrayItem = thisObject.profile.arrays.followers[i]
|
||||
let arrayItem = array[i]
|
||||
if (arrayItem === undefined) { break }
|
||||
addToResponse(arrayItem)
|
||||
}
|
||||
break
|
||||
}
|
||||
case DIRECTION_PAST: {
|
||||
case NT.globals.constants.queries.DIRECTION_PAST: {
|
||||
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
|
||||
let arrayItem = thisObject.profile.arrays.followers[i]
|
||||
let arrayItem = array[i]
|
||||
if (arrayItem === undefined) { break }
|
||||
addToResponse(arrayItem)
|
||||
}
|
||||
@@ -120,16 +48,10 @@ exports.newProfileFollowers = function newProfileFollowers() {
|
||||
}
|
||||
return response
|
||||
|
||||
function addToResponse(post) {
|
||||
function addToResponse(arrayItem) {
|
||||
let postResponse = {
|
||||
emitterUserProfileId: post.emitterUserProfileId,
|
||||
targetUserProfileId: post.targetUserProfileId,
|
||||
emitterPostHash: post.emitterPostHash,
|
||||
targetPostHash: post.targetPostHash,
|
||||
postType: post.postType,
|
||||
timestamp: post.timestamp,
|
||||
repliesCount: post.replies.length,
|
||||
reactions: Array.from(post.reactions)
|
||||
emitterUserProfileId: arrayItem.emitterUserProfileId,
|
||||
emitterBotProfileId: arrayItem.emitterBotProfileId
|
||||
}
|
||||
response.push(postResponse)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
exports.newProfileFollowing = function newProfileFollowing() {
|
||||
|
||||
let thisObject = {
|
||||
profile: undefined,
|
||||
initialIndex: undefined,
|
||||
amountRequested: undefined,
|
||||
direction: undefined,
|
||||
execute: execute,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
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 NT.globals.constants.queries.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 NT.globals.constants.queries.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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
exports.newProfilePosts = function newProfilePosts() {
|
||||
|
||||
/*
|
||||
Each User or Bot Profile can have posts. This query
|
||||
is designed for Network Clients to fetch the posts
|
||||
metadata they need from the Social Graph.
|
||||
*/
|
||||
let thisObject = {
|
||||
profile: undefined,
|
||||
initialIndex: undefined,
|
||||
@@ -10,13 +14,6 @@ exports.newProfilePosts = function newProfilePosts() {
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
const INITIAL_POST_INDEX_FIRST = 'First'
|
||||
const INITIAL_POST_INDEX_LAST = 'Last'
|
||||
const MIN_AMOUNT_REQUESTED = 1
|
||||
const MAX_AMOUNT_REQUESTED = 100
|
||||
const DIRECTION_FUTURE = 'Future'
|
||||
const DIRECTION_PAST = 'Past'
|
||||
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
@@ -24,94 +21,28 @@ exports.newProfilePosts = function newProfilePosts() {
|
||||
}
|
||||
|
||||
function initialize(queryReceived) {
|
||||
/*
|
||||
Validate User Profile
|
||||
*/
|
||||
if (queryReceived.targetUserProfileId !== undefined) {
|
||||
thisObject.profile = NT.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId)
|
||||
} else {
|
||||
thisObject.profile = NT.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle)
|
||||
}
|
||||
|
||||
if (thisObject.profile === undefined) {
|
||||
throw ('Target User Profile Not Found.')
|
||||
}
|
||||
/*
|
||||
Validate Bot Profile
|
||||
*/
|
||||
if (queryReceived.targetBotProfileId !== undefined) {
|
||||
thisObject.profile = thisObject.profile.bots.get(queryReceived.targetBotProfileId)
|
||||
if (thisObject.profile === undefined) {
|
||||
throw ('Target Bot Profile Not Found.')
|
||||
}
|
||||
}
|
||||
/*
|
||||
Validate Initial Index
|
||||
*/
|
||||
if (queryReceived.initialIndex === undefined) {
|
||||
throw ('Initial Index Undefined.')
|
||||
}
|
||||
|
||||
if (queryReceived.initialIndex === INITIAL_POST_INDEX_LAST) {
|
||||
queryReceived.initialIndex = thisObject.profile.posts.length - 1
|
||||
}
|
||||
|
||||
if (queryReceived.initialIndex === INITIAL_POST_INDEX_FIRST) {
|
||||
queryReceived.initialIndex = 0
|
||||
}
|
||||
|
||||
if (isNaN(queryReceived.initialIndex) === true) {
|
||||
throw ('Initial Post Is Not a Number.')
|
||||
}
|
||||
|
||||
thisObject.initialIndex = queryReceived.initialIndex
|
||||
/*
|
||||
Validate Amount Requested
|
||||
*/
|
||||
if (queryReceived.amountRequested === undefined) {
|
||||
throw ('Amount Requested Undefined.')
|
||||
}
|
||||
|
||||
if (isNaN(queryReceived.amountRequested) === true) {
|
||||
throw ('Amount Requested Is Not a Number.')
|
||||
}
|
||||
|
||||
if (queryReceived.amountRequested < MIN_AMOUNT_REQUESTED) {
|
||||
throw ('Amount Requested Below Min.')
|
||||
}
|
||||
|
||||
if (queryReceived.amountRequested > MAX_AMOUNT_REQUESTED) {
|
||||
throw ('Amount Requested Above Max.')
|
||||
}
|
||||
/*
|
||||
Validate Direction
|
||||
*/
|
||||
if (queryReceived.direction === undefined) {
|
||||
throw ('Direction Undefined.')
|
||||
}
|
||||
|
||||
if (queryReceived.direction !== DIRECTION_FUTURE && queryReceived.direction !== DIRECTION_PAST) {
|
||||
throw ('Direction Not Supported.')
|
||||
}
|
||||
|
||||
thisObject.direction = queryReceived.direction
|
||||
|
||||
NT.utilities.queriesValidations.profilesValidations(queryReceived, thisObject)
|
||||
NT.utilities.queriesValidations.arrayValidations(queryReceived, thisObject)
|
||||
}
|
||||
|
||||
function execute() {
|
||||
|
||||
let response = []
|
||||
let array = Array.from(thisObject.profile.posts)
|
||||
|
||||
switch (thisObject.direction) {
|
||||
case DIRECTION_FUTURE: {
|
||||
case NT.globals.constants.queries.DIRECTION_FUTURE: {
|
||||
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
|
||||
let arrayItem = thisObject.profile.arrays.posts[i]
|
||||
let arrayItem = array[i]
|
||||
if (arrayItem === undefined) { break }
|
||||
addToResponse(arrayItem)
|
||||
}
|
||||
break
|
||||
}
|
||||
case DIRECTION_PAST: {
|
||||
case NT.globals.constants.queries.DIRECTION_PAST: {
|
||||
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
|
||||
let arrayItem = thisObject.profile.arrays.posts[i]
|
||||
let arrayItem = array[i]
|
||||
if (arrayItem === undefined) { break }
|
||||
addToResponse(arrayItem)
|
||||
}
|
||||
@@ -124,11 +55,13 @@ exports.newProfilePosts = function newProfilePosts() {
|
||||
let postResponse = {
|
||||
emitterUserProfileId: post.emitterUserProfileId,
|
||||
targetUserProfileId: post.targetUserProfileId,
|
||||
emitterBotProfileId: post.emitterBotProfileId,
|
||||
targetBotProfileId: post.targetBotProfileId,
|
||||
emitterPostHash: post.emitterPostHash,
|
||||
targetPostHash: post.targetPostHash,
|
||||
postType: post.postType,
|
||||
timestamp: post.timestamp,
|
||||
repliesCount: post.replies.length,
|
||||
repliesCount: post.replies.size,
|
||||
reactions: Array.from(post.reactions)
|
||||
}
|
||||
response.push(postResponse)
|
||||
|
||||
@@ -26,7 +26,6 @@ exports.newUserProfileStats = function newUserProfileStats() {
|
||||
if (thisObject.profile === undefined) {
|
||||
throw ('Target User Profile Not Found.')
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function execute() {
|
||||
@@ -36,12 +35,12 @@ exports.newUserProfileStats = function newUserProfileStats() {
|
||||
"userProfileHandle": thisObject.profile.userProfileHandle,
|
||||
"blockchainAccount": thisObject.profile.blockchainAccount,
|
||||
"ranking": thisObject.profile.ranking,
|
||||
"followingCount": thisObject.profile.followingCount,
|
||||
"followersCount": thisObject.profile.followersCount,
|
||||
"followingCount": thisObject.profile.following.size,
|
||||
"followersCount": thisObject.profile.followers.size,
|
||||
"postsCount": thisObject.profile.posts.size,
|
||||
"botsCount": thisObject.profile.bots.size,
|
||||
"emitterEventsCount": thisObject.profile.emitterEventsCount,
|
||||
"targetEventsCount": thisObject.profile.targetEventsCount,
|
||||
"postsCount": thisObject.profile.postsCount,
|
||||
"botsCount": thisObject.profile.botsCount
|
||||
"targetEventsCount": thisObject.profile.targetEventsCount
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,12 @@
|
||||
exports.newQuery = function newQuery() {
|
||||
/*
|
||||
A Query is a call from a Network Client to
|
||||
a Network Node with the purpose to get
|
||||
relevant information from the Social Graph.
|
||||
|
||||
A Query does not produce changes
|
||||
on the state of the Social Graph.
|
||||
*/
|
||||
let thisObject = {
|
||||
query: undefined,
|
||||
queryType: undefined,
|
||||
|
||||
@@ -5,7 +5,6 @@ global.NT = {
|
||||
maps: {
|
||||
USER_PROFILES_BY_ID: new Map(), // Here we will store the user profiles by User Profile Id.
|
||||
USER_PROFILES_BY_HANDLE: new Map(), // Here we will store the user profiles by User Profile Handle.
|
||||
POSTS: new Map(), // This are all the posts we are keeping track of.
|
||||
EVENTS: new Map(), // This is the registry of all events received that prevents processing them more than once.
|
||||
},
|
||||
arrays: {
|
||||
@@ -23,16 +22,24 @@ global.NT = {
|
||||
QUERY_BOT_PROFILE_STATS: require('./Queries/BotProfileStats.js'),
|
||||
QUERY_PROFILE_POSTS: require('./Queries/ProfilePosts.js'),
|
||||
QUERY_PROFILE_FOLLOWERS: require('./Queries/ProfileFollowers.js'),
|
||||
//QUERY_PROFILE_FOLLOWING: require('./Queries/ProfileFollowing.js'),
|
||||
//QUERY_POST_REPLIES: require('./Queries/ProfileReplies.js'),
|
||||
QUERY_PROFILE_FOLLOWING: require('./Queries/ProfileFollowing.js'),
|
||||
QUERY_POST_REPLIES: require('./Queries/PostReplies.js'),
|
||||
QUERY_EVENTS: require('./Queries/Events.js')
|
||||
},
|
||||
utilities: {
|
||||
queriesValidations: require('./Utilities/QueriesValidations.js').newProfileQueries()
|
||||
},
|
||||
globals: {
|
||||
constants: {
|
||||
queries: {
|
||||
INITIAL_INDEX_FIRST: 'First',
|
||||
INITIAL_INDEX_LAST: 'Last',
|
||||
MIN_AMOUNT_REQUESTED: 1,
|
||||
MAX_AMOUNT_REQUESTED: 100,
|
||||
DIRECTION_FUTURE: 'Future',
|
||||
DIRECTION_PAST: 'Past'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const map = new Map([[1, { a: 2 }], [2, { a: 4 }], [4, { a: 8 }]])
|
||||
map.set(3, { a: 6 })
|
||||
map.delete(2)
|
||||
map.set(2, { a: 12 })
|
||||
let array = Array.from(map)
|
||||
|
||||
console.log(JSON.stringify(array))
|
||||
@@ -0,0 +1,97 @@
|
||||
exports.newProfileFollowers = function newProfileFollowers() {
|
||||
|
||||
let thisObject = {
|
||||
profilesValidations: profilesValidations,
|
||||
postValidations: postValidations,
|
||||
arrayValidations: arrayValidations
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function profilesValidations(queryReceived, thisObject) {
|
||||
/*
|
||||
Validate User Profile
|
||||
*/
|
||||
if (queryReceived.targetUserProfileId !== undefined) {
|
||||
thisObject.profile = NT.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId)
|
||||
}
|
||||
|
||||
if (thisObject.profile === undefined) {
|
||||
throw ('Target User Profile Not Found.')
|
||||
}
|
||||
/*
|
||||
Validate Bot Profile
|
||||
*/
|
||||
if (queryReceived.targetBotProfileId !== undefined) {
|
||||
thisObject.profile = thisObject.profile.bots.get(queryReceived.targetBotProfileId)
|
||||
if (thisObject.profile === undefined) {
|
||||
throw ('Target Bot Profile Not Found.')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function postValidations(queryReceived, thisObject) {
|
||||
/*
|
||||
Validate Post
|
||||
*/
|
||||
thisObject.post = thisObject.profile.posts.get(queryReceived.targetPostHash)
|
||||
|
||||
if (thisObject.post === undefined) {
|
||||
throw ('Target Post Not Found.')
|
||||
}
|
||||
}
|
||||
|
||||
function arrayValidations(queryReceived, thisObject) {
|
||||
/*
|
||||
Validate Initial Index
|
||||
*/
|
||||
if (queryReceived.initialIndex === undefined) {
|
||||
throw ('Initial Index Undefined.')
|
||||
}
|
||||
|
||||
if (queryReceived.initialIndex === NT.globals.constants.queries.INITIAL_INDEX_LAST) {
|
||||
queryReceived.initialIndex = thisObject.profile.posts.length - 1
|
||||
}
|
||||
|
||||
if (queryReceived.initialIndex === NT.globals.constants.queries.INITIAL_INDEX_FIRST) {
|
||||
queryReceived.initialIndex = 0
|
||||
}
|
||||
|
||||
if (isNaN(queryReceived.initialIndex) === true) {
|
||||
throw ('Initial Post Is Not a Number.')
|
||||
}
|
||||
|
||||
thisObject.initialIndex = queryReceived.initialIndex
|
||||
/*
|
||||
Validate Amount Requested
|
||||
*/
|
||||
if (queryReceived.amountRequested === undefined) {
|
||||
throw ('Amount Requested Undefined.')
|
||||
}
|
||||
|
||||
if (isNaN(queryReceived.amountRequested) === true) {
|
||||
throw ('Amount Requested Is Not a Number.')
|
||||
}
|
||||
|
||||
if (queryReceived.amountRequested < NT.globals.constants.queries.MIN_AMOUNT_REQUESTED) {
|
||||
throw ('Amount Requested Below Min.')
|
||||
}
|
||||
|
||||
if (queryReceived.amountRequested > NT.globals.constants.queries.MAX_AMOUNT_REQUESTED) {
|
||||
throw ('Amount Requested Above Max.')
|
||||
}
|
||||
/*
|
||||
Validate Direction
|
||||
*/
|
||||
if (queryReceived.direction === undefined) {
|
||||
throw ('Direction Undefined.')
|
||||
}
|
||||
|
||||
if (queryReceived.direction !== NT.globals.constants.queries.DIRECTION_FUTURE && queryReceived.direction !== NT.globals.constants.queries.DIRECTION_PAST) {
|
||||
throw ('Direction Not Supported.')
|
||||
}
|
||||
|
||||
thisObject.direction = queryReceived.direction
|
||||
|
||||
}
|
||||
}
|
||||
+17
-12
@@ -7,6 +7,7 @@ exports.newBotProfile = function newBotProfile() {
|
||||
*/
|
||||
let thisObject = {
|
||||
/* Unique Keys */
|
||||
userProfileId: undefined,
|
||||
botProfileId: undefined,
|
||||
botProfileHandle: undefined,
|
||||
/* Bot Unitque Properties */
|
||||
@@ -45,11 +46,13 @@ exports.newBotProfile = function newBotProfile() {
|
||||
}
|
||||
|
||||
function initialize(
|
||||
userProfileId,
|
||||
botProfileId,
|
||||
botAsset,
|
||||
botExchange,
|
||||
botEnabled
|
||||
) {
|
||||
thisObject.userProfileId = userProfileId
|
||||
thisObject.botProfileId = botProfileId
|
||||
thisObject.botAsset = botAsset
|
||||
thisObject.botExchange = botExchange
|
||||
@@ -106,38 +109,40 @@ exports.newBotProfile = function newBotProfile() {
|
||||
}
|
||||
|
||||
function addFollowing(
|
||||
targetUserProfileId
|
||||
targetUserProfileId,
|
||||
targetBotProfileId
|
||||
) {
|
||||
if (thisObject.following.get(targetUserProfileId) === undefined) {
|
||||
thisObject.following.set(targetUserProfileId, targetUserProfileId)
|
||||
if (thisObject.following.get(targetBotProfileId) === undefined) {
|
||||
thisObject.following.set(targetBotProfileId, { targetUserProfileId: targetUserProfileId, targetBotProfileId: targetBotProfileId })
|
||||
} else {
|
||||
throw ('Already Following.')
|
||||
}
|
||||
}
|
||||
|
||||
function removeFollowing(
|
||||
targetUserProfileId
|
||||
targetBotProfileId
|
||||
) {
|
||||
if (thisObject.following.get(targetUserProfileId) !== undefined) {
|
||||
thisObject.following.delete(targetUserProfileId)
|
||||
if (thisObject.following.get(targetBotProfileId) !== undefined) {
|
||||
thisObject.following.delete(targetBotProfileId)
|
||||
} else {
|
||||
throw ('Not Following.')
|
||||
}
|
||||
}
|
||||
|
||||
function addFollower(
|
||||
emitterUserProfileId
|
||||
emitterUserProfileId,
|
||||
emitterBotProfileId
|
||||
) {
|
||||
if (thisObject.followers.get(emitterUserProfileId) === undefined) {
|
||||
thisObject.followers.set(emitterUserProfileId, emitterUserProfileId)
|
||||
if (thisObject.followers.get(emitterBotProfileId) === undefined) {
|
||||
thisObject.followers.set(emitterBotProfileId, { emitterUserProfileId: emitterUserProfileId, emitterBotProfileId: emitterBotProfileId })
|
||||
}
|
||||
}
|
||||
|
||||
function removeFollower(
|
||||
emitterUserProfileId
|
||||
emitterBotProfileId
|
||||
) {
|
||||
if (thisObject.followers.get(emitterUserProfileId) !== undefined) {
|
||||
thisObject.followers.delete(emitterUserProfileId)
|
||||
if (thisObject.followers.get(emitterBotProfileId) !== undefined) {
|
||||
thisObject.followers.delete(emitterBotProfileId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,12 +26,14 @@ exports.newClientInterface = function newClientInterface() {
|
||||
"eventType": 10,
|
||||
"emitterUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"targetUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"emitterBotProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"targetBBotProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"emitterPostHash": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"targetPostHash": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"timestamp": 124234234234,
|
||||
"botId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"botAsset": "BTC",
|
||||
"botExchange": "Binance"
|
||||
"botExchange": "Binance",
|
||||
"botEnabled": true
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -56,10 +58,11 @@ exports.newClientInterface = function newClientInterface() {
|
||||
"targetUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"emitterUserProfileHandle": "Luis-Fernando-Molina",
|
||||
"targetUserProfileHandle": "Luis-Fernando-Molina",
|
||||
"emitterBotProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"targetBBotProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"emitterPostHash": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"targetPostHash": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"timestamp": 124234234234,
|
||||
"botId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"botAsset": "BTC",
|
||||
"botExchange": "Binance",
|
||||
"botEnabled": true,
|
||||
|
||||
@@ -289,9 +289,11 @@ exports.newEvent = function newEvent() {
|
||||
}
|
||||
|
||||
emitterBotProfile.addFollowing(
|
||||
targetUserProfileId,
|
||||
targetBotProfileId
|
||||
)
|
||||
targetBotProfile.addFollower(
|
||||
emitterUserProfileId,
|
||||
emitterBotProfileId
|
||||
)
|
||||
break
|
||||
@@ -374,6 +376,7 @@ exports.newEvent = function newEvent() {
|
||||
switch (thisObject.eventType) {
|
||||
case EVENT_TYPES.ADD_BOT: {
|
||||
emitterUserProfile.addBot(
|
||||
thisObject.emitterUserProfileId,
|
||||
thisObject.emitterBotProfileId,
|
||||
thisObject.botAsset,
|
||||
thisObject.botExchange,
|
||||
|
||||
@@ -149,6 +149,7 @@ exports.newUserProfile = function newUserProfile() {
|
||||
}
|
||||
|
||||
function addBot(
|
||||
userProfileId,
|
||||
botProfileId,
|
||||
botAsset,
|
||||
botExchange,
|
||||
@@ -160,6 +161,7 @@ exports.newUserProfile = function newUserProfile() {
|
||||
} else {
|
||||
let bot = NT.modules.BOTS.newBot()
|
||||
bot.initialize(
|
||||
userProfileId,
|
||||
botProfileId,
|
||||
botAsset,
|
||||
botExchange,
|
||||
|
||||
Reference in new issue
Block a user