diff --git a/Desktop/UI/WebApp.js b/Desktop/UI/WebApp.js index 8a1d4d47e..187186993 100644 --- a/Desktop/UI/WebApp.js +++ b/Desktop/UI/WebApp.js @@ -101,11 +101,11 @@ function newWebApp() { Test Query User Profiles. */ queryMessage = { - queryType: SA.projects.socialTrading.globals.queryTypes.USER_PROFILES, + queryType: SA.projects.socialTrading.globals.queryTypes.UNFOLLOWED_USER_PROFILES, emitterUserProfileId: undefined, - initialIndex: 'Last', + initialIndex: SA.projects.socialTrading.globals.queryConstants.INITIAL_INDEX_FIRST, amountRequested: 3, - direction: 'Past' + direction: SA.projects.socialTrading.globals.queryConstants.DIRECTION_UP } query = { @@ -147,7 +147,7 @@ function newWebApp() { if (event.target && event.target.nodeName === "BUTTON") { switch (event.target.action) { case 'Follow Profile': { - await sendUserProfileEvent( + await sendUserTargetProfileEvent( event.target.userProfileId, SA.projects.socialTrading.globals.eventTypes.FOLLOW_USER_PROFILE ) @@ -164,7 +164,7 @@ function newWebApp() { break } case 'Unfollow Profile': { - await sendUserProfileEvent( + await sendUserTargetProfileEvent( event.target.userProfileId, SA.projects.socialTrading.globals.eventTypes.UNFOLLOW_USER_PROFILE ) @@ -264,7 +264,7 @@ function newWebApp() { table.setAttribute("class", "profile-to-follow-table") } - async function sendUserProfileEvent( + async function sendUserTargetProfileEvent( userProfileId, eventType ) { diff --git a/Projects/ProjectsSchema.json b/Projects/ProjectsSchema.json index c6d84b71b..b49b681e4 100644 --- a/Projects/ProjectsSchema.json +++ b/Projects/ProjectsSchema.json @@ -1339,6 +1339,12 @@ "functionName": "newSocialTradingModulesQueriesUserProfiles", "fileName": "Queries/UserProfiles.js" }, + { + "name": "Unfollowed User Profiles", + "propertyName": "queriesUnfollowedUserProfiles", + "functionName": "newSocialTradingModulesQueriesUnfollowedUserProfiles", + "fileName": "Queries/UnfollowedUserProfiles.js" + }, { "name": "Bot Profile Stats", "propertyName": "queriesBotProfileStats", diff --git a/Projects/Social-Trading/NT/Modules/Queries/ProfileFollowers.js b/Projects/Social-Trading/NT/Modules/Queries/ProfileFollowers.js index ce9ba104d..6fd01ef6f 100644 --- a/Projects/Social-Trading/NT/Modules/Queries/ProfileFollowers.js +++ b/Projects/Social-Trading/NT/Modules/Queries/ProfileFollowers.js @@ -35,7 +35,7 @@ exports.newSocialTradingModulesQueriesProfileFollowers = function newSocialTradi let response = [] switch (thisObject.direction) { - case SA.projects.socialTrading.globals.queryConstants.DIRECTION_FUTURE: { + case SA.projects.socialTrading.globals.queryConstants.DIRECTION_UP: { for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) { let arrayItem = thisObject.array[i] if (arrayItem === undefined) { break } @@ -43,7 +43,7 @@ exports.newSocialTradingModulesQueriesProfileFollowers = function newSocialTradi } break } - case NT.projects.socialTrading.globals.queryConstants.DIRECTION_PAST: { + case NT.projects.socialTrading.globals.queryConstants.DIRECTION_DOWN: { for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) { let arrayItem = thisObject.array[i] if (arrayItem === undefined) { break } diff --git a/Projects/Social-Trading/NT/Modules/Queries/ProfileFollowing.js b/Projects/Social-Trading/NT/Modules/Queries/ProfileFollowing.js index a04791cac..d0c088350 100644 --- a/Projects/Social-Trading/NT/Modules/Queries/ProfileFollowing.js +++ b/Projects/Social-Trading/NT/Modules/Queries/ProfileFollowing.js @@ -35,7 +35,7 @@ exports.newSocialTradingModulesQueriesProfileFollowing = function newSocialTradi let response = [] switch (thisObject.direction) { - case SA.projects.socialTrading.globals.queryConstants.DIRECTION_FUTURE: { + case SA.projects.socialTrading.globals.queryConstants.DIRECTION_UP: { for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) { let arrayItem = thisObject.array[i] if (arrayItem === undefined) { break } @@ -43,7 +43,7 @@ exports.newSocialTradingModulesQueriesProfileFollowing = function newSocialTradi } break } - case SA.projects.socialTrading.globals.queryConstants.DIRECTION_PAST: { + case SA.projects.socialTrading.globals.queryConstants.DIRECTION_DOWN: { for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) { let arrayItem = thisObject.array[i] if (arrayItem === undefined) { break } diff --git a/Projects/Social-Trading/NT/Modules/Queries/UnfollowedUserProfiles.js b/Projects/Social-Trading/NT/Modules/Queries/UnfollowedUserProfiles.js new file mode 100644 index 000000000..51a9b0d23 --- /dev/null +++ b/Projects/Social-Trading/NT/Modules/Queries/UnfollowedUserProfiles.js @@ -0,0 +1,104 @@ +exports.newSocialTradingModulesQueriesUnfollowedUserProfiles = function newSocialTradingModulesQueriesUnfollowedUserProfiles() { + /* + This query returns a list of user profiles ordered + by Ranking. It filters out all the profiles that + are already followed by the Emitter User Profile. + */ + let thisObject = { + emitterUserProfile: undefined, + profiles: undefined, + initialIndex: undefined, + amountRequested: undefined, + direction: undefined, + execute: execute, + initialize: initialize, + finalize: finalize + } + + return thisObject + + function finalize() { + thisObject.profiles = undefined + thisObject.emitterUserProfile = undefined + } + + function initialize(queryReceived) { + + thisObject.emitterUserProfile = NT.projects.socialTrading.globals.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.emitterUserProfileId) + if (thisObject.emitterUserProfile === undefined) { + throw ('Emitter User Profile Not Found.') + } + + thisObject.profiles = Array.from( + NT.projects.socialTrading.globals.memory.maps.USER_PROFILES_BY_ID, + x => x[1] + ) + thisObject.profiles.sort((a, b) => (a["ranking"] > b["ranking"]) ? 1 : -1) + + NT.projects.socialTrading.utilities.queriesValidations.arrayValidations(queryReceived, thisObject, thisObject.profiles) + + } + + function execute() { + + let response = [] + + switch (thisObject.direction) { + case SA.projects.socialTrading.globals.queryConstants.DIRECTION_UP: { + let i = thisObject.initialIndex + let foundCount = 0 + while ( + foundCount < thisObject.amountRequested && + i < thisObject.profiles.length + ) { + let profile = thisObject.profiles[i] + if ( + thisObject.emitterUserProfile.following.get(profile.userProfileId) === undefined && + thisObject.emitterUserProfile.userProfileId !== profile.userProfileId + ) { + addToResponse(profile) + foundCount++ + } + i++ + } + break + } + case SA.projects.socialTrading.globals.queryConstants.DIRECTION_DOWN: { + let i = thisObject.initialIndex + let foundCount = 0 + while ( + foundCount < thisObject.amountRequested && + i >= 0 + ) { + let profile = thisObject.profiles[i] + if ( + thisObject.emitterUserProfile.following.get(profile.userProfileId) === undefined && + thisObject.emitterUserProfile.userProfileId !== profile.userProfileId + ) { + addToResponse(profile) + foundCount++ + } + i-- + } + break + } + } + return response + + function addToResponse(profile) { + let postResponse = { + "userProfileId": profile.userProfileId, + "userProfileHandle": profile.userProfileHandle, + "blockchainAccount": profile.blockchainAccount, + "ranking": profile.ranking, + "followingCount": profile.following.size, + "followersCount": profile.followers.size, + "postsCount": profile.posts.size, + "botsCount": profile.bots.size, + "emitterEventsCount": profile.emitterEventsCount, + "targetEventsCount": profile.targetEventsCount + } + response.push(postResponse) + } + } +} \ No newline at end of file diff --git a/Projects/Social-Trading/NT/Modules/Queries/UserProfiles.js b/Projects/Social-Trading/NT/Modules/Queries/UserProfiles.js index bf5223624..57b93bd74 100644 --- a/Projects/Social-Trading/NT/Modules/Queries/UserProfiles.js +++ b/Projects/Social-Trading/NT/Modules/Queries/UserProfiles.js @@ -5,7 +5,7 @@ exports.newSocialTradingModulesQueriesUserProfiles = function newSocialTradingMo and provide them with alternative of who to follow. */ let thisObject = { - array: undefined, + profiles: undefined, initialIndex: undefined, amountRequested: undefined, direction: undefined, @@ -17,18 +17,18 @@ exports.newSocialTradingModulesQueriesUserProfiles = function newSocialTradingMo return thisObject function finalize() { - thisObject.array = undefined + thisObject.profiles = undefined } function initialize(queryReceived) { - thisObject.array = Array.from( + thisObject.profiles = Array.from( NT.projects.socialTrading.globals.memory.maps.USER_PROFILES_BY_ID, x => x[1] ) - thisObject.array.sort((a, b) => (a["ranking"] > b["ranking"]) ? 1 : -1) + thisObject.profiles.sort((a, b) => (a["ranking"] > b["ranking"]) ? 1 : -1) - NT.projects.socialTrading.utilities.queriesValidations.arrayValidations(queryReceived, thisObject, thisObject.array) + NT.projects.socialTrading.utilities.queriesValidations.arrayValidations(queryReceived, thisObject, thisObject.profiles) } @@ -37,19 +37,19 @@ exports.newSocialTradingModulesQueriesUserProfiles = function newSocialTradingMo let response = [] switch (thisObject.direction) { - case SA.projects.socialTrading.globals.queryConstants.DIRECTION_FUTURE: { + case SA.projects.socialTrading.globals.queryConstants.DIRECTION_UP: { for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) { - let arrayItem = thisObject.array[i] - if (arrayItem === undefined) { break } - addToResponse(arrayItem) + let profile = thisObject.profiles[i] + if (profile === undefined) { break } + addToResponse(profile) } break } - case SA.projects.socialTrading.globals.queryConstants.DIRECTION_PAST: { + case SA.projects.socialTrading.globals.queryConstants.DIRECTION_DOWN: { for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) { - let arrayItem = thisObject.array[i] - if (arrayItem === undefined) { break } - addToResponse(arrayItem) + let profile = thisObject.profiles[i] + if (profile === undefined) { break } + addToResponse(profile) } break } diff --git a/Projects/Social-Trading/NT/Modules/Query.js b/Projects/Social-Trading/NT/Modules/Query.js index d60f1e998..8f9ab4633 100644 --- a/Projects/Social-Trading/NT/Modules/Query.js +++ b/Projects/Social-Trading/NT/Modules/Query.js @@ -34,6 +34,12 @@ exports.newSocialTradingModulesQuery = function newSocialTradingModulesQuery() { break } + case SA.projects.socialTrading.globals.queryTypes.UNFOLLOWED_USER_PROFILES: { + thisObject.query = NT.projects.socialTrading.modules.queriesUnfollowedUserProfiles.newSocialTradingModulesQueriesUnfollowedUserProfiles() + thisObject.query.initialize(queryReceived) + break + } + case SA.projects.socialTrading.globals.queryTypes.USER_PROFILE_STATS: { thisObject.query = NT.projects.socialTrading.modules.queriesUserProfileStats.newSocialTradingModulesQueriesUserProfileStats() thisObject.query.initialize(queryReceived) diff --git a/Projects/Social-Trading/NT/Utilities/QueriesValidations.js b/Projects/Social-Trading/NT/Utilities/QueriesValidations.js index dd63209ae..21d7932b7 100644 --- a/Projects/Social-Trading/NT/Utilities/QueriesValidations.js +++ b/Projects/Social-Trading/NT/Utilities/QueriesValidations.js @@ -91,7 +91,12 @@ exports.newSocialTradingUtilitiesQueriesValidations = function newSocialTradingU throw ('Direction Undefined.') } - if (queryReceived.direction !== SA.projects.socialTrading.globals.queryConstants.DIRECTION_FUTURE && queryReceived.direction !== SA.projects.socialTrading.globals.queryConstants.DIRECTION_PAST) { + if ( + queryReceived.direction !== SA.projects.socialTrading.globals.queryConstants.DIRECTION_FUTURE && + queryReceived.direction !== SA.projects.socialTrading.globals.queryConstants.DIRECTION_PAST && + queryReceived.direction !== SA.projects.socialTrading.globals.queryConstants.DIRECTION_UP && + queryReceived.direction !== SA.projects.socialTrading.globals.queryConstants.DIRECTION_DOWN + ) { throw ('Direction Not Supported.') } diff --git a/Projects/Social-Trading/SA/Globals/QueryConstants.js b/Projects/Social-Trading/SA/Globals/QueryConstants.js index 8f62db770..d5a3e0d1b 100644 --- a/Projects/Social-Trading/SA/Globals/QueryConstants.js +++ b/Projects/Social-Trading/SA/Globals/QueryConstants.js @@ -6,7 +6,9 @@ exports.newSocialTradingGlobalsQueryConstants = function () { MIN_AMOUNT_REQUESTED: 1, MAX_AMOUNT_REQUESTED: 100, DIRECTION_FUTURE: 'Future', - DIRECTION_PAST: 'Past' + DIRECTION_PAST: 'Past', + DIRECTION_UP: 'Up', + DIRECTION_Down: 'Down' } return thisObject diff --git a/Projects/Social-Trading/SA/Globals/QueryTypes.js b/Projects/Social-Trading/SA/Globals/QueryTypes.js index ec010b230..34fa39dc6 100644 --- a/Projects/Social-Trading/SA/Globals/QueryTypes.js +++ b/Projects/Social-Trading/SA/Globals/QueryTypes.js @@ -2,13 +2,14 @@ exports.newSocialTradingGlobalsQueryTypes = function () { let thisObject = { USER_PROFILES: 0, - USER_PROFILE_STATS: 1, - BOT_PROFILE_STATS: 2, - PROFILE_POSTS: 3, - PROFILE_FOLLOWERS: 4, - PROFILE_FOLLOWING: 5, - POST_REPLIES: 6, - EVENTS: 7 + UNFOLLOWED_USER_PROFILES: 1, + USER_PROFILE_STATS: 2, + BOT_PROFILE_STATS: 3, + PROFILE_POSTS: 4, + PROFILE_FOLLOWERS: 5, + PROFILE_FOLLOWING: 6, + POST_REPLIES: 7, + EVENTS: 8 } return thisObject