From 4aa11efddfa31ad357cf51604ae92468b3e2d74b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 29 Aug 2021 10:35:41 +0200 Subject: [PATCH] Post Re Implemented --- Network/Queries/Events.js | 7 +--- Network/Queries/PostReplies.js | 7 +--- Network/Queries/ProfileFollowers.js | 7 +--- Network/Queries/ProfilePosts.js | 7 +--- Network/botProfile.js | 13 +++++- Network/clientsInterface.js | 1 + Network/event.js | 5 ++- Network/post.js | 62 +++++++++++++++-------------- Network/userProfile.js | 14 ++++--- 9 files changed, 60 insertions(+), 63 deletions(-) diff --git a/Network/Queries/Events.js b/Network/Queries/Events.js index b234d316a..ee80312c7 100644 --- a/Network/Queries/Events.js +++ b/Network/Queries/Events.js @@ -232,13 +232,8 @@ exports.newEvents = function newEvents() { postType: post.postType, timestamp: post.timestamp, repliesCount: post.replies.length, - reactionsCount: [] + reactions: Array.from(post.reactions) } - - for (let i = 0; i < post.reactionTypesCount; i++) { - postResponse.reactionsCount.push(post.reactionsCount.get(i)) - } - return postResponse } } diff --git a/Network/Queries/PostReplies.js b/Network/Queries/PostReplies.js index 788af16b4..4661d692e 100644 --- a/Network/Queries/PostReplies.js +++ b/Network/Queries/PostReplies.js @@ -116,13 +116,8 @@ exports.newPostReplies = function newPostReplies() { postType: post.postType, timestamp: post.timestamp, repliesCount: post.replies.length, - reactionsCount: [] + reactions: Array.from(post.reactions) } - - for (let i = 0; i < post.reactionTypesCount; i++) { - postResponse.reactionsCount.push(post.reactionsCount.get(i)) - } - response.push(postResponse) } } diff --git a/Network/Queries/ProfileFollowers.js b/Network/Queries/ProfileFollowers.js index bf3e14b98..829a5f212 100644 --- a/Network/Queries/ProfileFollowers.js +++ b/Network/Queries/ProfileFollowers.js @@ -129,13 +129,8 @@ exports.newProfileFollowers = function newProfileFollowers() { postType: post.postType, timestamp: post.timestamp, repliesCount: post.replies.length, - reactionsCount: [] + reactions: Array.from(post.reactions) } - - for (let i = 0; i < post.reactionTypesCount; i++) { - postResponse.reactionsCount.push(post.reactionsCount.get(i)) - } - response.push(postResponse) } } diff --git a/Network/Queries/ProfilePosts.js b/Network/Queries/ProfilePosts.js index 3854d476e..b24381946 100644 --- a/Network/Queries/ProfilePosts.js +++ b/Network/Queries/ProfilePosts.js @@ -129,13 +129,8 @@ exports.newProfilePosts = function newProfilePosts() { postType: post.postType, timestamp: post.timestamp, repliesCount: post.replies.length, - reactionsCount: [] + reactions: Array.from(post.reactions) } - - for (let i = 0; i < post.reactionTypesCount; i++) { - postResponse.reactionsCount.push(post.reactionsCount.get(i)) - } - response.push(postResponse) } } diff --git a/Network/botProfile.js b/Network/botProfile.js index 1761781f7..dd28512a4 100644 --- a/Network/botProfile.js +++ b/Network/botProfile.js @@ -7,7 +7,7 @@ exports.newBotProfile = function newBotProfile() { /* Bot Unitque Properties */ botAsset: undefined, botExchange: undefined, - enabled: undefined, + botEnabled: undefined, /* Maps */ following: undefined, followers: undefined, @@ -39,7 +39,16 @@ exports.newBotProfile = function newBotProfile() { } - function initialize() { + function initialize( + botProfileId, + botAsset, + botExchange, + botEnabled + ) { + thisObject.botProfileId = botProfileId + thisObject.botAsset = botAsset + thisObject.botExchange = botExchange + thisObject.botEnabled = botEnabled thisObject.following = new Map() thisObject.followers = new Map() diff --git a/Network/clientsInterface.js b/Network/clientsInterface.js index b7c34d125..66b4c0650 100644 --- a/Network/clientsInterface.js +++ b/Network/clientsInterface.js @@ -62,6 +62,7 @@ exports.newClientInterface = function newClientInterface() { "botId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", "botAsset": "BTC", "botExchange": "Binance", + "botEnabled": true, "initialIndex": 35, "amountRequested": 50, "direction": "Past" diff --git a/Network/event.js b/Network/event.js index 736ea183f..8b2869311 100644 --- a/Network/event.js +++ b/Network/event.js @@ -12,6 +12,7 @@ exports.newEvent = function newEvent() { botId: undefined, botAsset: undefined, botExchange: undefined, + botEnabled: undefined, initialize: initialize, finalize: finalize } @@ -78,6 +79,7 @@ exports.newEvent = function newEvent() { thisObject.botId = eventReceived.botId thisObject.botAsset = eventReceived.botAsset thisObject.botExchange = eventReceived.botExchange + thisObject.botEnabled = eventReceived.botEnabled /* Validate Emitter User Profile. */ @@ -292,7 +294,8 @@ exports.newEvent = function newEvent() { emitterUserProfile.addBot( thisObject.botId, thisObject.botAsset, - thisObject.botExchange + thisObject.botExchange, + thisObject.botEnabled ) break } diff --git a/Network/post.js b/Network/post.js index 9b35c95cb..133ef9da3 100644 --- a/Network/post.js +++ b/Network/post.js @@ -1,19 +1,24 @@ exports.newPost = function newPost() { let thisObject = { + /* Parents Ids */ emitterUserProfileId: undefined, targetUserProfileId: undefined, emitterBotProfileId: undefined, targetBotProfileId: undefined, + /* Unique Keys */ emitterPostHash: undefined, targetPostHash: undefined, + /* Post Unitque Properties */ postType: undefined, timestamp: undefined, + /* Maps */ replies: undefined, - reactionsCount: undefined, - reactionTypesCount: undefined, + reactions: undefined, + /* Reaction Functions */ addReaction: addReaction, removeReactions: removeReaction, + /* Framework Functions */ initialize: initialize, finalize: finalize } @@ -35,29 +40,20 @@ exports.newPost = function newPost() { REACTION_HUG: 6 } - thisObject.reactionTypesCount = 7 - - thisObject.reactionsCount = new Map() - thisObject.reactionsCount.set(REACTION_TYPES.REACTION_LIKE, 0) - thisObject.reactionsCount.set(REACTION_TYPES.REACTION_LOVE, 0) - thisObject.reactionsCount.set(REACTION_TYPES.REACTION_HAHA, 0) - thisObject.reactionsCount.set(REACTION_TYPES.REACTION_WOW, 0) - thisObject.reactionsCount.set(REACTION_TYPES.REACTION_SAD, 0) - thisObject.reactionsCount.set(REACTION_TYPES.REACTION_ANGRY, 0) - thisObject.reactionsCount.set(REACTION_TYPES.REACTION_HUG, 0) + thisObject.reactions = new Map() + thisObject.reactions.set(REACTION_TYPES.REACTION_LIKE, 0) + thisObject.reactions.set(REACTION_TYPES.REACTION_LOVE, 0) + thisObject.reactions.set(REACTION_TYPES.REACTION_HAHA, 0) + thisObject.reactions.set(REACTION_TYPES.REACTION_WOW, 0) + thisObject.reactions.set(REACTION_TYPES.REACTION_SAD, 0) + thisObject.reactions.set(REACTION_TYPES.REACTION_ANGRY, 0) + thisObject.reactions.set(REACTION_TYPES.REACTION_HUG, 0) return thisObject function finalize() { - thisObject.emitterUserProfileId = undefined - thisObject.targetUserProfileId = undefined - thisObject.emitterBotProfileId = undefined - thisObject.targetBotProfileId = undefined - thisObject.emitterPostHash = undefined - thisObject.targetPostHash = undefined - thisObject.postType = undefined - thisObject.timestamp = undefined thisObject.replies = undefined + thisObject.reactions = undefined } function initialize( @@ -79,8 +75,6 @@ exports.newPost = function newPost() { thisObject.targetPostHash = targetPostHash thisObject.postType = postType thisObject.timestamp = timestamp - - thisObject.replies = [] /* Let's find the Target Post */ @@ -89,9 +83,17 @@ exports.newPost = function newPost() { if ( thisObject.postType === POST_TYPES.REPLY_TO_POST || thisObject.postType === POST_TYPES.REPOST_ || - thisObject.postType === POST_TYPES.QUOTE_REPOST_ + thisObject.postType === POST_TYPES.QUOTE_REPOST_ ) { - targetPost = NT.memory.maps.POSTS.get(thisObject.targetPostHash) + /* + Validate Target User Profile. + */ + let targetUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(thisObject.targetUserProfileId) + if (targetUserProfile === undefined) { + throw ('Target User Profile Not Found.') + } + + targetPost = targetUserProfile.posts.get(thisObject.targetPostHash) if (targetPost === undefined) { throw ('Target Post Not Found.') @@ -101,29 +103,29 @@ exports.newPost = function newPost() { Let's add this post to the replies of the Target Post */ if ( - thisObject.postType === POST_TYPES.REPLY_TO_POST + thisObject.postType === POST_TYPES.REPLY_TO_POST ) { - targetPost.replies.push(thisObject) + targetPost.replies.set(thisObject.targetPostHash, thisObject.targetPostHash) } } function addReaction(reactionType) { - let reactionCount = thisObject.reactionsCount.get(reactionType) + let reactionCount = thisObject.reactions.get(reactionType) if (reactionCount === undefined) { throw ('Reaction Type Not Supported.') } - thisObject.reactionsCount.set(reactionType, reactionsCount + 1) + thisObject.reactions.set(reactionType, reactionCount + 1) } function removeReaction(reactionType) { - let reactionCount = thisObject.reactionsCount.get(reactionType) + let reactionCount = thisObject.reactions.get(reactionType) if (reactionCount === undefined) { throw ('Reaction Type Not Supported.') } - thisObject.reactionsCount.set(reactionType, reactionsCount - 1) + thisObject.reactions.set(reactionType, reactionCount - 1) } } \ No newline at end of file diff --git a/Network/userProfile.js b/Network/userProfile.js index f1a2158f5..82f19bc0c 100644 --- a/Network/userProfile.js +++ b/Network/userProfile.js @@ -135,7 +135,8 @@ exports.newUserProfile = function newUserProfile() { function addBot( botProfileId, botAsset, - botExchange + botExchange, + botEnabled ) { let bot = thisObject.bots.get(botProfileId) if (bot !== undefined) { @@ -145,7 +146,8 @@ exports.newUserProfile = function newUserProfile() { bot.initialize( botProfileId, botAsset, - botExchange + botExchange, + botEnabled ) thisObject.bots.set(botProfileId, bot) } @@ -170,10 +172,10 @@ exports.newUserProfile = function newUserProfile() { if (bot === undefined) { throw ('Bot Does Not Exist.') } - if (bot.enabled === true) { + if (bot.botEnabled === true) { throw ('Bot Already Enabled.') } - bot.enabled = true + bot.botEnabled = true } function disableBot( @@ -183,9 +185,9 @@ exports.newUserProfile = function newUserProfile() { if (bot === undefined) { throw ('Bot Does Not Exist.') } - if (bot.enabled === false) { + if (bot.botEnabled === false) { throw ('Bot Already Disabled.') } - bot.enabled = false + bot.botEnabled = false } } \ No newline at end of file