From d091a28c79ec2fa34f7150573fe656e604a8cfd0 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 3 Sep 2021 15:48:10 +0200 Subject: [PATCH 1/3] Event Following User Debuged --- Desktop/DesktopApp.js | 30 ++- Projects/ProjectsSchema.json | 6 + Projects/Social-Trading/NT/Modules/Event.js | 198 ++++++++---------- .../Social-Trading/SA/Globals/EventTypes.js | 44 ++++ 4 files changed, 164 insertions(+), 114 deletions(-) create mode 100644 Projects/Social-Trading/SA/Globals/EventTypes.js diff --git a/Desktop/DesktopApp.js b/Desktop/DesktopApp.js index 8e0b948fb..5f3759939 100644 --- a/Desktop/DesktopApp.js +++ b/Desktop/DesktopApp.js @@ -41,8 +41,36 @@ exports.newDesktopApp = function newDesktopApp() { .then(showProfiles) .catch(onError) - function showProfiles(profiles) { + async function showProfiles(profiles) { console.log(profiles) + + for (let i = 0; i < profiles.length; i++) { + let profile = profiles[i] + + /* + Test Following Profiles. + */ + let eventMessage = { + eventType: SA.projects.socialTrading.globals.eventTypes.FOLLOW_USER_PROFILE, + emitterUserProfileId: DK.TEST_NETWORK_CLIENT_USER_PROFILE_ID, + targetUserProfileId: profile.userProfileId + } + + let event = { + requestType: 'Event', + eventMessage: JSON.stringify(eventMessage) + } + + await DK.webSocketsClient.sendMessage( + JSON.stringify(event) + ) + .then(followAdded) + .catch(onError) + + function followAdded() { + console.log("User Profile " + profile.userProfileHandle + " followed.") + } + } } /* Test Query User Profile Stats. diff --git a/Projects/ProjectsSchema.json b/Projects/ProjectsSchema.json index 6cc52d73f..c9d40726a 100644 --- a/Projects/ProjectsSchema.json +++ b/Projects/ProjectsSchema.json @@ -1439,6 +1439,12 @@ "propertyName": "queryTypes", "functionName": "newSocialTradingGlobalsQueryTypes", "fileName": "QueryTypes.js" + }, + { + "name": "Event Types", + "propertyName": "eventTypes", + "functionName": "newSocialTradingGlobalsEventTypes", + "fileName": "EventTypes.js" } ] } diff --git a/Projects/Social-Trading/NT/Modules/Event.js b/Projects/Social-Trading/NT/Modules/Event.js index bd39bcb81..271f87ebd 100644 --- a/Projects/Social-Trading/NT/Modules/Event.js +++ b/Projects/Social-Trading/NT/Modules/Event.js @@ -29,46 +29,6 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { finalize: finalize } - const EVENT_TYPES = { - /* Users Posts and Following Events */ - NEW_USER_POST: 10, - REPLY_TO_USER_POST: 11, - REPOST_USER_POST: 12, - QUOTE_REPOST_USER_POST: 13, - REMOVE_USER_POST: 14, - FOLLOW_USER_PROFILE: 15, - UNFOLLOW_USER_PROFILE: 16, - /* Bots Posts and Following Events */ - NEW_BOT_POST: 20, - REPLY_TO_BOT_POST: 21, - REPOST_BOT_POST: 22, - QUOTE_REPOST_BOT_POST: 23, - REMOVE_BOT_POST: 24, - FOLLOW_BOT_PROFILE: 25, - UNFOLLOW_BOT_PROFILE: 26, - /* Bots Management Events */ - ADD_BOT: 50, - REMOVE_BOT: 51, - ENABLE_BOT: 52, - DISABLE_BOT: 53, - /* Add Reaction to Posts Events */ - ADD_REACTION_LIKE: 100, - ADD_REACTION_LOVE: 101, - ADD_REACTION_HAHA: 102, - ADD_REACTION_WOW: 103, - ADD_REACTION_SAD: 104, - ADD_REACTION_ANGRY: 105, - ADD_REACTION_CARE: 106, - /* Remove Reaction to Posts Events */ - REMOVE_REACTION_LIKE: 200, - REMOVE_REACTION_LOVE: 201, - REMOVE_REACTION_HAHA: 202, - REMOVE_REACTION_WOW: 203, - REMOVE_REACTION_SAD: 204, - REMOVE_REACTION_ANGRY: 205, - REMOVE_REACTION_CARE: 206 - } - return thisObject function finalize() { @@ -101,7 +61,7 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { /* Validate Emitter User Profile. */ - if (emitterUserProfileId === undefined) { + if (thisObject.emitterUserProfileId === undefined) { throw ('Emitter User Profile Id Not Provided.') } emitterUserProfile = NT.projects.socialTrading.globals.memory.maps.USER_PROFILES_BY_ID.get(thisObject.emitterUserProfileId) @@ -120,8 +80,8 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { /* Validate Emitter Bot Profile. */ - if (emitterBotProfileId !== undefined) { - emitterBotProfile = emitterUserProfile.bots.get(emitterBotProfileId) + if (thisObject.emitterBotProfileId !== undefined) { + emitterBotProfile = emitterUserProfile.bots.get(thisObject.emitterBotProfileId) if (emitterBotProfile === undefined) { throw ('Emitter Bot Profile Not Found.') } @@ -129,8 +89,8 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { /* Validate Target Bot Profile. */ - if (targetBotProfileId !== undefined) { - targetBotProfile = emitterUserProfile.bots.get(targetBotProfileId) + if (thisObject.targetBotProfileId !== undefined) { + targetBotProfile = emitterUserProfile.bots.get(thisObject.targetBotProfileId) if (targetBotProfile === undefined) { throw ('Target Bot Profile Not Found.') } @@ -147,23 +107,23 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { Is is related to Posting? */ if ( - thisObject.eventType === EVENT_TYPES.NEW_USER_POST || - thisObject.eventType === EVENT_TYPES.REPLY_TO_USER_POST || - thisObject.eventType === EVENT_TYPES.REPOST_USER_POST || - thisObject.eventType === EVENT_TYPES.QUOTE_REPOST_USER_POST || - thisObject.eventType === EVENT_TYPES.NEW_BOT_POST || - thisObject.eventType === EVENT_TYPES.REPLY_TO_BOT_POST || - thisObject.eventType === EVENT_TYPES.REPOST_BOT_POST || - thisObject.eventType === EVENT_TYPES.QUOTE_REPOST_BOT_POST + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.NEW_USER_POST || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.REPLY_TO_USER_POST || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.REPOST_USER_POST || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.QUOTE_REPOST_USER_POST || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.NEW_BOT_POST || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.REPLY_TO_BOT_POST || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.REPOST_BOT_POST || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.QUOTE_REPOST_BOT_POST ) { /* New User Post */ if ( - thisObject.eventType === EVENT_TYPES.NEW_USER_POST || - thisObject.eventType === EVENT_TYPES.REPLY_TO_USER_POST || - thisObject.eventType === EVENT_TYPES.REPOST_USER_POST || - thisObject.eventType === EVENT_TYPES.QUOTE_REPOST_USER_POST + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.NEW_USER_POST || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.REPLY_TO_USER_POST || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.REPOST_USER_POST || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.QUOTE_REPOST_USER_POST ) { emitterUserProfile.addPost( thisObject.emitterUserProfileId, @@ -181,10 +141,10 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { New Bot Post */ if ( - thisObject.eventType === EVENT_TYPES.NEW_BOT_POST || - thisObject.eventType === EVENT_TYPES.REPLY_TO_BOT_POST || - thisObject.eventType === EVENT_TYPES.REPOST_BOT_POST || - thisObject.eventType === EVENT_TYPES.QUOTE_REPOST_BOT_POST + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.NEW_BOT_POST || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.REPLY_TO_BOT_POST || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.REPOST_BOT_POST || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.QUOTE_REPOST_BOT_POST ) { if (emitterBotProfile === undefined) { throw ('Emitter Bot Profile Id Not Provided.') @@ -206,7 +166,7 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { Remove User Post */ if ( - thisObject.eventType === EVENT_TYPES.REMOVE_USER_POST + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.REMOVE_USER_POST ) { emitterUserProfile.removePost( thisObject.emitterPostHash @@ -217,7 +177,7 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { Remove Bot Post */ if ( - thisObject.eventType === EVENT_TYPES.REMOVE_BOT_POST + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.REMOVE_BOT_POST ) { if (emitterBotProfile === undefined) { throw ('Emitter Bot Profile Id Not Provided.') @@ -236,13 +196,13 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { Is is a following? */ if ( - thisObject.eventType === EVENT_TYPES.FOLLOW_USER_PROFILE || - thisObject.eventType === EVENT_TYPES.UNFOLLOW_USER_PROFILE || - thisObject.eventType === EVENT_TYPES.FOLLOW_BOT_PROFILE || - thisObject.eventType === EVENT_TYPES.UNFOLLOW_BOT_PROFILE + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.FOLLOW_USER_PROFILE || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.UNFOLLOW_USER_PROFILE || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.FOLLOW_BOT_PROFILE || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.UNFOLLOW_BOT_PROFILE ) { switch (thisObject.eventType) { - case EVENT_TYPES.FOLLOW_USER_PROFILE: { + case SA.projects.socialTrading.globals.eventTypes.FOLLOW_USER_PROFILE: { if (thisObject.emitterUserProfileId === undefined) { throw ('Emitter User Profile Id Not Provided.') @@ -253,14 +213,14 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { } emitterUserProfile.addFollowing( - targetUserProfileId + thisObject.targetUserProfileId ) targetUserProfile.addFollower( - emitterUserProfileId + thisObject.emitterUserProfileId ) break } - case EVENT_TYPES.UNFOLLOW_USER_PROFILE: { + case SA.projects.socialTrading.globals.eventTypes.UNFOLLOW_USER_PROFILE: { if (thisObject.emitterUserProfileId === undefined) { throw ('Emitter User Profile Id Not Provided.') @@ -271,14 +231,14 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { } emitterUserProfile.removeFollowing( - targetUserProfileId + thisObject.targetUserProfileId ) targetUserProfile.removeFollower( - emitterUserProfileId + thisObject.emitterUserProfileId ) break } - case EVENT_TYPES.FOLLOW_BOT_PROFILE: { + case SA.projects.socialTrading.globals.eventTypes.FOLLOW_BOT_PROFILE: { if (thisObject.emitterBotProfileId === undefined) { throw ('Emitter Bot Profile Id Not Provided.') @@ -289,16 +249,16 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { } emitterBotProfile.addFollowing( - targetUserProfileId, - targetBotProfileId + thisObject.targetUserProfileId, + thisObject.targetBotProfileId ) targetBotProfile.addFollower( - emitterUserProfileId, - emitterBotProfileId + thisObject.emitterUserProfileId, + thisObject.emitterBotProfileId ) break } - case EVENT_TYPES.UNFOLLOW_BOT_PROFILE: { + case SA.projects.socialTrading.globals.eventTypes.UNFOLLOW_BOT_PROFILE: { if (thisObject.emitterBotProfileId === undefined) { throw ('Emitter Bot Profile Id Not Provided.') @@ -309,10 +269,10 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { } emitterBotProfile.removeFollowing( - targetBotProfileId + thisObject.targetBotProfileId ) targetBotProfile.removeFollower( - emitterBotProfileId + thisObject.emitterBotProfileId ) break } @@ -327,37 +287,49 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { */ let targetPost - if (targetBotProfile !== undefined) { - targetPost = targetBotProfile.posts.get(thisObject.targetPostHash) - } else { - targetPost = targetUserProfile.posts.get(thisObject.targetPostHash) - } - - if (targetPost === undefined) { - throw ('Target Post Not Found') - } - if ( - 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_CARE + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.ADD_REACTION_LIKE || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.ADD_REACTION_LOVE || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.ADD_REACTION_HAHA || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.ADD_REACTION_WOW || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.ADD_REACTION_SAD || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.ADD_REACTION_ANGRY || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.ADD_REACTION_CARE ) { + + if (targetBotProfile !== undefined) { + targetPost = targetBotProfile.posts.get(thisObject.targetPostHash) + } else { + targetPost = targetUserProfile.posts.get(thisObject.targetPostHash) + } + + if (targetPost === undefined) { + throw ('Target Post Not Found') + } + targetPost.addReaction(thisObject.eventType - 100) return } if ( - 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_CARE + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.REMOVE_REACTION_LIKE || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.REMOVE_REACTION_LOVE || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.REMOVE_REACTION_HAHA || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.REMOVE_REACTION_WOW || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.REMOVE_REACTION_SAD || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.REMOVE_REACTION_ANGRY || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.REMOVE_REACTION_CARE ) { + + if (targetBotProfile !== undefined) { + targetPost = targetBotProfile.posts.get(thisObject.targetPostHash) + } else { + targetPost = targetUserProfile.posts.get(thisObject.targetPostHash) + } + + if (targetPost === undefined) { + throw ('Target Post Not Found') + } + targetPost.removeReaction(thisObject.eventType - 200) return } @@ -368,13 +340,13 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { Is is a Bot? */ if ( - thisObject.eventType === EVENT_TYPES.ADD_BOT || - thisObject.eventType === EVENT_TYPES.REMOVE_BOT || - thisObject.eventType === EVENT_TYPES.ENABLE_BOT || - thisObject.eventType === EVENT_TYPES.DISABLE_BOT + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.ADD_BOT || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.REMOVE_BOT || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.ENABLE_BOT || + thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.DISABLE_BOT ) { switch (thisObject.eventType) { - case EVENT_TYPES.ADD_BOT: { + case SA.projects.socialTrading.globals.eventTypes.ADD_BOT: { emitterUserProfile.addBot( thisObject.emitterUserProfileId, thisObject.emitterBotProfileId, @@ -384,19 +356,19 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { ) break } - case EVENT_TYPES.REMOVE_BOT: { + case SA.projects.socialTrading.globals.eventTypes.REMOVE_BOT: { emitterUserProfile.removeBot( thisObject.emitterBotProfileId ) break } - case EVENT_TYPES.ENABLE_BOT: { + case SA.projects.socialTrading.globals.eventTypes.ENABLE_BOT: { emitterUserProfile.enableBot( thisObject.emitterBotProfileId ) break } - case EVENT_TYPES.DISABLE_BOT: { + case SA.projects.socialTrading.globals.eventTypes.DISABLE_BOT: { emitterUserProfile.disableBot( thisObject.emitterBotProfileId ) diff --git a/Projects/Social-Trading/SA/Globals/EventTypes.js b/Projects/Social-Trading/SA/Globals/EventTypes.js new file mode 100644 index 000000000..e5dc63d1f --- /dev/null +++ b/Projects/Social-Trading/SA/Globals/EventTypes.js @@ -0,0 +1,44 @@ +exports.newSocialTradingGlobalsEventTypes = function () { + + let thisObject = { + /* Users Posts and Following Events */ + NEW_USER_POST: 10, + REPLY_TO_USER_POST: 11, + REPOST_USER_POST: 12, + QUOTE_REPOST_USER_POST: 13, + REMOVE_USER_POST: 14, + FOLLOW_USER_PROFILE: 15, + UNFOLLOW_USER_PROFILE: 16, + /* Bots Posts and Following Events */ + NEW_BOT_POST: 20, + REPLY_TO_BOT_POST: 21, + REPOST_BOT_POST: 22, + QUOTE_REPOST_BOT_POST: 23, + REMOVE_BOT_POST: 24, + FOLLOW_BOT_PROFILE: 25, + UNFOLLOW_BOT_PROFILE: 26, + /* Bots Management Events */ + ADD_BOT: 50, + REMOVE_BOT: 51, + ENABLE_BOT: 52, + DISABLE_BOT: 53, + /* Add Reaction to Posts Events */ + ADD_REACTION_LIKE: 100, + ADD_REACTION_LOVE: 101, + ADD_REACTION_HAHA: 102, + ADD_REACTION_WOW: 103, + ADD_REACTION_SAD: 104, + ADD_REACTION_ANGRY: 105, + ADD_REACTION_CARE: 106, + /* Remove Reaction to Posts Events */ + REMOVE_REACTION_LIKE: 200, + REMOVE_REACTION_LOVE: 201, + REMOVE_REACTION_HAHA: 202, + REMOVE_REACTION_WOW: 203, + REMOVE_REACTION_SAD: 204, + REMOVE_REACTION_ANGRY: 205, + REMOVE_REACTION_CARE: 206 + } + + return thisObject +} \ No newline at end of file From 40c7307086fa02c92e88b797e520e19926fb5235 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 3 Sep 2021 15:56:30 +0200 Subject: [PATCH 2/3] Molutple Users Followed --- Desktop/DesktopApp.js | 1 + Projects/Social-Trading/NT/Modules/Event.js | 43 +++++++++++++-------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/Desktop/DesktopApp.js b/Desktop/DesktopApp.js index 5f3759939..91fc7a832 100644 --- a/Desktop/DesktopApp.js +++ b/Desktop/DesktopApp.js @@ -51,6 +51,7 @@ exports.newDesktopApp = function newDesktopApp() { Test Following Profiles. */ let eventMessage = { + eventId: i, eventType: SA.projects.socialTrading.globals.eventTypes.FOLLOW_USER_PROFILE, emitterUserProfileId: DK.TEST_NETWORK_CLIENT_USER_PROFILE_ID, targetUserProfileId: profile.userProfileId diff --git a/Projects/Social-Trading/NT/Modules/Event.js b/Projects/Social-Trading/NT/Modules/Event.js index 271f87ebd..7db74847a 100644 --- a/Projects/Social-Trading/NT/Modules/Event.js +++ b/Projects/Social-Trading/NT/Modules/Event.js @@ -96,11 +96,22 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { } } - postingEvents() - followingEvents() - reactionEvents() - botEvents() - eventCounters() + if (postingEvents()) { + eventCounters() + return + } + if (followingEvents()) { + eventCounters() + return + } + if (reactionEvents()) { + eventCounters() + return + } + if (botEvents()) { + eventCounters() + return + } function postingEvents() { /* @@ -135,7 +146,7 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { thisObject.eventType - 10, thisObject.timestamp ) - return + return true } /* New Bot Post @@ -160,7 +171,7 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { thisObject.eventType - 20, thisObject.timestamp ) - return + return true } /* Remove User Post @@ -171,7 +182,7 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { emitterUserProfile.removePost( thisObject.emitterPostHash ) - return + return true } /* Remove Bot Post @@ -186,7 +197,7 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { emitterBotProfile.removePost( thisObject.emitterPostHash ) - return + return true } } } @@ -277,7 +288,7 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { break } } - return + return true } } @@ -302,13 +313,13 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { } else { targetPost = targetUserProfile.posts.get(thisObject.targetPostHash) } - + if (targetPost === undefined) { throw ('Target Post Not Found') } targetPost.addReaction(thisObject.eventType - 100) - return + return true } if ( thisObject.eventType === SA.projects.socialTrading.globals.eventTypes.REMOVE_REACTION_LIKE || @@ -325,13 +336,13 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { } else { targetPost = targetUserProfile.posts.get(thisObject.targetPostHash) } - + if (targetPost === undefined) { throw ('Target Post Not Found') } - + targetPost.removeReaction(thisObject.eventType - 200) - return + return true } } @@ -375,7 +386,7 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { break } } - return + return true } } From d29335489f0708d5022ddae71c0e5f2dce21b7de Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 4 Sep 2021 11:29:01 +0200 Subject: [PATCH 3/3] genereteUniqueId function moved to SA --- .gitignore | 1 + Desktop/DesktopApp.js | 2 +- .../SA/Utilities/MiscellaneousFunctions.js | 15 +++++++++++++++ .../Low-Frequency-Learning/LearningEpisode.js | 2 +- .../Low-Frequency-Trading/TradingEpisode.js | 2 +- .../Low-Frequency-Trading/TradingOrders.js | 2 +- .../Low-Frequency-Trading/TradingPosition.js | 2 +- .../Low-Frequency-Trading/TradingStrategy.js | 2 +- .../TS/Utilities/MiscellaneousFunctions.js | 8 -------- Projects/ProjectsSchema.json | 6 ++++++ .../Social-Trading/NT/Modules/ClientInterface.js | 14 +++++++++----- 11 files changed, 37 insertions(+), 19 deletions(-) create mode 100644 Projects/Foundations/SA/Utilities/MiscellaneousFunctions.js diff --git a/.gitignore b/.gitignore index 3d0bf0240..0ec8e557c 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ Projects/Foundations/Icons/Thumbs.db *.exe node_modules launch.json +.idea diff --git a/Desktop/DesktopApp.js b/Desktop/DesktopApp.js index 91fc7a832..5dfbc3ea6 100644 --- a/Desktop/DesktopApp.js +++ b/Desktop/DesktopApp.js @@ -51,7 +51,7 @@ exports.newDesktopApp = function newDesktopApp() { Test Following Profiles. */ let eventMessage = { - eventId: i, + eventId: SA.projects.foundations.utilities.miscellaneousFunctions.genereteUniqueId(), eventType: SA.projects.socialTrading.globals.eventTypes.FOLLOW_USER_PROFILE, emitterUserProfileId: DK.TEST_NETWORK_CLIENT_USER_PROFILE_ID, targetUserProfileId: profile.userProfileId diff --git a/Projects/Foundations/SA/Utilities/MiscellaneousFunctions.js b/Projects/Foundations/SA/Utilities/MiscellaneousFunctions.js new file mode 100644 index 000000000..27c00cff2 --- /dev/null +++ b/Projects/Foundations/SA/Utilities/MiscellaneousFunctions.js @@ -0,0 +1,15 @@ +exports.newFoundationsUtilitiesMiscellaneousFunctions = function () { + + let thisObject = { + genereteUniqueId: genereteUniqueId + } + + return thisObject + + function genereteUniqueId() { + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { + var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8) + return v.toString(16) + }) + } +} \ No newline at end of file diff --git a/Projects/Foundations/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/LearningEpisode.js b/Projects/Foundations/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/LearningEpisode.js index 5ce13d58e..276a85fa2 100644 --- a/Projects/Foundations/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/LearningEpisode.js +++ b/Projects/Foundations/TS/Bot-Modules/Learning-Bot/Low-Frequency-Learning/LearningEpisode.js @@ -58,7 +58,7 @@ exports.newFoundationsBotModulesLearningEpisode = function (processIndex) { /* Recording the opening at the Learning Engine Data Structure */ learningEngine.learningCurrent.learningEpisode.status.value = 'Open' learningEngine.learningCurrent.learningEpisode.serialNumber.value = 1 - learningEngine.learningCurrent.learningEpisode.identifier.value = TS.projects.foundations.utilities.miscellaneousFunctions.genereteUniqueId() + learningEngine.learningCurrent.learningEpisode.identifier.value = SA.projects.foundations.utilities.miscellaneousFunctions.genereteUniqueId() learningEngine.learningCurrent.learningEpisode.beginRate.value = learningEngine.learningCurrent.learningEpisode.candle.close.value } diff --git a/Projects/Foundations/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingEpisode.js b/Projects/Foundations/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingEpisode.js index 2570ab8c5..6c3b51cb2 100644 --- a/Projects/Foundations/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingEpisode.js +++ b/Projects/Foundations/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingEpisode.js @@ -66,7 +66,7 @@ exports.newFoundationsBotModulesTradingEpisode = function (processIndex) { /* Recording the opening at the Trading Engine Data Structure */ tradingEngine.tradingCurrent.tradingEpisode.status.value = 'Open' tradingEngine.tradingCurrent.tradingEpisode.serialNumber.value = 1 - tradingEngine.tradingCurrent.tradingEpisode.identifier.value = TS.projects.foundations.utilities.miscellaneousFunctions.genereteUniqueId() + tradingEngine.tradingCurrent.tradingEpisode.identifier.value = SA.projects.foundations.utilities.miscellaneousFunctions.genereteUniqueId() tradingEngine.tradingCurrent.tradingEpisode.beginRate.value = tradingEngine.tradingCurrent.tradingEpisode.candle.close.value } diff --git a/Projects/Foundations/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingOrders.js b/Projects/Foundations/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingOrders.js index fe9107dba..91d1958d2 100644 --- a/Projects/Foundations/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingOrders.js +++ b/Projects/Foundations/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingOrders.js @@ -361,7 +361,7 @@ exports.newFoundationsBotModulesTradingOrders = function (processIndex) { /* Create Order Procedure */ tradingEngineOrder.status.value = 'Open' - tradingEngineOrder.identifier.value = TS.projects.foundations.utilities.miscellaneousFunctions.genereteUniqueId() + tradingEngineOrder.identifier.value = SA.projects.foundations.utilities.miscellaneousFunctions.genereteUniqueId() tradingEngineOrder.begin.value = tradingEngine.tradingCurrent.tradingEpisode.cycle.begin.value tradingEngineOrder.end.value = tradingEngine.tradingCurrent.tradingEpisode.cycle.end.value tradingEngineOrder.serialNumber.value = tradingEngine.tradingCurrent.tradingEpisode.tradingEpisodeCounters.orders.value diff --git a/Projects/Foundations/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingPosition.js b/Projects/Foundations/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingPosition.js index 61b3ddb06..f2de2313c 100644 --- a/Projects/Foundations/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingPosition.js +++ b/Projects/Foundations/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingPosition.js @@ -58,7 +58,7 @@ exports.newFoundationsBotModulesTradingPosition = function (processIndex) { /* Recording the opening at the Trading Engine Data Structure */ tradingEngine.tradingCurrent.position.status.value = 'Open' tradingEngine.tradingCurrent.position.serialNumber.value = tradingEngine.tradingCurrent.tradingEpisode.tradingEpisodeCounters.positions.value + 1 - tradingEngine.tradingCurrent.position.identifier.value = TS.projects.foundations.utilities.miscellaneousFunctions.genereteUniqueId() + tradingEngine.tradingCurrent.position.identifier.value = SA.projects.foundations.utilities.miscellaneousFunctions.genereteUniqueId() tradingEngine.tradingCurrent.position.beginRate.value = tradingEngine.tradingCurrent.tradingEpisode.candle.close.value tradingEngine.tradingCurrent.position.positionBaseAsset.beginBalance.value = tradingEngine.tradingCurrent.tradingEpisode.episodeBaseAsset.balance.value tradingEngine.tradingCurrent.position.positionQuotedAsset.beginBalance.value = tradingEngine.tradingCurrent.tradingEpisode.episodeQuotedAsset.balance.value diff --git a/Projects/Foundations/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingStrategy.js b/Projects/Foundations/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingStrategy.js index da4f00516..f676de4d7 100644 --- a/Projects/Foundations/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingStrategy.js +++ b/Projects/Foundations/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingStrategy.js @@ -44,7 +44,7 @@ exports.newFoundationsBotModulesTradingStrategy = function (processIndex) { /* Recording the opening at the Trading Engine Data Structure */ tradingEngine.tradingCurrent.strategy.status.value = 'Open' tradingEngine.tradingCurrent.strategy.serialNumber.value = tradingEngine.tradingCurrent.tradingEpisode.tradingEpisodeCounters.strategies.value - tradingEngine.tradingCurrent.strategy.identifier.value = TS.projects.foundations.utilities.miscellaneousFunctions.genereteUniqueId() + tradingEngine.tradingCurrent.strategy.identifier.value = SA.projects.foundations.utilities.miscellaneousFunctions.genereteUniqueId() tradingEngine.tradingCurrent.strategy.beginRate.value = tradingEngine.tradingCurrent.tradingEpisode.candle.min.value tradingEngine.tradingCurrent.strategy.index.value = index diff --git a/Projects/Foundations/TS/Utilities/MiscellaneousFunctions.js b/Projects/Foundations/TS/Utilities/MiscellaneousFunctions.js index 16aae45ce..502378e7d 100644 --- a/Projects/Foundations/TS/Utilities/MiscellaneousFunctions.js +++ b/Projects/Foundations/TS/Utilities/MiscellaneousFunctions.js @@ -1,7 +1,6 @@ exports.newFoundationsUtilitiesMiscellaneousFunctions = function () { let thisObject = { - genereteUniqueId: genereteUniqueId, truncateToThisPrecision: truncateToThisPrecision, pad: pad, asyncGetDatasetFile: asyncGetDatasetFile, @@ -10,13 +9,6 @@ exports.newFoundationsUtilitiesMiscellaneousFunctions = function () { return thisObject - function genereteUniqueId() { - return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { - var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8) - return v.toString(16) - }) - } - function truncateToThisPrecision(floatNumber, precision) { return parseFloat(floatNumber.toFixed(precision)) } diff --git a/Projects/ProjectsSchema.json b/Projects/ProjectsSchema.json index c9d40726a..f60a3f0f5 100644 --- a/Projects/ProjectsSchema.json +++ b/Projects/ProjectsSchema.json @@ -894,6 +894,12 @@ "propertyName": "plugins", "functionName": "newFoundationsUtilitiesPlugins", "fileName": "Plugins.js" + }, + { + "name": "Miscellaneous Functions", + "propertyName": "miscellaneousFunctions", + "functionName": "newFoundationsUtilitiesMiscellaneousFunctions", + "fileName": "MiscellaneousFunctions.js" } ] }, diff --git a/Projects/Social-Trading/NT/Modules/ClientInterface.js b/Projects/Social-Trading/NT/Modules/ClientInterface.js index b74c0b675..16a1f1978 100644 --- a/Projects/Social-Trading/NT/Modules/ClientInterface.js +++ b/Projects/Social-Trading/NT/Modules/ClientInterface.js @@ -123,7 +123,7 @@ exports.newSocialTradingModulesClientInterface = function newSocialTradingModule let response = { result: 'Ok', - message: 'Client Interface Event Processed.' + message: 'Client Interface Event Processed.' } return response @@ -132,9 +132,11 @@ exports.newSocialTradingModulesClientInterface = function newSocialTradingModule Any exception that happens while trying to change the state of the Social Graph, will be returned to the caller without doing anything else here. */ + let errorMessage = err.message + if (errorMessage === undefined) { errorMessage = err } let response = { result: 'Error', - message: 'Client Interface ' + err.message + message: 'Client Interface ' + errorMessage } return response } @@ -191,21 +193,23 @@ exports.newSocialTradingModulesClientInterface = function newSocialTradingModule try { let query = NT.projects.socialTrading.modules.query.newSocialTradingModulesQuery() query.initialize(queryReceived) - + let response = { result: 'Ok', message: 'Client Interface Query Processed.', data: query.execute() } return response - + } catch (err) { /* Any exception that happens while trying to execute the query. */ + let errorMessage = err.message + if (errorMessage === undefined) { errorMessage = err } let response = { result: 'Error', - message: err.message + message: 'Client Interface ' + errorMessage } return response }