From c7011e4183107b33c52451fe792d4039da67ec26 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 29 Aug 2021 13:11:22 +0200 Subject: [PATCH 1/9] added userprofileId to Bot --- Network/botProfile.js | 3 +++ Network/event.js | 1 + Network/userProfile.js | 2 ++ 3 files changed, 6 insertions(+) diff --git a/Network/botProfile.js b/Network/botProfile.js index a85bcfa57..2be6b4437 100644 --- a/Network/botProfile.js +++ b/Network/botProfile.js @@ -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 diff --git a/Network/event.js b/Network/event.js index b3329a046..2afa3effa 100644 --- a/Network/event.js +++ b/Network/event.js @@ -374,6 +374,7 @@ exports.newEvent = function newEvent() { switch (thisObject.eventType) { case EVENT_TYPES.ADD_BOT: { emitterUserProfile.addBot( + thisObject.emitterUserProfileId, thisObject.emitterBotProfileId, thisObject.botAsset, thisObject.botExchange, diff --git a/Network/userProfile.js b/Network/userProfile.js index 88a0d26f4..0144038cd 100644 --- a/Network/userProfile.js +++ b/Network/userProfile.js @@ -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, From dec45412108e90473ce93f4849753610daa812d3 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 29 Aug 2021 13:18:57 +0200 Subject: [PATCH 2/9] Bug Fixed with Following and Followers of Bots --- Network/botProfile.js | 26 ++++++++++++++------------ Network/event.js | 2 ++ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Network/botProfile.js b/Network/botProfile.js index 2be6b4437..e7ce60b41 100644 --- a/Network/botProfile.js +++ b/Network/botProfile.js @@ -109,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) } } } diff --git a/Network/event.js b/Network/event.js index 2afa3effa..b586d9077 100644 --- a/Network/event.js +++ b/Network/event.js @@ -289,9 +289,11 @@ exports.newEvent = function newEvent() { } emitterBotProfile.addFollowing( + targetUserProfileId, targetBotProfileId ) targetBotProfile.addFollower( + emitterUserProfileId, emitterBotProfileId ) break From 4c9701965a2d576809921b3a94b3bb08b41aafae Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 29 Aug 2021 13:51:03 +0200 Subject: [PATCH 3/9] User Profile and Bot Profiles Statistics done --- Network/Queries/BotProfileStats.js | 15 ++++++++------- Network/Queries/UserProfileStats.js | 11 +++++------ Network/Query.js | 7 +++++++ Network/clientsInterface.js | 9 ++++++--- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/Network/Queries/BotProfileStats.js b/Network/Queries/BotProfileStats.js index 137072fb9..510f1ebb3 100644 --- a/Network/Queries/BotProfileStats.js +++ b/Network/Queries/BotProfileStats.js @@ -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 } } } \ No newline at end of file diff --git a/Network/Queries/UserProfileStats.js b/Network/Queries/UserProfileStats.js index 383d39aab..a7fd8580b 100644 --- a/Network/Queries/UserProfileStats.js +++ b/Network/Queries/UserProfileStats.js @@ -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 } } } \ No newline at end of file diff --git a/Network/Query.js b/Network/Query.js index 6842871ee..f69f56841 100644 --- a/Network/Query.js +++ b/Network/Query.js @@ -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, diff --git a/Network/clientsInterface.js b/Network/clientsInterface.js index 66b4c0650..1cc17e4d6 100644 --- a/Network/clientsInterface.js +++ b/Network/clientsInterface.js @@ -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, From 2812dc2ab107b61dd0dc7f3404ad545ad7062755 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 29 Aug 2021 16:31:32 +0200 Subject: [PATCH 4/9] Update ProfilePosts.js --- Network/Queries/ProfilePosts.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Network/Queries/ProfilePosts.js b/Network/Queries/ProfilePosts.js index b24381946..e74d7e81b 100644 --- a/Network/Queries/ProfilePosts.js +++ b/Network/Queries/ProfilePosts.js @@ -45,6 +45,13 @@ exports.newProfilePosts = function newProfilePosts() { throw ('Target Bot Profile Not Found.') } } + + if (queryReceived.targetBotProfileHandle !== undefined) { + thisObject.profile = thisObject.profile.bots.get(queryReceived.targetBotProfileHandle) + if (thisObject.profile === undefined) { + throw ('Target Bot Profile Not Found.') + } + } /* Validate Initial Index */ @@ -102,16 +109,18 @@ exports.newProfilePosts = function newProfilePosts() { let response = [] switch (thisObject.direction) { case DIRECTION_FUTURE: { + let array = Array.from(thisObject.profile.posts) 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: { + let array = Array.from(thisObject.profile.posts) 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 +133,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) From 50e6643062f7bc20882200ec2d4ec5599b5bb6f7 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 29 Aug 2021 16:53:34 +0200 Subject: [PATCH 5/9] Post Replies Query done --- Network/Queries/PostReplies.js | 43 +++++++++++++++++++++++++++------ Network/Queries/ProfilePosts.js | 22 +++++++---------- 2 files changed, 45 insertions(+), 20 deletions(-) diff --git a/Network/Queries/PostReplies.js b/Network/Queries/PostReplies.js index 4661d692e..6a27a1cc5 100644 --- a/Network/Queries/PostReplies.js +++ b/Network/Queries/PostReplies.js @@ -1,5 +1,9 @@ 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 = { post: undefined, initialIndex: undefined, @@ -24,10 +28,30 @@ exports.newPostReplies = function newPostReplies() { } function initialize(queryReceived) { + let profile + /* + Validate User Profile + */ + if (queryReceived.targetUserProfileId !== undefined) { + profile = NT.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) + } + + if (profile === undefined) { + throw ('Target User Profile Not Found.') + } + /* + Validate Bot Profile + */ + if (queryReceived.targetBotProfileId !== undefined) { + profile = profile.bots.get(queryReceived.targetBotProfileId) + if (profile === undefined) { + throw ('Target Bot Profile Not Found.') + } + } /* Validate Post */ - thisObject.post = NT.memory.maps.POSTS.get(queryReceived.targetPostHash) + thisObject.post = profile.posts.get(queryReceived.targetPostHash) if (thisObject.post === undefined) { throw ('Target Post Not Found.') @@ -86,21 +110,24 @@ exports.newPostReplies = function newPostReplies() { } function execute() { + let response = [] + let array = Array.from(thisObject.post.replies) + switch (thisObject.direction) { case 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: { 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 +138,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) diff --git a/Network/Queries/ProfilePosts.js b/Network/Queries/ProfilePosts.js index e74d7e81b..60e83d135 100644 --- a/Network/Queries/ProfilePosts.js +++ b/Network/Queries/ProfilePosts.js @@ -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, @@ -29,9 +33,7 @@ exports.newProfilePosts = function newProfilePosts() { */ 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.') @@ -45,13 +47,6 @@ exports.newProfilePosts = function newProfilePosts() { throw ('Target Bot Profile Not Found.') } } - - if (queryReceived.targetBotProfileHandle !== undefined) { - thisObject.profile = thisObject.profile.bots.get(queryReceived.targetBotProfileHandle) - if (thisObject.profile === undefined) { - throw ('Target Bot Profile Not Found.') - } - } /* Validate Initial Index */ @@ -106,10 +101,12 @@ exports.newProfilePosts = function newProfilePosts() { } function execute() { + let response = [] + let array = Array.from(thisObject.profile.posts) + switch (thisObject.direction) { case DIRECTION_FUTURE: { - let array = Array.from(thisObject.profile.posts) for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) { let arrayItem = array[i] if (arrayItem === undefined) { break } @@ -118,7 +115,6 @@ exports.newProfilePosts = function newProfilePosts() { break } case DIRECTION_PAST: { - let array = Array.from(thisObject.profile.posts) for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) { let arrayItem = array[i] if (arrayItem === undefined) { break } From 541370c6a8a7c7e696358daff099954a4f343ffa Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 29 Aug 2021 17:11:14 +0200 Subject: [PATCH 6/9] Queries Following and Followers --- Network/Queries/ProfileFollowers.js | 21 ++--- Network/Queries/ProfileFollowing.js | 132 ++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+), 13 deletions(-) create mode 100644 Network/Queries/ProfileFollowing.js diff --git a/Network/Queries/ProfileFollowers.js b/Network/Queries/ProfileFollowers.js index 829a5f212..915f65c1a 100644 --- a/Network/Queries/ProfileFollowers.js +++ b/Network/Queries/ProfileFollowers.js @@ -29,8 +29,6 @@ exports.newProfileFollowers = function newProfileFollowers() { */ 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) { @@ -99,11 +97,14 @@ exports.newProfileFollowers = function newProfileFollowers() { } function execute() { + let response = [] + let array = Array.from(thisObject.profile.followers) + switch (thisObject.direction) { case 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) } @@ -111,7 +112,7 @@ exports.newProfileFollowers = function newProfileFollowers() { } case 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 +121,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) } diff --git a/Network/Queries/ProfileFollowing.js b/Network/Queries/ProfileFollowing.js new file mode 100644 index 000000000..8c0336190 --- /dev/null +++ b/Network/Queries/ProfileFollowing.js @@ -0,0 +1,132 @@ +exports.newProfileFollowing = function newProfileFollowing() { + + let thisObject = { + profile: undefined, + initialIndex: undefined, + amountRequested: undefined, + direction: undefined, + execute: execute, + initialize: initialize, + 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() { + thisObject.profile = undefined + } + + function initialize(queryReceived) { + /* + 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.') + } + } + /* + 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 + + } + + 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) + } + } +} \ No newline at end of file From 79adad9893cbb07216bf2d544912b0125fccff61 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 29 Aug 2021 17:34:54 +0200 Subject: [PATCH 7/9] Utilities for Queries --- Network/Queries/PostReplies.js | 86 ++------------------ Network/Queries/ProfileFollowers.js | 74 +---------------- Network/Queries/ProfileFollowing.js | 74 +---------------- Network/Queries/ProfilePosts.js | 75 +---------------- Network/SocialGraphNetwokNode.js | 3 + Network/Utilities/QueriesValidations.js | 104 ++++++++++++++++++++++++ 6 files changed, 118 insertions(+), 298 deletions(-) create mode 100644 Network/Utilities/QueriesValidations.js diff --git a/Network/Queries/PostReplies.js b/Network/Queries/PostReplies.js index 6a27a1cc5..6eb79e96c 100644 --- a/Network/Queries/PostReplies.js +++ b/Network/Queries/PostReplies.js @@ -5,6 +5,7 @@ exports.newPostReplies = function newPostReplies() { fetch the posts metadata that are replies to a certain post. */ let thisObject = { + profile: undefined, post: undefined, initialIndex: undefined, amountRequested: undefined, @@ -14,98 +15,21 @@ 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) { - let profile - /* - Validate User Profile - */ - if (queryReceived.targetUserProfileId !== undefined) { - profile = NT.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) - } - if (profile === undefined) { - throw ('Target User Profile Not Found.') - } - /* - Validate Bot Profile - */ - if (queryReceived.targetBotProfileId !== undefined) { - profile = profile.bots.get(queryReceived.targetBotProfileId) - if (profile === undefined) { - throw ('Target Bot Profile Not Found.') - } - } - /* - Validate Post - */ - thisObject.post = profile.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) } diff --git a/Network/Queries/ProfileFollowers.js b/Network/Queries/ProfileFollowers.js index 915f65c1a..371bfde95 100644 --- a/Network/Queries/ProfileFollowers.js +++ b/Network/Queries/ProfileFollowers.js @@ -10,10 +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' @@ -24,75 +20,9 @@ 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) - } - 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) } diff --git a/Network/Queries/ProfileFollowing.js b/Network/Queries/ProfileFollowing.js index 8c0336190..09c6d29d7 100644 --- a/Network/Queries/ProfileFollowing.js +++ b/Network/Queries/ProfileFollowing.js @@ -10,10 +10,6 @@ exports.newProfileFollowing = function newProfileFollowing() { 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' @@ -24,75 +20,9 @@ exports.newProfileFollowing = function newProfileFollowing() { } function initialize(queryReceived) { - /* - 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.') - } - } - /* - 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) } diff --git a/Network/Queries/ProfilePosts.js b/Network/Queries/ProfilePosts.js index 60e83d135..02e8fcfe0 100644 --- a/Network/Queries/ProfilePosts.js +++ b/Network/Queries/ProfilePosts.js @@ -14,10 +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' @@ -28,76 +24,9 @@ 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) - } - - 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() { diff --git a/Network/SocialGraphNetwokNode.js b/Network/SocialGraphNetwokNode.js index c1611edbe..7073ba1a9 100644 --- a/Network/SocialGraphNetwokNode.js +++ b/Network/SocialGraphNetwokNode.js @@ -26,6 +26,9 @@ global.NT = { //QUERY_PROFILE_FOLLOWING: require('./Queries/ProfileFollowing.js'), //QUERY_POST_REPLIES: require('./Queries/ProfileReplies.js'), QUERY_EVENTS: require('./Queries/Events.js') + }, + utilities: { + queriesValidations: require('./Utilities/QueriesValidations.js').newProfileQueries() } } diff --git a/Network/Utilities/QueriesValidations.js b/Network/Utilities/QueriesValidations.js new file mode 100644 index 000000000..ba0934ec9 --- /dev/null +++ b/Network/Utilities/QueriesValidations.js @@ -0,0 +1,104 @@ +exports.newProfileFollowers = function newProfileFollowers() { + + let thisObject = { + profilesValidations: profilesValidations, + postValidations: postValidations, + arrayValidations: arrayValidations + } + + 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 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 === 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 + + } +} \ No newline at end of file From 390115d789b7ee37525d3ee2d38f20b343af8845 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 29 Aug 2021 17:44:46 +0200 Subject: [PATCH 8/9] Global Contants Implemented --- Network/Queries/Events.js | 21 +++++++-------------- Network/Queries/PostReplies.js | 7 ++----- Network/Queries/ProfileFollowers.js | 7 ++----- Network/Queries/ProfileFollowing.js | 7 ++----- Network/Queries/ProfilePosts.js | 7 ++----- Network/SocialGraphNetwokNode.js | 14 +++++++++++++- Network/Utilities/QueriesValidations.js | 17 +++++------------ 7 files changed, 33 insertions(+), 47 deletions(-) diff --git a/Network/Queries/Events.js b/Network/Queries/Events.js index ee80312c7..87b85f484 100644 --- a/Network/Queries/Events.js +++ b/Network/Queries/Events.js @@ -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 } diff --git a/Network/Queries/PostReplies.js b/Network/Queries/PostReplies.js index 6eb79e96c..41a4f06a9 100644 --- a/Network/Queries/PostReplies.js +++ b/Network/Queries/PostReplies.js @@ -15,9 +15,6 @@ exports.newPostReplies = function newPostReplies() { finalize: finalize } - const DIRECTION_FUTURE = 'Future' - const DIRECTION_PAST = 'Past' - return thisObject function finalize() { @@ -39,7 +36,7 @@ exports.newPostReplies = function newPostReplies() { 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 arrayItem = array[i] if (post === undefined) { break } @@ -47,7 +44,7 @@ exports.newPostReplies = function newPostReplies() { } break } - case DIRECTION_PAST: { + case NT.globals.constants.queries.DIRECTION_PAST: { for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) { let arrayItem = array[i] if (post === undefined) { break } diff --git a/Network/Queries/ProfileFollowers.js b/Network/Queries/ProfileFollowers.js index 371bfde95..3fc0a3a9d 100644 --- a/Network/Queries/ProfileFollowers.js +++ b/Network/Queries/ProfileFollowers.js @@ -10,9 +10,6 @@ exports.newProfileFollowers = function newProfileFollowers() { finalize: finalize } - const DIRECTION_FUTURE = 'Future' - const DIRECTION_PAST = 'Past' - return thisObject function finalize() { @@ -32,7 +29,7 @@ exports.newProfileFollowers = function newProfileFollowers() { 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 = array[i] if (arrayItem === undefined) { break } @@ -40,7 +37,7 @@ exports.newProfileFollowers = function newProfileFollowers() { } break } - case DIRECTION_PAST: { + 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 } diff --git a/Network/Queries/ProfileFollowing.js b/Network/Queries/ProfileFollowing.js index 09c6d29d7..4fea1534d 100644 --- a/Network/Queries/ProfileFollowing.js +++ b/Network/Queries/ProfileFollowing.js @@ -10,9 +10,6 @@ exports.newProfileFollowing = function newProfileFollowing() { finalize: finalize } - const DIRECTION_FUTURE = 'Future' - const DIRECTION_PAST = 'Past' - return thisObject function finalize() { @@ -32,7 +29,7 @@ exports.newProfileFollowing = function newProfileFollowing() { let array = Array.from(thisObject.profile.following) 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 = array[i] if (arrayItem === undefined) { break } @@ -40,7 +37,7 @@ exports.newProfileFollowing = function newProfileFollowing() { } break } - case DIRECTION_PAST: { + 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 } diff --git a/Network/Queries/ProfilePosts.js b/Network/Queries/ProfilePosts.js index 02e8fcfe0..bbeded5d4 100644 --- a/Network/Queries/ProfilePosts.js +++ b/Network/Queries/ProfilePosts.js @@ -14,9 +14,6 @@ exports.newProfilePosts = function newProfilePosts() { finalize: finalize } - const DIRECTION_FUTURE = 'Future' - const DIRECTION_PAST = 'Past' - return thisObject function finalize() { @@ -35,7 +32,7 @@ exports.newProfilePosts = function newProfilePosts() { 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 = array[i] if (arrayItem === undefined) { break } @@ -43,7 +40,7 @@ exports.newProfilePosts = function newProfilePosts() { } break } - case DIRECTION_PAST: { + 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 } diff --git a/Network/SocialGraphNetwokNode.js b/Network/SocialGraphNetwokNode.js index 7073ba1a9..3b3de0575 100644 --- a/Network/SocialGraphNetwokNode.js +++ b/Network/SocialGraphNetwokNode.js @@ -28,7 +28,19 @@ global.NT = { QUERY_EVENTS: require('./Queries/Events.js') }, utilities: { - queriesValidations: require('./Utilities/QueriesValidations.js').newProfileQueries() + 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' + } + } } } diff --git a/Network/Utilities/QueriesValidations.js b/Network/Utilities/QueriesValidations.js index ba0934ec9..618c1759b 100644 --- a/Network/Utilities/QueriesValidations.js +++ b/Network/Utilities/QueriesValidations.js @@ -6,13 +6,6 @@ exports.newProfileFollowers = function newProfileFollowers() { arrayValidations: arrayValidations } - 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 profilesValidations(queryReceived, thisObject) { @@ -56,11 +49,11 @@ exports.newProfileFollowers = function newProfileFollowers() { throw ('Initial Index Undefined.') } - if (queryReceived.initialIndex === INITIAL_POST_INDEX_LAST) { + if (queryReceived.initialIndex === NT.globals.constants.queries.INITIAL_INDEX_LAST) { queryReceived.initialIndex = thisObject.profile.posts.length - 1 } - if (queryReceived.initialIndex === INITIAL_POST_INDEX_FIRST) { + if (queryReceived.initialIndex === NT.globals.constants.queries.INITIAL_INDEX_FIRST) { queryReceived.initialIndex = 0 } @@ -80,11 +73,11 @@ exports.newProfileFollowers = function newProfileFollowers() { 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.') } /* @@ -94,7 +87,7 @@ exports.newProfileFollowers = function newProfileFollowers() { 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.') } From 06b5b9956c44cbfe838ae94425d0c7061804f7a9 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 29 Aug 2021 17:45:53 +0200 Subject: [PATCH 9/9] Cleaning --- Network/SocialGraphNetwokNode.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/Network/SocialGraphNetwokNode.js b/Network/SocialGraphNetwokNode.js index 3b3de0575..db8ae95c4 100644 --- a/Network/SocialGraphNetwokNode.js +++ b/Network/SocialGraphNetwokNode.js @@ -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,8 +22,8 @@ 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: { @@ -44,10 +43,3 @@ global.NT = { } } -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)) \ No newline at end of file