From 658bfd2b0d92eab24655f53aa60decd37fedce43 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 27 Aug 2021 10:52:09 +0200 Subject: [PATCH 1/8] Query Post Replies Implemented --- Network/Queries/PostReplies.js | 127 ++++++++++++++++++++++++++++++++ Network/Queries/ProfilePosts.js | 49 +++++++----- Network/clientsInterface.js | 6 +- 3 files changed, 161 insertions(+), 21 deletions(-) create mode 100644 Network/Queries/PostReplies.js diff --git a/Network/Queries/PostReplies.js b/Network/Queries/PostReplies.js new file mode 100644 index 000000000..776c7ba22 --- /dev/null +++ b/Network/Queries/PostReplies.js @@ -0,0 +1,127 @@ +exports.newPostReplies = function newPostReplies() { + + let thisObject = { + post: undefined, + initialReplyIndex: undefined, + amountRequested: undefined, + direction: undefined, + execute: execute, + initialize: initialize, + 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() { + + } + + function initialize(queryReceived) { + /* + Validate Post + */ + thisObject.post = NT.memory.POSTS.get(queryReceived.targetPostHash) + + if (thisObject.post === undefined) { + throw ('Target Post Not Found.') + } + /* + Validate Initial Reply Index + */ + if (queryReceived.initialReplyIndex === undefined) { + throw ('Initial Reply Index Undefined.') + } + + if (queryReceived.initialReplyIndex === INITIAL_REPLY_INDEX_LAST) { + queryReceived.initialReplyIndex = thisObject.poat.replies.length - 1 + } + + if (queryReceived.initialReplyIndex === INITIAL_REPLY_INDEX_FIRST) { + queryReceived.initialReplyIndex = 0 + } + + if (isNaN(queryReceived.initialReplyIndex) === true) { + throw ('Initial Reply Is Not a Number.') + } + + thisObject.initialReplyIndex = queryReceived.initialReplyIndex + /* + 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 = [] + switch (thisObject.direction) { + case DIRECTION_FUTURE: { + for (let i = thisObject.initialReplyIndex; i < thisObject.initialReplyIndex + thisObject.amountRequested; i++) { + let post = thisObject.post.replies[i] + if (post === undefined) { break } + addPostToResponse(post) + } + } + case DIRECTION_PAST: { + for (let i = thisObject.initialReplyIndex; i > thisObject.initialReplyIndex - thisObject.amountRequested; i--) { + let post = thisObject.post.replies[i] + if (post === undefined) { break } + addPostToResponse(post) + } + } + } + return response + + function addPostToResponse(post) { + let postResponse = { + "emitterPostHash": post.emitterPostHash, + "targetPostHash": post.targetPostHash, + "postType": post.postType, + "userProfile": post.userProfile.userProfieId, + "timestamp": post.timestamp, + "repliesCount": post.replies.length, + "targetPostHash": post.targetPost.emitterPostHash, + "reactionsCount": [] + } + + for (let i = 0; i < post.reactionTypesCount; i++) { + postResponse.reactionsCount.push(post.reactionsCount.get(i)) + } + + response.push(postResponse) + } + } +} \ No newline at end of file diff --git a/Network/Queries/ProfilePosts.js b/Network/Queries/ProfilePosts.js index e80302005..4558f663e 100644 --- a/Network/Queries/ProfilePosts.js +++ b/Network/Queries/ProfilePosts.js @@ -44,7 +44,7 @@ exports.newProfilePosts = function newProfilePosts() { } if (queryReceived.initialPostIndex === INITIAL_POST_INDEX_LAST) { - queryReceived.initialPostIndex = thisObject.posts.length - 1 + queryReceived.initialPostIndex = thisObject.profile.posts.length - 1 } if (queryReceived.initialPostIndex === INITIAL_POST_INDEX_FIRST) { @@ -75,7 +75,7 @@ exports.newProfilePosts = function newProfilePosts() { throw ('Amount Requested Above Max.') } /* - Validate Amount Requested + Validate Direction */ if (queryReceived.direction === undefined) { throw ('Direction Undefined.') @@ -90,33 +90,42 @@ exports.newProfilePosts = function newProfilePosts() { } function execute() { - let response = [] switch (thisObject.direction) { case DIRECTION_FUTURE: { for (let i = thisObject.initialPostIndex; i < thisObject.initialPostIndex + thisObject.amountRequested; i++) { let post = thisObject.profile.posts[i] if (post === undefined) { break } - - let postResponse = { - "emitterPostHash": post.emitterPostHash, - "targetPostHash": post.targetPostHash, - "postType": post.postType, - "userProfile": post.userProfile.userProfieId, - "timestamp": post.timestamp, - "repliesCount": post.replies.length, - "targetPostHash": post.targetPost.emitterPostHash, - "reactionsCount": [] - } - - for (let i = 0; i < post.reactionTypesCount; i++) { - postResponse.reactionsCount.push(post.reactionsCount.get(i)) - } - - response.push(postResponse) + addPostToResponse(post) + } + } + case DIRECTION_PAST: { + for (let i = thisObject.initialPostIndex; i > thisObject.initialPostIndex - thisObject.amountRequested; i--) { + let post = thisObject.profile.posts[i] + if (post === undefined) { break } + addPostToResponse(post) } } } return response + + function addPostToResponse(post) { + let postResponse = { + "emitterPostHash": post.emitterPostHash, + "targetPostHash": post.targetPostHash, + "postType": post.postType, + "userProfile": post.userProfile.userProfieId, + "timestamp": post.timestamp, + "repliesCount": post.replies.length, + "targetPostHash": post.targetPost.emitterPostHash, + "reactionsCount": [] + } + + for (let i = 0; i < post.reactionTypesCount; i++) { + postResponse.reactionsCount.push(post.reactionsCount.get(i)) + } + + response.push(postResponse) + } } } \ No newline at end of file diff --git a/Network/clientsInterface.js b/Network/clientsInterface.js index 4f25230c6..9b250073a 100644 --- a/Network/clientsInterface.js +++ b/Network/clientsInterface.js @@ -61,7 +61,11 @@ exports.newClientInterface = function newClientInterface() { "timestamp": 124234234234, "botId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", "botAsset": "BTC", - "botExchange": "Binance" + "botExchange": "Binance", + "initialReplyIndex": 25, + "initialPostIndex": 35, + "amountRequested": 50, + "direction": "Past" } */ From 104499ab57f45d8e208b0236b982399f6add5aaa Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 27 Aug 2021 11:18:18 +0200 Subject: [PATCH 2/8] memory reorganized into maps and arrays --- Network/NetwokNode.js | 20 ++++++++++++-------- Network/Queries/PostReplies.js | 2 +- Network/Queries/ProfilePosts.js | 10 +++++----- Network/Queries/ProfileStats.js | 6 +++--- Network/Query.js | 6 +++--- Network/clientsInterface.js | 4 ++-- Network/event.js | 8 ++++---- Network/post.js | 2 +- Network/userProfile.js | 28 ++++++++++++++-------------- 9 files changed, 45 insertions(+), 41 deletions(-) diff --git a/Network/NetwokNode.js b/Network/NetwokNode.js index 20a2d0fef..c2b1b55a5 100644 --- a/Network/NetwokNode.js +++ b/Network/NetwokNode.js @@ -2,13 +2,17 @@ global.NT = { memory: { - 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. - TIMELINE: [], // A time ordered list of Posts and Trades. - NETWORK_CLIENTS: [], // These are the Network Clients connected to this Network Node. - NETWORK_PEERS: [], // These are the Network Peers connected to this Network Node. + 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: { + EVENTS: [], // A time ordered list of events. + NETWORK_CLIENTS: [], // These are the Network Clients connected to this Network Node ordered by Ranking. + NETWORK_PEERS: [], // These are the Network Peers connected to this Network Node ordered by Ranking. + } }, modules: { USER_PROFILE: require('./UserProfile.js'), @@ -19,6 +23,6 @@ global.NT = { QUERY_PROFILE_STATS: require('./Queries/ProfileStats.js'), QUERY_PROFILE_POSTS: require('./Queries/ProfilePosts.js'), QUERY_POST_REPLIES: require('./Queries/ProfileReplies.js'), - QUERY_TIMELINE_CHUNK: require('./Queries/TimelineChunk.js') + QUERY_EVENTS: require('./Queries/Events.js') } } \ No newline at end of file diff --git a/Network/Queries/PostReplies.js b/Network/Queries/PostReplies.js index 776c7ba22..150d4022e 100644 --- a/Network/Queries/PostReplies.js +++ b/Network/Queries/PostReplies.js @@ -27,7 +27,7 @@ exports.newPostReplies = function newPostReplies() { /* Validate Post */ - thisObject.post = NT.memory.POSTS.get(queryReceived.targetPostHash) + thisObject.post = NT.memory.maps.POSTS.get(queryReceived.targetPostHash) if (thisObject.post === undefined) { throw ('Target Post Not Found.') diff --git a/Network/Queries/ProfilePosts.js b/Network/Queries/ProfilePosts.js index 4558f663e..76fe86b68 100644 --- a/Network/Queries/ProfilePosts.js +++ b/Network/Queries/ProfilePosts.js @@ -28,9 +28,9 @@ exports.newProfilePosts = function newProfilePosts() { Validate User Profile */ if (queryReceived.targetUserProfileId !== undefined) { - thisObject.profile = NT.memory.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) + thisObject.profile = NT.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) } else { - thisObject.profile = NT.memory.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle) + thisObject.profile = NT.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle) } if (thisObject.profile === undefined) { @@ -44,7 +44,7 @@ exports.newProfilePosts = function newProfilePosts() { } if (queryReceived.initialPostIndex === INITIAL_POST_INDEX_LAST) { - queryReceived.initialPostIndex = thisObject.profile.posts.length - 1 + queryReceived.initialPostIndex = thisObject.profile.maps.POSTS.length - 1 } if (queryReceived.initialPostIndex === INITIAL_POST_INDEX_FIRST) { @@ -94,14 +94,14 @@ exports.newProfilePosts = function newProfilePosts() { switch (thisObject.direction) { case DIRECTION_FUTURE: { for (let i = thisObject.initialPostIndex; i < thisObject.initialPostIndex + thisObject.amountRequested; i++) { - let post = thisObject.profile.posts[i] + let post = thisObject.profile.maps.POSTS[i] if (post === undefined) { break } addPostToResponse(post) } } case DIRECTION_PAST: { for (let i = thisObject.initialPostIndex; i > thisObject.initialPostIndex - thisObject.amountRequested; i--) { - let post = thisObject.profile.posts[i] + let post = thisObject.profile.maps.POSTS[i] if (post === undefined) { break } addPostToResponse(post) } diff --git a/Network/Queries/ProfileStats.js b/Network/Queries/ProfileStats.js index f4bb73e19..69615657f 100644 --- a/Network/Queries/ProfileStats.js +++ b/Network/Queries/ProfileStats.js @@ -18,9 +18,9 @@ exports.newProfileStats = function newProfileStats() { Validate User Profile */ if (queryReceived.targetUserProfileId !== undefined) { - thisObject.profile = NT.memory.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) + thisObject.profile = NT.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) } else { - thisObject.profile = NT.memory.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle) + thisObject.profile = NT.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle) } if (thisObject.profile === undefined) { @@ -42,7 +42,7 @@ exports.newProfileStats = function newProfileStats() { "tradePostsFollowersCount": thisObject.profile.tradePostsFollowersCount, "emitterEventsCount": thisObject.profile.emitterEventsCount, "targetEventsCount": thisObject.profile.targetEventsCount, - "postsCount": thisObject.profile.postsCount, + "postsCount": thisObject.profile.maps.POSTSCount, "botsCount": thisObject.profile.botsCount } } diff --git a/Network/Query.js b/Network/Query.js index aa852b0e6..3c5d24dfd 100644 --- a/Network/Query.js +++ b/Network/Query.js @@ -13,7 +13,7 @@ exports.newQuery = function newQuery() { PROFILE_STATS: 0, PROFILE_POSTS: 1, POST_REPLIES: 2, - TIMELINE_CHUNK: 3 + EVENTS: 3 } @@ -48,8 +48,8 @@ exports.newQuery = function newQuery() { break } - case QUERY_TYPES.TIMELINE_CHUNK: { - thisObject.query = NT.modules.QUERY_TIMELINE_CHUNK.newTimelineChunk() + case QUERY_TYPES.maps.EVENTS: { + thisObject.query = NT.modules.QUERY_EVENTS.newEvents() query.initialize(queryReceived) break } diff --git a/Network/clientsInterface.js b/Network/clientsInterface.js index 9b250073a..27ae8b792 100644 --- a/Network/clientsInterface.js +++ b/Network/clientsInterface.js @@ -36,13 +36,13 @@ exports.newClientInterface = function newClientInterface() { */ let eventReceived = JSON.parse(eventMessage) - if (NT.memory.EVENTS.get(eventReceived.eventId) !== undefined) { + if (NT.memory.maps.EVENTS.get(eventReceived.eventId) !== undefined) { throw ('Event Already Exists.') } let event = NT.modules.EVENT.newEvent() event.initialize(eventReceived) - NT.memory.EVENTS.set(eventReceived.eventId, event) + NT.memory.maps.EVENTS.set(eventReceived.eventId, event) } function queryReceived(queryMessage) { diff --git a/Network/event.js b/Network/event.js index 50988a5c7..8c0ff314e 100644 --- a/Network/event.js +++ b/Network/event.js @@ -58,13 +58,13 @@ exports.newEvent = function newEvent() { function initialize(eventReceived) { - thisObject.emitterUserProfile = NT.memory.USER_PROFILES_BY_ID.get(eventReceived.emitterUserProfileId) + thisObject.emitterUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(eventReceived.emitterUserProfileId) if (thisObject.emitterUserProfile === undefined) { throw ('Emitter User Profile Not Found.') } thisObject.emitterUserProfile.emitterEventsCount++ - thisObject.targetUserProfile = NT.memory.USER_PROFILES_BY_ID.get(eventReceived.targetUserProfileId) + thisObject.targetUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(eventReceived.targetUserProfileId) if (thisObject.targetUserProfile === undefined) { /* We thow an exception when it does not have a target user profile and is required*/ if ( @@ -172,7 +172,7 @@ exports.newEvent = function newEvent() { eventReceived.eventType === EVENT_TYPES.ADD_REACTION_ANGRY || eventReceived.eventType === EVENT_TYPES.ADD_REACTION_HUG ) { - let targetPost = NT.memory.POSTS.get(eventReceived.targetPostHash) + let targetPost = NT.memory.maps.POSTS.get(eventReceived.targetPostHash) if (targetPost === undefined) { throw ('Target Post Not Found') @@ -190,7 +190,7 @@ exports.newEvent = function newEvent() { eventReceived.eventType === EVENT_TYPES.REMOVE_REACTION_ANGRY || eventReceived.eventType === EVENT_TYPES.REMOVE_REACTION_HUG ) { - let targetPost = NT.memory.POSTS.get(eventReceived.targetPostHash) + let targetPost = NT.memory.maps.POSTS.get(eventReceived.targetPostHash) if (targetPost === undefined) { throw ('Target Post Not Found') diff --git a/Network/post.js b/Network/post.js index 97509e6e3..43a6edb9d 100644 --- a/Network/post.js +++ b/Network/post.js @@ -86,7 +86,7 @@ exports.newPost = function newPost() { event.eventType === POST_TYPES.RE_POST_TRADE || event.eventType === POST_TYPES.QUOTE_REPOST_TRADE ) { - thisObject.targetPost = NT.memory.POSTS.get(thisObject.targetPostHash) + thisObject.targetPost = NT.memory.maps.POSTS.get(thisObject.targetPostHash) if (thisObject.targetPost === undefined) { throw ('Target Post Not Found.') diff --git a/Network/userProfile.js b/Network/userProfile.js index d1f2863e1..b4de58d1e 100644 --- a/Network/userProfile.js +++ b/Network/userProfile.js @@ -46,7 +46,7 @@ exports.newUserProfile = function newUserProfile() { thisObject.tradePostsFollowing = undefined thisObject.tradePostsFollowers = undefined - thisObject.posts = undefined + thisObject.maps.POSTS = undefined thisObject.bots = undefined } @@ -64,10 +64,10 @@ exports.newUserProfile = function newUserProfile() { thisObject.tradePostsFollowersCount = 0 thisObject.emitterEventsCount = 0 thisObject.targetEventsCount = 0 - thisObject.postsCount = 0 + thisObject.maps.POSTSCount = 0 thisObject.botsCount = 0 - thisObject.posts = [] + thisObject.maps.POSTS = [] thisObject.bots = undefined } @@ -78,7 +78,7 @@ exports.newUserProfile = function newUserProfile() { userProfile, timestamp ) { - if (NT.memory.POSTS.get(emitterPostHash) !== undefined) { + if (NT.memory.maps.POSTS.get(emitterPostHash) !== undefined) { throw ('Post Already Exists.') } @@ -91,29 +91,29 @@ exports.newUserProfile = function newUserProfile() { timestamp ) - thisObject.posts.push(post) - NT.memory.POSTS.set(emitterPostHash, post) - thisObject.postsCount++ + thisObject.maps.POSTS.push(post) + NT.memory.maps.POSTS.set(emitterPostHash, post) + thisObject.maps.POSTSCount++ } function removePost( emitterPostHash ) { - if (NT.memory.POSTS.get(emitterPostHash) === undefined) { + if (NT.memory.maps.POSTS.get(emitterPostHash) === undefined) { throw ('Post Does Not Exist.') } - let post = thisObject.posts.get(emitterPostHash) + let post = thisObject.maps.POSTS.get(emitterPostHash) post.finalize() - for (let i = thisObject.posts.length - 1; i >= 0; i-- { - if (thisObject.posts[i].emitterPostHash === emitterPostHash) { - thisObject.posts.splice(i, 1) + for (let i = thisObject.maps.POSTS.length - 1; i >= 0; i--) { + if (thisObject.maps.POSTS[i].emitterPostHash === emitterPostHash) { + thisObject.maps.POSTS.splice(i, 1) break } } - NT.memory.POSTS.delete(emitterPostHash) - thisObject.postsCount-- + NT.memory.maps.POSTS.delete(emitterPostHash) + thisObject.maps.POSTSCount-- } function addMultiMediaPostsFollowing( From 777b57703a0d72be057d3b9f8002f567cdb0f5ed Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 27 Aug 2021 12:09:43 +0200 Subject: [PATCH 3/8] initialIndex simplified --- Network/Queries/Events.js | 131 ++++++++++++++++++++++++++++++++ Network/Queries/PostReplies.js | 26 +++---- Network/Queries/ProfilePosts.js | 26 +++---- Network/clientsInterface.js | 3 +- 4 files changed, 158 insertions(+), 28 deletions(-) create mode 100644 Network/Queries/Events.js diff --git a/Network/Queries/Events.js b/Network/Queries/Events.js new file mode 100644 index 000000000..f580190b3 --- /dev/null +++ b/Network/Queries/Events.js @@ -0,0 +1,131 @@ +exports.newEvents = function newEvents() { + + let thisObject = { + profile: undefined, + initialIndex: undefined, + amountRequested: undefined, + direction: undefined, + execute: execute, + initialize: initialize, + 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() { + thisObject.profile = undefined + } + + function initialize(queryReceived) { + /* + Validate User Profile + */ + if (queryReceived.emitterUserProfileId !== undefined) { + thisObject.profile = NT.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.emitterUserProfileId) + } else { + thisObject.profile = NT.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.emitterUserProfileHandle) + } + + if (thisObject.profile === undefined) { + throw ('Emitter User Profile Not Found.') + } + /* + Validate Initial Index + */ + if (queryReceived.initialIndex === undefined) { + throw ('Initial Index Undefined.') + } + + if (queryReceived.initialIndex === INITIAL_EVENT_INDEX_LAST) { + queryReceived.initialIndex = thisObject.profile.maps.POSTS.length - 1 + } + + if (queryReceived.initialIndex === INITIAL_EVENT_INDEX_FIRST) { + queryReceived.initialIndex = 0 + } + + if (isNaN(queryReceived.initialIndex) === true) { + throw ('Initial Event 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 = [] + switch (thisObject.direction) { + case DIRECTION_FUTURE: { + for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) { + let post = thisObject.profile.maps.POSTS[i] + if (post === undefined) { break } + addPostToResponse(post) + } + } + case DIRECTION_PAST: { + for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) { + let post = thisObject.profile.maps.POSTS[i] + if (post === undefined) { break } + addPostToResponse(post) + } + } + } + return response + + function addPostToResponse(post) { + let postResponse = { + "emitterPostHash": post.emitterPostHash, + "targetPostHash": post.targetPostHash, + "postType": post.postType, + "userProfile": post.userProfile.userProfieId, + "timestamp": post.timestamp, + "repliesCount": post.replies.length, + "targetPostHash": post.targetPost.emitterPostHash, + "reactionsCount": [] + } + + for (let i = 0; i < post.reactionTypesCount; i++) { + postResponse.reactionsCount.push(post.reactionsCount.get(i)) + } + + response.push(postResponse) + } + } +} \ No newline at end of file diff --git a/Network/Queries/PostReplies.js b/Network/Queries/PostReplies.js index 150d4022e..616b1cfd7 100644 --- a/Network/Queries/PostReplies.js +++ b/Network/Queries/PostReplies.js @@ -2,7 +2,7 @@ exports.newPostReplies = function newPostReplies() { let thisObject = { post: undefined, - initialReplyIndex: undefined, + initialIndex: undefined, amountRequested: undefined, direction: undefined, execute: execute, @@ -20,7 +20,7 @@ exports.newPostReplies = function newPostReplies() { return thisObject function finalize() { - + thisObject.post = undefined } function initialize(queryReceived) { @@ -33,25 +33,25 @@ exports.newPostReplies = function newPostReplies() { throw ('Target Post Not Found.') } /* - Validate Initial Reply Index + Validate Initial Index */ - if (queryReceived.initialReplyIndex === undefined) { - throw ('Initial Reply Index Undefined.') + if (queryReceived.initialIndex === undefined) { + throw ('Initial Index Undefined.') } - if (queryReceived.initialReplyIndex === INITIAL_REPLY_INDEX_LAST) { - queryReceived.initialReplyIndex = thisObject.poat.replies.length - 1 + if (queryReceived.initialIndex === INITIAL_REPLY_INDEX_LAST) { + queryReceived.initialIndex = thisObject.poat.replies.length - 1 } - if (queryReceived.initialReplyIndex === INITIAL_REPLY_INDEX_FIRST) { - queryReceived.initialReplyIndex = 0 + if (queryReceived.initialIndex === INITIAL_REPLY_INDEX_FIRST) { + queryReceived.initialIndex = 0 } - if (isNaN(queryReceived.initialReplyIndex) === true) { + if (isNaN(queryReceived.initialIndex) === true) { throw ('Initial Reply Is Not a Number.') } - thisObject.initialReplyIndex = queryReceived.initialReplyIndex + thisObject.initialIndex = queryReceived.initialIndex /* Validate Amount Requested */ @@ -89,14 +89,14 @@ exports.newPostReplies = function newPostReplies() { let response = [] switch (thisObject.direction) { case DIRECTION_FUTURE: { - for (let i = thisObject.initialReplyIndex; i < thisObject.initialReplyIndex + thisObject.amountRequested; i++) { + for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) { let post = thisObject.post.replies[i] if (post === undefined) { break } addPostToResponse(post) } } case DIRECTION_PAST: { - for (let i = thisObject.initialReplyIndex; i > thisObject.initialReplyIndex - thisObject.amountRequested; i--) { + for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) { let post = thisObject.post.replies[i] if (post === undefined) { break } addPostToResponse(post) diff --git a/Network/Queries/ProfilePosts.js b/Network/Queries/ProfilePosts.js index 76fe86b68..9b1fba963 100644 --- a/Network/Queries/ProfilePosts.js +++ b/Network/Queries/ProfilePosts.js @@ -2,7 +2,7 @@ exports.newProfilePosts = function newProfilePosts() { let thisObject = { profile: undefined, - initialPostIndex: undefined, + initialIndex: undefined, amountRequested: undefined, direction: undefined, execute: execute, @@ -20,7 +20,7 @@ exports.newProfilePosts = function newProfilePosts() { return thisObject function finalize() { - + thisObject.profile = undefined } function initialize(queryReceived) { @@ -37,25 +37,25 @@ exports.newProfilePosts = function newProfilePosts() { throw ('Target User Profile Not Found.') } /* - Validate Initial Post Index + Validate Initial Index */ - if (queryReceived.initialPostIndex === undefined) { - throw ('Initial Post Index Undefined.') + if (queryReceived.initialIndex === undefined) { + throw ('Initial Index Undefined.') } - if (queryReceived.initialPostIndex === INITIAL_POST_INDEX_LAST) { - queryReceived.initialPostIndex = thisObject.profile.maps.POSTS.length - 1 + if (queryReceived.initialIndex === INITIAL_POST_INDEX_LAST) { + queryReceived.initialIndex = thisObject.profile.maps.POSTS.length - 1 } - if (queryReceived.initialPostIndex === INITIAL_POST_INDEX_FIRST) { - queryReceived.initialPostIndex = 0 + if (queryReceived.initialIndex === INITIAL_POST_INDEX_FIRST) { + queryReceived.initialIndex = 0 } - if (isNaN(queryReceived.initialPostIndex) === true) { + if (isNaN(queryReceived.initialIndex) === true) { throw ('Initial Post Is Not a Number.') } - thisObject.initialPostIndex = queryReceived.initialPostIndex + thisObject.initialIndex = queryReceived.initialIndex /* Validate Amount Requested */ @@ -93,14 +93,14 @@ exports.newProfilePosts = function newProfilePosts() { let response = [] switch (thisObject.direction) { case DIRECTION_FUTURE: { - for (let i = thisObject.initialPostIndex; i < thisObject.initialPostIndex + thisObject.amountRequested; i++) { + for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) { let post = thisObject.profile.maps.POSTS[i] if (post === undefined) { break } addPostToResponse(post) } } case DIRECTION_PAST: { - for (let i = thisObject.initialPostIndex; i > thisObject.initialPostIndex - thisObject.amountRequested; i--) { + for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) { let post = thisObject.profile.maps.POSTS[i] if (post === undefined) { break } addPostToResponse(post) diff --git a/Network/clientsInterface.js b/Network/clientsInterface.js index 27ae8b792..b7c34d125 100644 --- a/Network/clientsInterface.js +++ b/Network/clientsInterface.js @@ -62,8 +62,7 @@ exports.newClientInterface = function newClientInterface() { "botId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", "botAsset": "BTC", "botExchange": "Binance", - "initialReplyIndex": 25, - "initialPostIndex": 35, + "initialIndex": 35, "amountRequested": 50, "direction": "Past" } From 96535a2dd4290d26cf39f55a588f53b34eef8269 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 27 Aug 2021 12:49:28 +0200 Subject: [PATCH 4/8] Event Module Fixed, withoout unnecesary references --- Network/Queries/Events.js | 52 ++++++++++------- Network/Queries/PostReplies.js | 22 ++++---- Network/Queries/ProfilePosts.js | 28 +++++----- Network/Queries/ProfileStats.js | 2 +- Network/event.js | 98 +++++++++++++++++++-------------- Network/userProfile.js | 18 +++--- 6 files changed, 124 insertions(+), 96 deletions(-) diff --git a/Network/Queries/Events.js b/Network/Queries/Events.js index f580190b3..0e5af2b39 100644 --- a/Network/Queries/Events.js +++ b/Network/Queries/Events.js @@ -44,7 +44,7 @@ exports.newEvents = function newEvents() { } if (queryReceived.initialIndex === INITIAL_EVENT_INDEX_LAST) { - queryReceived.initialIndex = thisObject.profile.maps.POSTS.length - 1 + queryReceived.initialIndex = thisObject.profile.posts.length - 1 } if (queryReceived.initialIndex === INITIAL_EVENT_INDEX_FIRST) { @@ -94,38 +94,52 @@ exports.newEvents = function newEvents() { switch (thisObject.direction) { case DIRECTION_FUTURE: { for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) { - let post = thisObject.profile.maps.POSTS[i] - if (post === undefined) { break } - addPostToResponse(post) + let event = NT.memory.arrays.EVENTS[i] + if (event === undefined) { break } + addToResponse(event) } } case DIRECTION_PAST: { for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) { - let post = thisObject.profile.maps.POSTS[i] - if (post === undefined) { break } - addPostToResponse(post) + let event = NT.memory.arrays.EVENTS[i] + if (event === undefined) { break } + addToResponse(event) } } } return response - function addPostToResponse(post) { - let postResponse = { - "emitterPostHash": post.emitterPostHash, - "targetPostHash": post.targetPostHash, - "postType": post.postType, - "userProfile": post.userProfile.userProfieId, - "timestamp": post.timestamp, - "repliesCount": post.replies.length, - "targetPostHash": post.targetPost.emitterPostHash, - "reactionsCount": [] + function addToResponse(event) { + let eventResponse = { + eventId: event.eventId, + eventType: event.eventType, + emitterUserProfileId: event.emitterUserProfileId, + targetUserProfileId: event.targetUserProfileId, + emitterPostHash: event.emitterPostHash, + targetPostHash: event.targetPostHash, + timestamp: event.timestamp, + botId: event.botId, + botAsset: event.botAsset, + botExchange: event.botExchange, + emitterUserProfile: { + + }, + targetUserProfile: { + + }, + emitterPost: { + + }, + targetPost: { + + } } for (let i = 0; i < post.reactionTypesCount; i++) { - postResponse.reactionsCount.push(post.reactionsCount.get(i)) + eventResponse.reactionsCount.push(post.reactionsCount.get(i)) } - response.push(postResponse) + response.push(eventResponse) } } } \ No newline at end of file diff --git a/Network/Queries/PostReplies.js b/Network/Queries/PostReplies.js index 616b1cfd7..ace183b99 100644 --- a/Network/Queries/PostReplies.js +++ b/Network/Queries/PostReplies.js @@ -92,29 +92,29 @@ exports.newPostReplies = function newPostReplies() { for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) { let post = thisObject.post.replies[i] if (post === undefined) { break } - addPostToResponse(post) + addToResponse(post) } } case DIRECTION_PAST: { for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) { let post = thisObject.post.replies[i] if (post === undefined) { break } - addPostToResponse(post) + addToResponse(post) } } } return response - function addPostToResponse(post) { + function addToResponse(post) { let postResponse = { - "emitterPostHash": post.emitterPostHash, - "targetPostHash": post.targetPostHash, - "postType": post.postType, - "userProfile": post.userProfile.userProfieId, - "timestamp": post.timestamp, - "repliesCount": post.replies.length, - "targetPostHash": post.targetPost.emitterPostHash, - "reactionsCount": [] + emitterPostHash: post.emitterPostHash, + targetPostHash: post.targetPostHash, + postType: post.postType, + userProfile: post.userProfile.userProfieId, + timestamp: post.timestamp, + repliesCount: post.replies.length, + targetPostHash: post.targetPost.emitterPostHash, + reactionsCount: [] } for (let i = 0; i < post.reactionTypesCount; i++) { diff --git a/Network/Queries/ProfilePosts.js b/Network/Queries/ProfilePosts.js index 9b1fba963..24d097ff2 100644 --- a/Network/Queries/ProfilePosts.js +++ b/Network/Queries/ProfilePosts.js @@ -44,7 +44,7 @@ exports.newProfilePosts = function newProfilePosts() { } if (queryReceived.initialIndex === INITIAL_POST_INDEX_LAST) { - queryReceived.initialIndex = thisObject.profile.maps.POSTS.length - 1 + queryReceived.initialIndex = thisObject.profile.posts.length - 1 } if (queryReceived.initialIndex === INITIAL_POST_INDEX_FIRST) { @@ -94,31 +94,31 @@ exports.newProfilePosts = function newProfilePosts() { switch (thisObject.direction) { case DIRECTION_FUTURE: { for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) { - let post = thisObject.profile.maps.POSTS[i] + let post = thisObject.profile.posts[i] if (post === undefined) { break } - addPostToResponse(post) + addToResponse(post) } } case DIRECTION_PAST: { for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) { - let post = thisObject.profile.maps.POSTS[i] + let post = thisObject.profile.posts[i] if (post === undefined) { break } - addPostToResponse(post) + addToResponse(post) } } } return response - function addPostToResponse(post) { + function addToResponse(post) { let postResponse = { - "emitterPostHash": post.emitterPostHash, - "targetPostHash": post.targetPostHash, - "postType": post.postType, - "userProfile": post.userProfile.userProfieId, - "timestamp": post.timestamp, - "repliesCount": post.replies.length, - "targetPostHash": post.targetPost.emitterPostHash, - "reactionsCount": [] + emitterPostHash: post.emitterPostHash, + targetPostHash: post.targetPostHash, + postType: post.postType, + userProfile: post.userProfile.userProfieId, + timestamp: post.timestamp, + repliesCount: post.replies.length, + targetPostHash: post.targetPost.emitterPostHash, + reactionsCount: [] } for (let i = 0; i < post.reactionTypesCount; i++) { diff --git a/Network/Queries/ProfileStats.js b/Network/Queries/ProfileStats.js index 69615657f..350ed48f4 100644 --- a/Network/Queries/ProfileStats.js +++ b/Network/Queries/ProfileStats.js @@ -42,7 +42,7 @@ exports.newProfileStats = function newProfileStats() { "tradePostsFollowersCount": thisObject.profile.tradePostsFollowersCount, "emitterEventsCount": thisObject.profile.emitterEventsCount, "targetEventsCount": thisObject.profile.targetEventsCount, - "postsCount": thisObject.profile.maps.POSTSCount, + "postsCount": thisObject.profile.postsCount, "botsCount": thisObject.profile.botsCount } } diff --git a/Network/event.js b/Network/event.js index 8c0ff314e..313765cfb 100644 --- a/Network/event.js +++ b/Network/event.js @@ -2,11 +2,14 @@ exports.newEvent = function newEvent() { let thisObject = { eventId: undefined, - eventType: undefined, - emitterUserProfile: undefined, - targetUserProfile: undefined, - asset: undefined, + emitterUserProfileId: undefined, + targetUserProfileId: undefined, + emitterPostHash: undefined, + targetPostHash: undefined, timestamp: undefined, + botId: undefined, + botAsset: undefined, + botExchange: undefined, initialize: initialize, finalize: finalize } @@ -52,20 +55,36 @@ exports.newEvent = function newEvent() { return thisObject function finalize() { - thisObject.emitterUserProfile = undefined - thisObject.targetUserProfile = undefined + emitterUserProfile = undefined + targetUserProfile = undefined } function initialize(eventReceived) { - - thisObject.emitterUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(eventReceived.emitterUserProfileId) - if (thisObject.emitterUserProfile === undefined) { + /* + Store the message properties into this object properties. + */ + thisObject.eventId = eventReceived.eventId + thisObject.emitterUserProfileId = eventReceived.emitterUserProfileId + thisObject.targetUserProfileId = eventReceived.targetUserProfileId + thisObject.emitterPostHash = eventReceived.emitterPostHash + thisObject.targetPostHash = eventReceived.targetPostHash + thisObject.timestamp = eventReceived.timestamp + thisObject.botId = eventReceived.botId + thisObject.botAsset = eventReceived.botAsset + thisObject.botExchange = eventReceived.botExchange + /* + Validate Emitter User Profile. + */ + let emitterUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(eventReceived.emitterUserProfileId) + if (emitterUserProfile === undefined) { throw ('Emitter User Profile Not Found.') } - thisObject.emitterUserProfile.emitterEventsCount++ - - thisObject.targetUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(eventReceived.targetUserProfileId) - if (thisObject.targetUserProfile === undefined) { + emitterUserProfile.emitterEventsCount++ + /* + Validate Target User Profile. + */ + let targetUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(eventReceived.targetUserProfileId) + if (targetUserProfile === undefined) { /* We thow an exception when it does not have a target user profile and is required*/ if ( eventReceived.eventType !== EVENT_TYPES.NEW_MULTI_MEDIA_POST && @@ -74,13 +93,8 @@ exports.newEvent = function newEvent() { throw ('Target User Profile Not Found.') } } else { - thisObject.targetUserProfile.targetEventsCount++ + targetUserProfile.targetEventsCount++ } - - thisObject.eventId = eventReceived.eventId - thisObject.eventType = eventReceived.eventType - thisObject.asset = eventReceived.asset - thisObject.timestamp = eventReceived.timestamp /* Is is a new post? */ @@ -98,13 +112,13 @@ exports.newEvent = function newEvent() { eventReceived.eventType === EVENT_TYPES.NEW_MULTI_MEDIA_POST || eventReceived.eventType === EVENT_TYPES.REPLY_TO_MULTI_MEDIA_POST || eventReceived.eventType === EVENT_TYPES.REPOST_MULTI_MEDIA || - eventReceived.eventType === EVENT_TYPES.QUOTE_REPOST_MULTI_MEDIA + eventReceived.eventType === EVENT_TYPES.QUOTE_REPOST_MULTI_MEDIA ) { - thisObject.emitterUserProfile.addPost( + emitterUserProfile.addPost( eventReceived.emitterPostHash, eventReceived.targetPostHash, thisObject.eventType, - thisObject.emitterUserProfile, + emitterUserProfile, thisObject.timestamp ) } @@ -122,38 +136,38 @@ exports.newEvent = function newEvent() { ) { switch (eventReceived.eventType) { case EVENT_TYPES.FOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS: { - thisObject.emitterUserProfile.addMultiMediaPostsFollowing( - thisObject.targetUserProfile + emitterUserProfile.addMultiMediaPostsFollowing( + targetUserProfile ) - thisObject.targetUserProfile.addMultiMediaPostsFollower( - thisObject.emitterUserProfile + targetUserProfile.addMultiMediaPostsFollower( + emitterUserProfile ) break } case EVENT_TYPES.UNFOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS: { - thisObject.emitterUserProfile.removeMultiMediaPostsFollowing( - thisObject.targetUserProfile + emitterUserProfile.removeMultiMediaPostsFollowing( + targetUserProfile ) - thisObject.targetUserProfile.removeMultiMediaPostsFollower( - thisObject.emitterUserProfile + targetUserProfile.removeMultiMediaPostsFollower( + emitterUserProfile ) break } case EVENT_TYPES.FOLLOW_USER_PROFILE_TRADE_POSTS: { - thisObject.emitterUserProfile.addTradePostsFollowing( - thisObject.targetUserProfile + emitterUserProfile.addTradePostsFollowing( + targetUserProfile ) - thisObject.targetUserProfile.addTradePostsFollower( - thisObject.emitterUserProfile + targetUserProfile.addTradePostsFollower( + emitterUserProfile ) break } case EVENT_TYPES.UNFOLLOW_USER_PROFILE_TRADE_POSTS: { - thisObject.emitterUserProfile.removeTradePostsFollowing( - thisObject.targetUserProfile + emitterUserProfile.removeTradePostsFollowing( + targetUserProfile ) - thisObject.targetUserProfile.removeTradePostsFollower( - thisObject.emitterUserProfile + targetUserProfile.removeTradePostsFollower( + emitterUserProfile ) break } @@ -210,7 +224,7 @@ exports.newEvent = function newEvent() { ) { switch (eventReceived.eventType) { case EVENT_TYPES.ADD_BOT: { - thisObject.emitterUserProfile.addBot( + emitterUserProfile.addBot( thisObject.botId, thisObject.botAsset, thisObject.botExchange @@ -218,19 +232,19 @@ exports.newEvent = function newEvent() { break } case EVENT_TYPES.REMOVE_BOT: { - thisObject.emitterUserProfile.removeBot( + emitterUserProfile.removeBot( thisObject.botId ) break } case EVENT_TYPES.ENABLE_BOT: { - thisObject.emitterUserProfile.enableBot( + emitterUserProfile.enableBot( thisObject.botId ) break } case EVENT_TYPES.DISABLE_BOT: { - thisObject.emitterUserProfile.disableBot( + emitterUserProfile.disableBot( thisObject.botId ) break diff --git a/Network/userProfile.js b/Network/userProfile.js index b4de58d1e..500b713bb 100644 --- a/Network/userProfile.js +++ b/Network/userProfile.js @@ -46,7 +46,7 @@ exports.newUserProfile = function newUserProfile() { thisObject.tradePostsFollowing = undefined thisObject.tradePostsFollowers = undefined - thisObject.maps.POSTS = undefined + thisObject.posts = undefined thisObject.bots = undefined } @@ -64,10 +64,10 @@ exports.newUserProfile = function newUserProfile() { thisObject.tradePostsFollowersCount = 0 thisObject.emitterEventsCount = 0 thisObject.targetEventsCount = 0 - thisObject.maps.POSTSCount = 0 + thisObject.postsCount = 0 thisObject.botsCount = 0 - thisObject.maps.POSTS = [] + thisObject.posts = [] thisObject.bots = undefined } @@ -93,7 +93,7 @@ exports.newUserProfile = function newUserProfile() { thisObject.maps.POSTS.push(post) NT.memory.maps.POSTS.set(emitterPostHash, post) - thisObject.maps.POSTSCount++ + thisObject.postsCount++ } function removePost( @@ -103,17 +103,17 @@ exports.newUserProfile = function newUserProfile() { throw ('Post Does Not Exist.') } - let post = thisObject.maps.POSTS.get(emitterPostHash) + let post = thisObject.posts.get(emitterPostHash) post.finalize() - for (let i = thisObject.maps.POSTS.length - 1; i >= 0; i--) { - if (thisObject.maps.POSTS[i].emitterPostHash === emitterPostHash) { - thisObject.maps.POSTS.splice(i, 1) + for (let i = thisObject.posts.length - 1; i >= 0; i--) { + if (thisObject.posts[i].emitterPostHash === emitterPostHash) { + thisObject.posts.splice(i, 1) break } } NT.memory.maps.POSTS.delete(emitterPostHash) - thisObject.maps.POSTSCount-- + thisObject.postsCount-- } function addMultiMediaPostsFollowing( From 94a48d90085562ee4855bf80211b4c073ff7cdcf Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 27 Aug 2021 13:42:27 +0200 Subject: [PATCH 5/8] Events Query without Filters --- Network/Queries/Events.js | 59 +++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/Network/Queries/Events.js b/Network/Queries/Events.js index 0e5af2b39..1de03b0a2 100644 --- a/Network/Queries/Events.js +++ b/Network/Queries/Events.js @@ -110,6 +110,12 @@ exports.newEvents = function newEvents() { return response function addToResponse(event) { + + let emitterUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(eventReceived.emitterUserProfileId) + let targetUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(eventReceived.targetUserProfileId) + let emitterPost = NT.memory.maps.POSTS.get(eventReceived.emitterPostHash) + let targetPost = NT.memory.maps.POSTS.get(eventReceived.targetPostHash) + let eventResponse = { eventId: event.eventId, eventType: event.eventType, @@ -120,26 +126,49 @@ exports.newEvents = function newEvents() { timestamp: event.timestamp, botId: event.botId, botAsset: event.botAsset, - botExchange: event.botExchange, - emitterUserProfile: { - - }, - targetUserProfile: { - - }, - emitterPost: { - - }, - targetPost: { - - } + botExchange: event.botExchange } - for (let i = 0; i < post.reactionTypesCount; i++) { - eventResponse.reactionsCount.push(post.reactionsCount.get(i)) + if (emitterUserProfile !== undefined) { + let query = NT.modules.QUERY_PROFILE_STATS.newProfileStats() + query.initialize({ targetUserProfileId: event.emitterUserProfileId }) + eventResponse.emitterUserProfile = query.execute() + } + + if (targetUserProfile !== undefined) { + let query = NT.modules.QUERY_PROFILE_STATS.newProfileStats() + query.initialize({ targetUserProfileId: event.targetUserProfileId }) + eventResponse.targetUserProfile = query.execute() + } + + if (emitterPost !== undefined) { + eventResponse.emitterPost = addPost(emitterPost) + } + + if (targetPost !== undefined) { + eventResponse.targetPost = addPost(targetPost) } response.push(eventResponse) + + function addPost(post) { + let postResponse = { + emitterPostHash: post.emitterPostHash, + targetPostHash: post.targetPostHash, + postType: post.postType, + userProfile: post.userProfile.userProfieId, + timestamp: post.timestamp, + repliesCount: post.replies.length, + targetPostHash: post.targetPost.emitterPostHash, + reactionsCount: [] + } + + for (let i = 0; i < post.reactionTypesCount; i++) { + postResponse.reactionsCount.push(post.reactionsCount.get(i)) + } + + return postResponse + } } } } \ No newline at end of file From fd3bddf540f6cd76c29234daf89cc001d4c743f3 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 27 Aug 2021 14:17:12 +0200 Subject: [PATCH 6/8] Superalgos Network: Events Query implemented. --- Network/Queries/Events.js | 153 +++++++++++++++++++++++++++----------- Network/event.js | 95 +++++++++++------------ Network/post.js | 12 ++- 3 files changed, 167 insertions(+), 93 deletions(-) diff --git a/Network/Queries/Events.js b/Network/Queries/Events.js index 1de03b0a2..383608b78 100644 --- a/Network/Queries/Events.js +++ b/Network/Queries/Events.js @@ -96,78 +96,147 @@ exports.newEvents = function newEvents() { for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) { let event = NT.memory.arrays.EVENTS[i] if (event === undefined) { break } - addToResponse(event) + checkEventContext(event) } } case DIRECTION_PAST: { for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) { let event = NT.memory.arrays.EVENTS[i] if (event === undefined) { break } - addToResponse(event) + checkEventContext(event) } } } return response - function addToResponse(event) { + function checkEventContext(event) { + /* + For an event to be returned at the response of this query, it needs to be related + to the profile making the query. How it can be related? + 1. The Emitter or Target profile must be the same as the Query Profile. + 2. The Emitter or Traget profile must be at the Following map of the Query Profile. + 3. The Emmiter or Target post must be belong to any profile at the Following of the Query Profile. + + Any of the above happening, means that indeed it is related. + */ let emitterUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(eventReceived.emitterUserProfileId) let targetUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(eventReceived.targetUserProfileId) let emitterPost = NT.memory.maps.POSTS.get(eventReceived.emitterPostHash) let targetPost = NT.memory.maps.POSTS.get(eventReceived.targetPostHash) - - let eventResponse = { - eventId: event.eventId, - eventType: event.eventType, - emitterUserProfileId: event.emitterUserProfileId, - targetUserProfileId: event.targetUserProfileId, - emitterPostHash: event.emitterPostHash, - targetPostHash: event.targetPostHash, - timestamp: event.timestamp, - botId: event.botId, - botAsset: event.botAsset, - botExchange: event.botExchange - } - + /* + Test #1 : The Emitter or Target profile must be the same as the Query Profile. + */ if (emitterUserProfile !== undefined) { - let query = NT.modules.QUERY_PROFILE_STATS.newProfileStats() - query.initialize({ targetUserProfileId: event.emitterUserProfileId }) - eventResponse.emitterUserProfile = query.execute() + if (emitterUserProfile.userProfieId === thisObject.profile.userProfieId) { + addToResponse(event) + return + } } - if (targetUserProfile !== undefined) { - let query = NT.modules.QUERY_PROFILE_STATS.newProfileStats() - query.initialize({ targetUserProfileId: event.targetUserProfileId }) - eventResponse.targetUserProfile = query.execute() + if (targetUserProfile.userProfieId === thisObject.profile.userProfieId) { + addToResponse(event) + return + } } - + /* + Test #2 : The Emitter or Traget profile must be at the Following map of the Query Profile. + */ + if (emitterUserProfile !== undefined) { + if (thisObject.profile.multiMediaPostsFollowing.get(emitterUserProfile.userProfieId) !== undefined) { + addToResponse(event) + return + } + } + if (targetUserProfile !== undefined) { + if (thisObject.profile.multiMediaPostsFollowing.get(targetUserProfile.userProfieId) !== undefined) { + addToResponse(event) + return + } + } + /* + Test #3 : The Emmiter or Target post must be belong to any profile at the Following of the Query Profile. + */ if (emitterPost !== undefined) { - eventResponse.emitterPost = addPost(emitterPost) + if (thisObject.profile.multiMediaPostsFollowing.get(emitterPost.emitterUserProfileId) !== undefined) { + addToResponse(event) + return + } + } + if (emitterPost !== undefined) { + if (thisObject.profile.multiMediaPostsFollowing.get(emitterPost.targetUserProfileId) !== undefined) { + addToResponse(event) + return + } } - if (targetPost !== undefined) { - eventResponse.targetPost = addPost(targetPost) + if (thisObject.profile.multiMediaPostsFollowing.get(targetPost.emitterUserProfileId) !== undefined) { + addToResponse(event) + return + } + } + if (targetPost !== undefined) { + if (thisObject.profile.multiMediaPostsFollowing.get(targetPost.targetUserProfileId) !== undefined) { + addToResponse(event) + return + } } - response.push(eventResponse) + function addToResponse(event) { - function addPost(post) { - let postResponse = { - emitterPostHash: post.emitterPostHash, - targetPostHash: post.targetPostHash, - postType: post.postType, - userProfile: post.userProfile.userProfieId, - timestamp: post.timestamp, - repliesCount: post.replies.length, - targetPostHash: post.targetPost.emitterPostHash, - reactionsCount: [] + let eventResponse = { + eventId: event.eventId, + eventType: event.eventType, + emitterUserProfileId: event.emitterUserProfileId, + targetUserProfileId: event.targetUserProfileId, + emitterPostHash: event.emitterPostHash, + targetPostHash: event.targetPostHash, + timestamp: event.timestamp, + botId: event.botId, + botAsset: event.botAsset, + botExchange: event.botExchange } - for (let i = 0; i < post.reactionTypesCount; i++) { - postResponse.reactionsCount.push(post.reactionsCount.get(i)) + if (emitterUserProfile !== undefined) { + let query = NT.modules.QUERY_PROFILE_STATS.newProfileStats() + query.initialize({ targetUserProfileId: event.emitterUserProfileId }) + eventResponse.emitterUserProfile = query.execute() } - return postResponse + if (targetUserProfile !== undefined) { + let query = NT.modules.QUERY_PROFILE_STATS.newProfileStats() + query.initialize({ targetUserProfileId: event.targetUserProfileId }) + eventResponse.targetUserProfile = query.execute() + } + + if (emitterPost !== undefined) { + eventResponse.emitterPost = addPost(emitterPost) + } + + if (targetPost !== undefined) { + eventResponse.targetPost = addPost(targetPost) + } + + response.push(eventResponse) + + function addPost(post) { + let postResponse = { + emitterPostHash: post.emitterPostHash, + targetPostHash: post.targetPostHash, + postType: post.postType, + userProfile: post.userProfile.userProfieId, + timestamp: post.timestamp, + repliesCount: post.replies.length, + targetPostHash: post.targetPost.emitterPostHash, + reactionsCount: [] + } + + for (let i = 0; i < post.reactionTypesCount; i++) { + postResponse.reactionsCount.push(post.reactionsCount.get(i)) + } + + return postResponse + } } } } diff --git a/Network/event.js b/Network/event.js index 313765cfb..e69fd9ead 100644 --- a/Network/event.js +++ b/Network/event.js @@ -75,7 +75,7 @@ exports.newEvent = function newEvent() { /* Validate Emitter User Profile. */ - let emitterUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(eventReceived.emitterUserProfileId) + let emitterUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(thisObject.emitterUserProfileId) if (emitterUserProfile === undefined) { throw ('Emitter User Profile Not Found.') } @@ -83,12 +83,12 @@ exports.newEvent = function newEvent() { /* Validate Target User Profile. */ - let targetUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(eventReceived.targetUserProfileId) + let targetUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(thisObject.targetUserProfileId) if (targetUserProfile === undefined) { /* We thow an exception when it does not have a target user profile and is required*/ if ( - eventReceived.eventType !== EVENT_TYPES.NEW_MULTI_MEDIA_POST && - eventReceived.eventType !== EVENT_TYPES.NEW_TRADE_POST + thisObject.eventType !== EVENT_TYPES.NEW_MULTI_MEDIA_POST && + thisObject.eventType !== EVENT_TYPES.NEW_TRADE_POST ) { throw ('Target User Profile Not Found.') } @@ -99,26 +99,27 @@ exports.newEvent = function newEvent() { Is is a new post? */ if ( - eventReceived.eventType === EVENT_TYPES.NEW_MULTI_MEDIA_POST || - eventReceived.eventType === EVENT_TYPES.REPLY_TO_MULTI_MEDIA_POST || - eventReceived.eventType === EVENT_TYPES.REPOST_MULTI_MEDIA || - eventReceived.eventType === EVENT_TYPES.QUOTE_REPOST_MULTI_MEDIA || - eventReceived.eventType === EVENT_TYPES.NEW_TRADE_POST || - eventReceived.eventType === EVENT_TYPES.REPLY_TO_TRADE_POST || - eventReceived.eventType === EVENT_TYPES.RE_POST_TRADE || - eventReceived.eventType === EVENT_TYPES.QUOTE_REPOST_TRADE + thisObject.eventType === EVENT_TYPES.NEW_MULTI_MEDIA_POST || + thisObject.eventType === EVENT_TYPES.REPLY_TO_MULTI_MEDIA_POST || + thisObject.eventType === EVENT_TYPES.REPOST_MULTI_MEDIA || + thisObject.eventType === EVENT_TYPES.QUOTE_REPOST_MULTI_MEDIA || + thisObject.eventType === EVENT_TYPES.NEW_TRADE_POST || + thisObject.eventType === EVENT_TYPES.REPLY_TO_TRADE_POST || + thisObject.eventType === EVENT_TYPES.RE_POST_TRADE || + thisObject.eventType === EVENT_TYPES.QUOTE_REPOST_TRADE ) { if ( - eventReceived.eventType === EVENT_TYPES.NEW_MULTI_MEDIA_POST || - eventReceived.eventType === EVENT_TYPES.REPLY_TO_MULTI_MEDIA_POST || - eventReceived.eventType === EVENT_TYPES.REPOST_MULTI_MEDIA || - eventReceived.eventType === EVENT_TYPES.QUOTE_REPOST_MULTI_MEDIA + thisObject.eventType === EVENT_TYPES.NEW_MULTI_MEDIA_POST || + thisObject.eventType === EVENT_TYPES.REPLY_TO_MULTI_MEDIA_POST || + thisObject.eventType === EVENT_TYPES.REPOST_MULTI_MEDIA || + thisObject.eventType === EVENT_TYPES.QUOTE_REPOST_MULTI_MEDIA ) { emitterUserProfile.addPost( - eventReceived.emitterPostHash, - eventReceived.targetPostHash, + thisObject.emitterUserProfileId, + thisObject.targetUserProfileId, + thisObject.emitterPostHash, + thisObject.targetPostHash, thisObject.eventType, - emitterUserProfile, thisObject.timestamp ) } @@ -129,12 +130,12 @@ exports.newEvent = function newEvent() { Is is a following? */ if ( - eventReceived.eventType === EVENT_TYPES.FOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS || - eventReceived.eventType === EVENT_TYPES.UNFOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS || - eventReceived.eventType === EVENT_TYPES.FOLLOW_USER_PROFILE_TRADE_POSTS || - eventReceived.eventType === EVENT_TYPES.UNFOLLOW_USER_PROFILE_TRADE_POSTS + thisObject.eventType === EVENT_TYPES.FOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS || + thisObject.eventType === EVENT_TYPES.UNFOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS || + thisObject.eventType === EVENT_TYPES.FOLLOW_USER_PROFILE_TRADE_POSTS || + thisObject.eventType === EVENT_TYPES.UNFOLLOW_USER_PROFILE_TRADE_POSTS ) { - switch (eventReceived.eventType) { + switch (thisObject.eventType) { case EVENT_TYPES.FOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS: { emitterUserProfile.addMultiMediaPostsFollowing( targetUserProfile @@ -178,51 +179,51 @@ exports.newEvent = function newEvent() { Is is a Reaction? */ if ( - eventReceived.eventType === EVENT_TYPES.ADD_REACTION_LIKE || - eventReceived.eventType === EVENT_TYPES.ADD_REACTION_LOVE || - eventReceived.eventType === EVENT_TYPES.ADD_REACTION_HAHA || - eventReceived.eventType === EVENT_TYPES.ADD_REACTION_WOW || - eventReceived.eventType === EVENT_TYPES.ADD_REACTION_SAD || - eventReceived.eventType === EVENT_TYPES.ADD_REACTION_ANGRY || - eventReceived.eventType === EVENT_TYPES.ADD_REACTION_HUG + thisObject.eventType === EVENT_TYPES.ADD_REACTION_LIKE || + thisObject.eventType === EVENT_TYPES.ADD_REACTION_LOVE || + thisObject.eventType === EVENT_TYPES.ADD_REACTION_HAHA || + thisObject.eventType === EVENT_TYPES.ADD_REACTION_WOW || + thisObject.eventType === EVENT_TYPES.ADD_REACTION_SAD || + thisObject.eventType === EVENT_TYPES.ADD_REACTION_ANGRY || + thisObject.eventType === EVENT_TYPES.ADD_REACTION_HUG ) { - let targetPost = NT.memory.maps.POSTS.get(eventReceived.targetPostHash) + let targetPost = NT.memory.maps.POSTS.get(thisObject.targetPostHash) if (targetPost === undefined) { throw ('Target Post Not Found') } - targetPost.addReaction(eventReceived.eventType - 100) + targetPost.addReaction(thisObject.eventType - 100) return } if ( - eventReceived.eventType === EVENT_TYPES.REMOVE_REACTION_LIKE || - eventReceived.eventType === EVENT_TYPES.REMOVE_REACTION_LOVE || - eventReceived.eventType === EVENT_TYPES.REMOVE_REACTION_HAHA || - eventReceived.eventType === EVENT_TYPES.REMOVE_REACTION_WOW || - eventReceived.eventType === EVENT_TYPES.REMOVE_REACTION_SAD || - eventReceived.eventType === EVENT_TYPES.REMOVE_REACTION_ANGRY || - eventReceived.eventType === EVENT_TYPES.REMOVE_REACTION_HUG + thisObject.eventType === EVENT_TYPES.REMOVE_REACTION_LIKE || + thisObject.eventType === EVENT_TYPES.REMOVE_REACTION_LOVE || + thisObject.eventType === EVENT_TYPES.REMOVE_REACTION_HAHA || + thisObject.eventType === EVENT_TYPES.REMOVE_REACTION_WOW || + thisObject.eventType === EVENT_TYPES.REMOVE_REACTION_SAD || + thisObject.eventType === EVENT_TYPES.REMOVE_REACTION_ANGRY || + thisObject.eventType === EVENT_TYPES.REMOVE_REACTION_HUG ) { - let targetPost = NT.memory.maps.POSTS.get(eventReceived.targetPostHash) + let targetPost = NT.memory.maps.POSTS.get(thisObject.targetPostHash) if (targetPost === undefined) { throw ('Target Post Not Found') } - targetPost.removeReaction(eventReceived.eventType - 200) + targetPost.removeReaction(thisObject.eventType - 200) return } /* Is is a Bot? */ if ( - eventReceived.eventType === EVENT_TYPES.ADD_BOT || - eventReceived.eventType === EVENT_TYPES.REMOVE_BOT || - eventReceived.eventType === EVENT_TYPES.ENABLE_BOT || - eventReceived.eventType === EVENT_TYPES.DISABLE_BOT + thisObject.eventType === EVENT_TYPES.ADD_BOT || + thisObject.eventType === EVENT_TYPES.REMOVE_BOT || + thisObject.eventType === EVENT_TYPES.ENABLE_BOT || + thisObject.eventType === EVENT_TYPES.DISABLE_BOT ) { - switch (eventReceived.eventType) { + switch (thisObject.eventType) { case EVENT_TYPES.ADD_BOT: { emitterUserProfile.addBot( thisObject.botId, diff --git a/Network/post.js b/Network/post.js index 43a6edb9d..0c5d595cc 100644 --- a/Network/post.js +++ b/Network/post.js @@ -1,10 +1,11 @@ exports.newPost = function newPost() { let thisObject = { + emitterUserProfileId: undefined, + targetUserProfileId: undefined, emitterPostHash: undefined, targetPostHash: undefined, postType: undefined, - userProfile: undefined, timestamp: undefined, replies: undefined, targetPost: undefined, @@ -51,27 +52,30 @@ exports.newPost = function newPost() { return thisObject function finalize() { + thisObject.emitterUserProfileId = undefined + thisObject.targetUserProfileId = undefined thisObject.emitterPostHash = undefined thisObject.targetPostHash = undefined thisObject.postType = undefined - thisObject.userProfile = undefined thisObject.timestamp = undefined thisObject.replies = undefined thisObject.targetPost = undefined } function initialize( + emitterUserProfileId, + targetUserProfileId, emitterPostHash, targetPostHash, postType, - userProfile, timestamp ) { + thisObject.emitterUserProfileId = emitterUserProfileId + thisObject.targetUserProfileId = targetUserProfileId thisObject.emitterPostHash = emitterPostHash thisObject.targetPostHash = targetPostHash thisObject.postType = postType - thisObject.userProfile = userProfile thisObject.timestamp = timestamp thisObject.replies = [] From 72cf70617dd0ffdb5c82750593c0ad3baae69311 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 27 Aug 2021 14:22:04 +0200 Subject: [PATCH 7/8] Superalgos Network: Events Query implemented. Deep Scan Bug Fixed --- Network/Queries/Events.js | 2 ++ Network/Queries/PostReplies.js | 2 ++ Network/Queries/ProfilePosts.js | 2 ++ 3 files changed, 6 insertions(+) diff --git a/Network/Queries/Events.js b/Network/Queries/Events.js index 383608b78..3f57304e5 100644 --- a/Network/Queries/Events.js +++ b/Network/Queries/Events.js @@ -98,6 +98,7 @@ exports.newEvents = function newEvents() { if (event === undefined) { break } checkEventContext(event) } + break } case DIRECTION_PAST: { for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) { @@ -105,6 +106,7 @@ exports.newEvents = function newEvents() { if (event === undefined) { break } checkEventContext(event) } + break } } return response diff --git a/Network/Queries/PostReplies.js b/Network/Queries/PostReplies.js index ace183b99..63c778c36 100644 --- a/Network/Queries/PostReplies.js +++ b/Network/Queries/PostReplies.js @@ -94,6 +94,7 @@ exports.newPostReplies = function newPostReplies() { if (post === undefined) { break } addToResponse(post) } + break } case DIRECTION_PAST: { for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) { @@ -101,6 +102,7 @@ exports.newPostReplies = function newPostReplies() { if (post === undefined) { break } addToResponse(post) } + break } } return response diff --git a/Network/Queries/ProfilePosts.js b/Network/Queries/ProfilePosts.js index 24d097ff2..8a8f51625 100644 --- a/Network/Queries/ProfilePosts.js +++ b/Network/Queries/ProfilePosts.js @@ -98,6 +98,7 @@ exports.newProfilePosts = function newProfilePosts() { if (post === undefined) { break } addToResponse(post) } + break } case DIRECTION_PAST: { for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) { @@ -105,6 +106,7 @@ exports.newProfilePosts = function newProfilePosts() { if (post === undefined) { break } addToResponse(post) } + break } } return response From f997021c0d039ffe359a3c9802e68867acf7a7b8 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 27 Aug 2021 14:34:42 +0200 Subject: [PATCH 8/8] Superalgos Network: Events Query implemented. Deep Scan Bug Fixed #2 --- Client/githubServer.js | 56 +++++++++++++++++++++++++++++++++ Network/Queries/Events.js | 4 +-- Network/Queries/PostReplies.js | 4 +-- Network/Queries/ProfilePosts.js | 4 +-- Network/post.js | 12 +++---- 5 files changed, 68 insertions(+), 12 deletions(-) diff --git a/Client/githubServer.js b/Client/githubServer.js index a349fbcd8..ea77e9660 100644 --- a/Client/githubServer.js +++ b/Client/githubServer.js @@ -211,6 +211,7 @@ exports.newGithubServer = function newGithubServer() { }) await getPrList() await mergePrs() + await closePrsToMaster() async function getPrList() { @@ -592,6 +593,61 @@ exports.newGithubServer = function newGithubServer() { } } } + + async function closePrsToMaster() { + + const per_page = 100 // Max + let page = 0 + let lastPage = false + + while (lastPage === false) { + try { + page++ + + await CL.projects.foundations.utilities.asyncFunctions.sleep(GITHUB_API_WAITING_TIME) + + let listResponse = await octokit.rest.pulls.list({ + owner: owner, + repo: repo, + state: 'open', + head: 'develop', + base: 'develop', + sort: undefined, + direction: undefined, + per_page: per_page, + page: page + }); + + if (listResponse.data.length < 100) { + lastPage = true + } + console.log('[INFO] Github Server -> mergeGithubPullRequests -> doGithub -> getPrList -> Receiving Page = ' + page) + for (let i = 0; i < listResponse.data.length; i++) { + let pullRequest = listResponse.data[i] + console.log('[INFO] Github Server -> mergeGithubPullRequests -> doGithub -> getPrList -> Pull Request "' + pullRequest.title + '" found and added to the list to validate. ') + githubPrListArray.push(pullRequest) + } + console.log('[INFO] Github Server -> mergeGithubPullRequests -> doGithub -> getPrList -> Received = ' + listResponse.data.length) + + } catch (err) { + console.log(err) + + if (err.stack.indexOf('last page') >= 0) { + return + } else { + console.log('[ERROR] Github Server -> mergeGithubPullRequests -> doGithub -> getPrList ->Method call produced an error.') + console.log('[ERROR] Github Server -> mergeGithubPullRequests -> doGithub -> getPrList ->err.stack = ' + err.stack) + console.log('[ERROR] Github Server -> mergeGithubPullRequests -> doGithub -> getPrList ->repository = ' + repository) + console.log('[ERROR] Github Server -> mergeGithubPullRequests -> doGithub -> getPrList ->username = ' + username) + console.log('[ERROR] Github Server -> mergeGithubPullRequests -> doGithub -> getPrList ->token starts with = ' + token.substring(0, 10) + '...') + console.log('[ERROR] Github Server -> mergeGithubPullRequests -> doGithub -> getPrList ->token ends with = ' + '...' + token.substring(token.length - 10)) + error = err + return + } + } + } + } + } catch (err) { console.log('[ERROR] Github Server -> mergeGithubPullRequests -> doGithub -> err.stack = ' + err.stack) } diff --git a/Network/Queries/Events.js b/Network/Queries/Events.js index 3f57304e5..fb401ea2f 100644 --- a/Network/Queries/Events.js +++ b/Network/Queries/Events.js @@ -223,13 +223,13 @@ exports.newEvents = function newEvents() { function addPost(post) { let postResponse = { + emitterUserProfileId: post.emitterUserProfileId, + targetUserProfileId: post.targetUserProfileId, emitterPostHash: post.emitterPostHash, targetPostHash: post.targetPostHash, postType: post.postType, - userProfile: post.userProfile.userProfieId, timestamp: post.timestamp, repliesCount: post.replies.length, - targetPostHash: post.targetPost.emitterPostHash, reactionsCount: [] } diff --git a/Network/Queries/PostReplies.js b/Network/Queries/PostReplies.js index 63c778c36..788af16b4 100644 --- a/Network/Queries/PostReplies.js +++ b/Network/Queries/PostReplies.js @@ -109,13 +109,13 @@ exports.newPostReplies = function newPostReplies() { function addToResponse(post) { let postResponse = { + emitterUserProfileId: post.emitterUserProfileId, + targetUserProfileId: post.targetUserProfileId, emitterPostHash: post.emitterPostHash, targetPostHash: post.targetPostHash, postType: post.postType, - userProfile: post.userProfile.userProfieId, timestamp: post.timestamp, repliesCount: post.replies.length, - targetPostHash: post.targetPost.emitterPostHash, reactionsCount: [] } diff --git a/Network/Queries/ProfilePosts.js b/Network/Queries/ProfilePosts.js index 8a8f51625..fab001ff7 100644 --- a/Network/Queries/ProfilePosts.js +++ b/Network/Queries/ProfilePosts.js @@ -113,13 +113,13 @@ exports.newProfilePosts = function newProfilePosts() { function addToResponse(post) { let postResponse = { + emitterUserProfileId: post.emitterUserProfileId, + targetUserProfileId: post.targetUserProfileId, emitterPostHash: post.emitterPostHash, targetPostHash: post.targetPostHash, postType: post.postType, - userProfile: post.userProfile.userProfieId, timestamp: post.timestamp, repliesCount: post.replies.length, - targetPostHash: post.targetPost.emitterPostHash, reactionsCount: [] } diff --git a/Network/post.js b/Network/post.js index 0c5d595cc..f3e3bd873 100644 --- a/Network/post.js +++ b/Network/post.js @@ -8,9 +8,8 @@ exports.newPost = function newPost() { postType: undefined, timestamp: undefined, replies: undefined, - targetPost: undefined, reactionsCount: undefined, - reactionTypesCount: undefined, + reactionTypesCount: undefined, addReaction: addReaction, removeReactions: removeReaction, initialize: initialize, @@ -59,7 +58,6 @@ exports.newPost = function newPost() { thisObject.postType = undefined thisObject.timestamp = undefined thisObject.replies = undefined - thisObject.targetPost = undefined } function initialize( @@ -82,6 +80,8 @@ exports.newPost = function newPost() { /* Let's find the Target Post */ + let targetPost + if ( event.eventType === POST_TYPES.REPLY_TO_MULTI_MEDIA_POST || event.eventType === POST_TYPES.REPOST_MULTI_MEDIA || @@ -90,9 +90,9 @@ exports.newPost = function newPost() { event.eventType === POST_TYPES.RE_POST_TRADE || event.eventType === POST_TYPES.QUOTE_REPOST_TRADE ) { - thisObject.targetPost = NT.memory.maps.POSTS.get(thisObject.targetPostHash) + targetPost = NT.memory.maps.POSTS.get(thisObject.targetPostHash) - if (thisObject.targetPost === undefined) { + if (targetPost === undefined) { throw ('Target Post Not Found.') } } @@ -103,7 +103,7 @@ exports.newPost = function newPost() { event.eventType === POST_TYPES.REPLY_TO_MULTI_MEDIA_POST || event.eventType === POST_TYPES.REPLY_TO_TRADE_POST ) { - thisObject.targetPost.replies.push(thisObject) + targetPost.replies.push(thisObject) } }