From 4a202b909aeed3bea40120825045a2864e452fa1 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 28 Aug 2021 20:30:40 +0200 Subject: [PATCH 1/8] Superalgos Network: Bot Profile Stats Implemented --- Network/NetwokNode.js | 3 +- Network/Queries/BotProfileStats.js | 52 +++++++++++++++++++ Network/Queries/Events.js | 14 ++--- .../{ProfileStats.js => UserProfileStats.js} | 6 +-- Network/Query.js | 24 ++++++--- Network/userProfile.js | 2 +- 6 files changed, 84 insertions(+), 17 deletions(-) create mode 100644 Network/Queries/BotProfileStats.js rename Network/Queries/{ProfileStats.js => UserProfileStats.js} (89%) diff --git a/Network/NetwokNode.js b/Network/NetwokNode.js index fa5c8f701..5db39e9a1 100644 --- a/Network/NetwokNode.js +++ b/Network/NetwokNode.js @@ -20,7 +20,8 @@ global.NT = { EVENT: require('./Event.js'), POST: require('./Post.js'), QUERY: require('./Query.js'), - QUERY_PROFILE_STATS: require('./Queries/ProfileStats.js'), + QUERY_USER_PROFILE_STATS: require('./Queries/UserProfileStats.js'), + QUERY_BOT_PROFILE_STATS: require('./Queries/BotProfileStats.js'), QUERY_PROFILE_POSTS: require('./Queries/ProfilePosts.js'), QUERY_POST_REPLIES: require('./Queries/ProfileReplies.js'), QUERY_EVENTS: require('./Queries/Events.js') diff --git a/Network/Queries/BotProfileStats.js b/Network/Queries/BotProfileStats.js new file mode 100644 index 000000000..de05fea1a --- /dev/null +++ b/Network/Queries/BotProfileStats.js @@ -0,0 +1,52 @@ +exports.newBotProfileStats = function newBotProfileStats() { + + let thisObject = { + profile: undefined, + execute: execute, + initialize: initialize, + finalize: finalize + } + + return thisObject + + function finalize() { + thisObject.profile = undefined + } + + function initialize(queryReceived) { + /* + Validate Bot Profile + */ + let userProfile + if (queryReceived.targetBotProfileId !== undefined) { + userProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) + } else { + userProfile = NT.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileId) + } + + if (userProfile === undefined) { + throw ('Target User Profile Not Found.') + } + /* + Validate Bot Profile + */ + thisObject.profile = userProfile.bots.get(queryReceived.targetBotProfileId) + if (thisObject.profile === undefined) { + throw ('Target Bot Profile Not Found.') + } + } + + function execute() { + + return { + "botProfileId": thisObject.profile.botProfileId, + "botProfileHandle": thisObject.profile.botProfileHandle, + "ranking": thisObject.profile.ranking, + "followingCount": thisObject.profile.followingCount, + "followersCount": thisObject.profile.followersCount, + "emitterEventsCount": thisObject.profile.emitterEventsCount, + "targetEventsCount": thisObject.profile.targetEventsCount, + "postsCount": thisObject.profile.postsCount + } + } +} \ No newline at end of file diff --git a/Network/Queries/Events.js b/Network/Queries/Events.js index bb84a4de8..b234d316a 100644 --- a/Network/Queries/Events.js +++ b/Network/Queries/Events.js @@ -130,13 +130,13 @@ exports.newEvents = function newEvents() { Test #1 : The Emitter or Target profile must be the same as the Query Profile. */ if (emitterUserProfile !== undefined) { - if (emitterUserProfile.userProfieId === thisObject.profile.userProfieId) { + if (emitterUserProfile.userProfileId === thisObject.profile.userProfileId) { addToResponse(event) return } } if (targetUserProfile !== undefined) { - if (targetUserProfile.userProfieId === thisObject.profile.userProfieId) { + if (targetUserProfile.userProfileId === thisObject.profile.userProfileId) { addToResponse(event) return } @@ -145,13 +145,13 @@ exports.newEvents = function newEvents() { Test #2 : The Emitter or Traget profile must be at the Following map of the Query Profile. */ if (emitterUserProfile !== undefined) { - if (thisObject.profile.following.get(emitterUserProfile.userProfieId) !== undefined) { + if (thisObject.profile.following.get(emitterUserProfile.userProfileId) !== undefined) { addToResponse(event) return } } if (targetUserProfile !== undefined) { - if (thisObject.profile.following.get(targetUserProfile.userProfieId) !== undefined) { + if (thisObject.profile.following.get(targetUserProfile.userProfileId) !== undefined) { addToResponse(event) return } @@ -200,15 +200,17 @@ exports.newEvents = function newEvents() { } if (emitterUserProfile !== undefined) { - let query = NT.modules.QUERY_PROFILE_STATS.newProfileStats() + let query = NT.modules.QUERY_PROFILE_STATS.newUserProfileStats() query.initialize({ targetUserProfileId: event.emitterUserProfileId }) eventResponse.emitterUserProfile = query.execute() + query.finalize() } if (targetUserProfile !== undefined) { - let query = NT.modules.QUERY_PROFILE_STATS.newProfileStats() + let query = NT.modules.QUERY_PROFILE_STATS.newUserProfileStats() query.initialize({ targetUserProfileId: event.targetUserProfileId }) eventResponse.targetUserProfile = query.execute() + query.finalize() } if (emitterPost !== undefined) { diff --git a/Network/Queries/ProfileStats.js b/Network/Queries/UserProfileStats.js similarity index 89% rename from Network/Queries/ProfileStats.js rename to Network/Queries/UserProfileStats.js index 56de88255..383d39aab 100644 --- a/Network/Queries/ProfileStats.js +++ b/Network/Queries/UserProfileStats.js @@ -1,4 +1,4 @@ -exports.newProfileStats = function newProfileStats() { +exports.newUserProfileStats = function newUserProfileStats() { let thisObject = { profile: undefined, @@ -10,7 +10,7 @@ exports.newProfileStats = function newProfileStats() { return thisObject function finalize() { - + thisObject.profile = undefined } function initialize(queryReceived) { @@ -32,7 +32,7 @@ exports.newProfileStats = function newProfileStats() { function execute() { return { - "userProfieId": thisObject.profile.userProfieId, + "userProfileId": thisObject.profile.userProfileId, "userProfileHandle": thisObject.profile.userProfileHandle, "blockchainAccount": thisObject.profile.blockchainAccount, "ranking": thisObject.profile.ranking, diff --git a/Network/Query.js b/Network/Query.js index 3c5d24dfd..65166a513 100644 --- a/Network/Query.js +++ b/Network/Query.js @@ -10,10 +10,11 @@ exports.newQuery = function newQuery() { const QUERY_TYPES = { - PROFILE_STATS: 0, - PROFILE_POSTS: 1, - POST_REPLIES: 2, - EVENTS: 3 + USER_PROFILE_STATS: 0, + BOT_PROFILE_STATS: 1, + PROFILE_POSTS: 2, + POST_REPLIES: 3, + EVENTS: 4 } @@ -30,27 +31,38 @@ exports.newQuery = function newQuery() { switch (thisObject.queryType) { - case QUERY_TYPES.PROFILE_STATS: { - thisObject.query = NT.modules.QUERY_PROFILE_STATS.newProfileStats() + case QUERY_TYPES.USER_PROFILE_STATS: { + thisObject.query = NT.modules.QUERY_USER_PROFILE_STATS.newUserProfileStats() query.initialize(queryReceived) + query.finalize() + break + } + + case QUERY_TYPES.BOT_PROFILE_STATS: { + thisObject.query = NT.modules.QUERY_BOT_PROFILE_STATS.newBotProfileStats() + query.initialize(queryReceived) + query.finalize() break } case QUERY_TYPES.PROFILE_POSTS: { thisObject.query = NT.modules.QUERY_PROFILE_POSTS.newProfilePosts() query.initialize(queryReceived) + query.finalize() break } case QUERY_TYPES.POST_REPLIES: { thisObject.query = NT.modules.QUERY_POST_REPLIES.newPostReplies() query.initialize(queryReceived) + query.finalize() break } case QUERY_TYPES.maps.EVENTS: { thisObject.query = NT.modules.QUERY_EVENTS.newEvents() query.initialize(queryReceived) + query.finalize() break } default: throw('Query Type Not Supported.') diff --git a/Network/userProfile.js b/Network/userProfile.js index 50766821f..07516f643 100644 --- a/Network/userProfile.js +++ b/Network/userProfile.js @@ -1,7 +1,7 @@ exports.newUserProfile = function newUserProfile() { let thisObject = { - userProfieId: undefined, + userProfileId: undefined, userProfileHandle: undefined, blockchainAccount: undefined, ranking: undefined, From 1cd04a056b2ab9715cec8fe1ea4ce43355e6bd54 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 29 Aug 2021 09:16:30 +0200 Subject: [PATCH 2/8] User Profile re-written --- Network/NetwokNode.js | 14 +- Network/Queries/BotProfileStats.js | 1 - Network/Queries/ProfileFollowers.js | 142 ++++++++++++++++ Network/Queries/ProfilePosts.js | 21 ++- Network/Query.js | 20 ++- Network/botProfile.js | 44 ++++- Network/event.js | 18 +- Network/userProfile.js | 154 ++++++++---------- .../User-Profiles/Luis-Fernando-Molina.json | 10 +- .../Spaces/User-Profile-Space/UserProfile.js | 2 +- 10 files changed, 308 insertions(+), 118 deletions(-) create mode 100644 Network/Queries/ProfileFollowers.js diff --git a/Network/NetwokNode.js b/Network/NetwokNode.js index 5db39e9a1..794844275 100644 --- a/Network/NetwokNode.js +++ b/Network/NetwokNode.js @@ -23,7 +23,17 @@ global.NT = { QUERY_USER_PROFILE_STATS: require('./Queries/UserProfileStats.js'), QUERY_BOT_PROFILE_STATS: require('./Queries/BotProfileStats.js'), QUERY_PROFILE_POSTS: require('./Queries/ProfilePosts.js'), - QUERY_POST_REPLIES: require('./Queries/ProfileReplies.js'), + QUERY_PROFILE_FOLLOWERS: require('./Queries/ProfileFollowers.js'), + //QUERY_PROFILE_FOLLOWING: require('./Queries/ProfileFollowing.js'), + //QUERY_POST_REPLIES: require('./Queries/ProfileReplies.js'), QUERY_EVENTS: require('./Queries/Events.js') } -} \ No newline at end of file +} + +const map = new Map([[1, { a: 2 }], [2, { a: 4 }], [4, { a: 8 }]]) +map.set(3, { a: 6 }) +map.delete(2) +map.set(2, { a: 12 }) +let array = Array.from(map) + +console.log(JSON.stringify(array)) \ No newline at end of file diff --git a/Network/Queries/BotProfileStats.js b/Network/Queries/BotProfileStats.js index de05fea1a..137072fb9 100644 --- a/Network/Queries/BotProfileStats.js +++ b/Network/Queries/BotProfileStats.js @@ -41,7 +41,6 @@ exports.newBotProfileStats = function newBotProfileStats() { return { "botProfileId": thisObject.profile.botProfileId, "botProfileHandle": thisObject.profile.botProfileHandle, - "ranking": thisObject.profile.ranking, "followingCount": thisObject.profile.followingCount, "followersCount": thisObject.profile.followersCount, "emitterEventsCount": thisObject.profile.emitterEventsCount, diff --git a/Network/Queries/ProfileFollowers.js b/Network/Queries/ProfileFollowers.js new file mode 100644 index 000000000..bf3e14b98 --- /dev/null +++ b/Network/Queries/ProfileFollowers.js @@ -0,0 +1,142 @@ +exports.newProfileFollowers = function newProfileFollowers() { + + let thisObject = { + profile: undefined, + initialIndex: undefined, + amountRequested: undefined, + direction: undefined, + execute: execute, + initialize: initialize, + finalize: finalize + } + + const INITIAL_POST_INDEX_FIRST = 'First' + const INITIAL_POST_INDEX_LAST = 'Last' + const MIN_AMOUNT_REQUESTED = 1 + const MAX_AMOUNT_REQUESTED = 100 + const DIRECTION_FUTURE = 'Future' + const DIRECTION_PAST = 'Past' + + return thisObject + + function finalize() { + thisObject.profile = undefined + } + + function initialize(queryReceived) { + /* + Validate User Profile + */ + if (queryReceived.targetUserProfileId !== undefined) { + thisObject.profile = NT.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) + } else { + thisObject.profile = NT.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle) + } + + if (thisObject.profile === undefined) { + throw ('Target User Profile Not Found.') + } + /* + Validate Bot Profile + */ + if (queryReceived.targetBotProfileId !== undefined) { + thisObject.profile = thisObject.profile.bots.get(queryReceived.targetBotProfileId) + if (thisObject.profile === undefined) { + throw ('Target Bot Profile Not Found.') + } + } + /* + Validate Initial Index + */ + if (queryReceived.initialIndex === undefined) { + throw ('Initial Index Undefined.') + } + + if (queryReceived.initialIndex === INITIAL_POST_INDEX_LAST) { + queryReceived.initialIndex = thisObject.profile.posts.length - 1 + } + + if (queryReceived.initialIndex === INITIAL_POST_INDEX_FIRST) { + queryReceived.initialIndex = 0 + } + + if (isNaN(queryReceived.initialIndex) === true) { + throw ('Initial Post Is Not a Number.') + } + + thisObject.initialIndex = queryReceived.initialIndex + /* + Validate Amount Requested + */ + if (queryReceived.amountRequested === undefined) { + throw ('Amount Requested Undefined.') + } + + if (isNaN(queryReceived.amountRequested) === true) { + throw ('Amount Requested Is Not a Number.') + } + + if (queryReceived.amountRequested < MIN_AMOUNT_REQUESTED) { + throw ('Amount Requested Below Min.') + } + + if (queryReceived.amountRequested > MAX_AMOUNT_REQUESTED) { + throw ('Amount Requested Above Max.') + } + /* + Validate Direction + */ + if (queryReceived.direction === undefined) { + throw ('Direction Undefined.') + } + + if (queryReceived.direction !== DIRECTION_FUTURE && queryReceived.direction !== DIRECTION_PAST) { + throw ('Direction Not Supported.') + } + + thisObject.direction = queryReceived.direction + + } + + function execute() { + let response = [] + switch (thisObject.direction) { + case DIRECTION_FUTURE: { + for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) { + let arrayItem = thisObject.profile.arrays.followers[i] + if (arrayItem === undefined) { break } + addToResponse(arrayItem) + } + break + } + case DIRECTION_PAST: { + for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) { + let arrayItem = thisObject.profile.arrays.followers[i] + if (arrayItem === undefined) { break } + addToResponse(arrayItem) + } + break + } + } + return response + + function addToResponse(post) { + let postResponse = { + emitterUserProfileId: post.emitterUserProfileId, + targetUserProfileId: post.targetUserProfileId, + emitterPostHash: post.emitterPostHash, + targetPostHash: post.targetPostHash, + postType: post.postType, + timestamp: post.timestamp, + repliesCount: post.replies.length, + 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 fab001ff7..3854d476e 100644 --- a/Network/Queries/ProfilePosts.js +++ b/Network/Queries/ProfilePosts.js @@ -36,6 +36,15 @@ exports.newProfilePosts = function newProfilePosts() { if (thisObject.profile === undefined) { throw ('Target User Profile Not Found.') } + /* + Validate Bot Profile + */ + if (queryReceived.targetBotProfileId !== undefined) { + thisObject.profile = thisObject.profile.bots.get(queryReceived.targetBotProfileId) + if (thisObject.profile === undefined) { + throw ('Target Bot Profile Not Found.') + } + } /* Validate Initial Index */ @@ -94,17 +103,17 @@ 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.posts[i] - if (post === undefined) { break } - addToResponse(post) + let arrayItem = thisObject.profile.arrays.posts[i] + if (arrayItem === undefined) { break } + addToResponse(arrayItem) } break } case DIRECTION_PAST: { for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) { - let post = thisObject.profile.posts[i] - if (post === undefined) { break } - addToResponse(post) + let arrayItem = thisObject.profile.arrays.posts[i] + if (arrayItem === undefined) { break } + addToResponse(arrayItem) } break } diff --git a/Network/Query.js b/Network/Query.js index 65166a513..6842871ee 100644 --- a/Network/Query.js +++ b/Network/Query.js @@ -13,8 +13,10 @@ exports.newQuery = function newQuery() { USER_PROFILE_STATS: 0, BOT_PROFILE_STATS: 1, PROFILE_POSTS: 2, - POST_REPLIES: 3, - EVENTS: 4 + PROFILE_FOLLOWERS: 3, + PROFILE_FOLLOWING: 4, + POST_REPLIES: 5, + EVENTS: 6 } @@ -59,6 +61,20 @@ exports.newQuery = function newQuery() { break } + case QUERY_TYPES.PROFILE_FOLLOWERS: { + thisObject.query = NT.modules.QUERY_PROFILE_FOLLOWERS.newProfileFollowers() + query.initialize(queryReceived) + query.finalize() + break + } + + case QUERY_TYPES.PROFILE_FOLLOWING: { + thisObject.query = NT.modules.QUERY_PROFILE_FOLLOWING.newProfileFollowing() + query.initialize(queryReceived) + query.finalize() + break + } + case QUERY_TYPES.maps.EVENTS: { thisObject.query = NT.modules.QUERY_EVENTS.newEvents() query.initialize(queryReceived) diff --git a/Network/botProfile.js b/Network/botProfile.js index baa427101..121829218 100644 --- a/Network/botProfile.js +++ b/Network/botProfile.js @@ -6,14 +6,23 @@ exports.newUserProfile = function newUserProfile() { botAsset: undefined, botExchange: undefined, enabled: undefined, - following: undefined, - followers: undefined, + arrays: { + following: undefined, + followers: undefined, + posts: undefined, + bots: undefined + }, + maps: { + following: undefined, + followers: undefined, + posts: undefined, + bots: undefined + }, followingCount: undefined, followersCount: undefined, emitterEventsCount: undefined, targetEventsCount: undefined, postsCount: undefined, - posts: undefined, addPost: addPost, removePost: removePost, addFollowing: addFollowing, @@ -27,16 +36,35 @@ exports.newUserProfile = function newUserProfile() { return thisObject function finalize() { - thisObject.following = undefined - thisObject.followers = undefined - thisObject.posts = undefined + thisObject.arrays = { + following: undefined, + followers: undefined, + posts: undefined, + bots: undefined + } + + thisObject.maps = { + following: undefined, + followers: undefined, + posts: undefined, + bots: undefined + } } function initialize() { - thisObject.following = new Map() - thisObject.followers = new Map() + thisObject.arrays = { + following: [], + followers: [], + posts: [] + } + + thisObject.maps = { + following: new Map(), + followers: new Map(), + posts: new Map() + } thisObject.followingCount = 0 thisObject.followersCount = 0 diff --git a/Network/event.js b/Network/event.js index ba63b45bc..736ea183f 100644 --- a/Network/event.js +++ b/Network/event.js @@ -107,7 +107,7 @@ exports.newEvent = function newEvent() { if (emitterBotProfileId !== undefined) { let botProfile = emitterUserProfile.bots.get(emitterBotProfileId) if ( - emitterBotProfile === undefined + botProfile === undefined ) { throw ('Emitter BOt Profile Not Found.') } @@ -202,37 +202,37 @@ exports.newEvent = function newEvent() { switch (thisObject.eventType) { case EVENT_TYPES.FOLLOW_USER_PROFILE: { emitterUserProfile.addFollowing( - targetUserProfile + targetUserProfileId ) targetUserProfile.addFollower( - emitterUserProfile + emitterUserProfileId ) break } case EVENT_TYPES.UNFOLLOW_USER_PROFILE: { emitterUserProfile.removeFollowing( - targetUserProfile + targetUserProfileId ) targetUserProfile.removeFollower( - emitterUserProfile + emitterUserProfileId ) break } case EVENT_TYPES.FOLLOW_BOT_PROFILE: { emitterUserProfile.addTradePostsFollowing( - targetUserProfile + targetBotProfileId ) targetUserProfile.addTradePostsFollower( - emitterUserProfile + emitterUserProfileId ) break } case EVENT_TYPES.UNFOLLOW_BOT_PROFILE: { emitterUserProfile.removeTradePostsFollowing( - targetUserProfile + targetBotProfileId ) targetUserProfile.removeTradePostsFollower( - emitterUserProfile + emitterBotProfileId ) break } diff --git a/Network/userProfile.js b/Network/userProfile.js index 07516f643..b245a02d4 100644 --- a/Network/userProfile.js +++ b/Network/userProfile.js @@ -1,30 +1,33 @@ exports.newUserProfile = function newUserProfile() { let thisObject = { + userProfileId: undefined, userProfileHandle: undefined, blockchainAccount: undefined, ranking: undefined, + following: undefined, followers: undefined, - followingCount: undefined, - followersCount: undefined, + posts: undefined, + bots: undefined, + emitterEventsCount: undefined, targetEventsCount: undefined, - postsCount: undefined, - botsCount: undefined, - bots: undefined, - posts: undefined, + addPost: addPost, removePost: removePost, + addFollowing: addFollowing, removeFollowing: removeFollowing, addFollower: addFollower, removeFollower: removeFollower, + addBot: addBot, removeBot: removeBot, enableBot: enableBot, disableBot: disableBot, + initialize: initialize, finalize: finalize } @@ -32,28 +35,24 @@ exports.newUserProfile = function newUserProfile() { return thisObject function finalize() { + thisObject.following = undefined thisObject.followers = undefined - thisObject.posts = undefined thisObject.bots = undefined + } function initialize() { thisObject.following = new Map() thisObject.followers = new Map() - - thisObject.followingCount = 0 - thisObject.followersCount = 0 + thisObject.posts = new Map() + thisObject.bots = new Map() thisObject.emitterEventsCount = 0 thisObject.targetEventsCount = 0 - thisObject.postsCount = 0 - thisObject.botsCount = 0 - thisObject.posts = [] - thisObject.bots = [] } function addPost( @@ -64,140 +63,127 @@ exports.newUserProfile = function newUserProfile() { postType, timestamp ) { - if (NT.memory.maps.POSTS.get(emitterPostHash) !== undefined) { + if (thisObject.posts.get(emitterPostHash) !== undefined) { throw ('Post Already Exists.') + } else { + let post = NT.modules.POST.newPost() + post.initialize( + emitterUserProfileId, + targetUserProfileId, + undefined, + undefined, + emitterPostHash, + targetPostHash, + postType, + timestamp + ) + + thisObject.posts.set(emitterPostHash, post) } - - let post = NT.modules.POST.newPost() - post.initialize( - emitterUserProfileId, - targetUserProfileId, - undefined, - undefined, - emitterPostHash, - targetPostHash, - postType, - timestamp - ) - - thisObject.posts.push(post) - NT.memory.maps.POSTS.set(emitterPostHash, post) - thisObject.postsCount++ } function removePost( emitterPostHash ) { - if (NT.memory.maps.POSTS.get(emitterPostHash) === undefined) { + if (thisObject.posts.get(emitterPostHash) === undefined) { throw ('Post Does Not Exist.') + } else { + let post = thisObject.posts.get(emitterPostHash) + post.finalize() + thisObject.posts.delete(emitterPostHash) } - - let post = thisObject.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) - break - } - } - NT.memory.maps.POSTS.delete(emitterPostHash) - thisObject.postsCount-- } function addFollowing( - userProfile + targetUserProfileId ) { - if (thisObject.following.get(userProfile.id) === undefined) { - thisObject.following.set(userProfile.id, userProfile) - thisObject.followingCount++ + if (thisObject.following.get(targetUserProfileId) === undefined) { + thisObject.following.set(targetUserProfileId, targetUserProfileId) + } else { + throw ('Already Following.') } } function removeFollowing( - userProfile + targetUserProfileId ) { - if (thisObject.following.get(userProfile.id) !== undefined) { - thisObject.following.delete(userProfile.id) - thisObject.followingCount-- + if (thisObject.following.get(targetUserProfileId) !== undefined) { + thisObject.following.delete(targetUserProfileId) + } else { + throw ('Not Following.') } } function addFollower( - userProfile + emitterUserProfileId ) { - if (thisObject.followers.get(userProfile.id) === undefined) { - thisObject.followers.set(userProfile.id, userProfile) - thisObject.followersCount++ + if (thisObject.followers.get(emitterUserProfileId) === undefined) { + thisObject.followers.set(emitterUserProfileId, emitterUserProfileId) } } function removeFollower( - userProfile + emitterUserProfileId ) { - if (thisObject.followers.get(userProfile.id) !== undefined) { - thisObject.followers.delete(userProfile.id) - thisObject.followersCount-- + if (thisObject.followers.get(emitterUserProfileId) !== undefined) { + thisObject.followers.delete(emitterUserProfileId) } } function addBot( - botId, + botProfileId, botAsset, botExchange ) { - if (thisObject.bots.get(botId) !== undefined) { + let bot = thisObject.bots.get(botProfileId) + if (bot !== undefined) { throw ('Bot Already Exists.') + } else { + let bot = NT.modules.BOTS.newBot() + bot.initialize( + botProfileId, + botAsset, + botExchange + ) + thisObject.bots.set(botProfileId, bot) } - - let bot = NT.modules.BOTS.newBot() - bot.initialize( - botId, - botAsset, - botExchange - ) - thisObject.bots.set(botId, bot) - thisObject.botsCount++ } function removeBot( - botId + botProfileId ) { - if (thisObject.bots.get(botId) === undefined) { + let bot = thisObject.bots.get(botProfileId) + if (bot === undefined) { throw ('Bot Does Not Exist.') + } else { + thisObject.bots.get(botProfileId).finalize() + thisObject.bots.delete(botProfileId) } - thisObject.bots.get(botId).finalize() - thisObject.bots.delete(botId) - thisObject.botsCount-- } function enableBot( - botId + botProfileId ) { - let bot = thisObject.bots.get(botId) + let bot = thisObject.bots.get(botProfileId) if (bot === undefined) { throw ('Bot Does Not Exist.') } - if (bot.enabled === true) { throw ('Bot Already Enabled.') } - bot.enabled = true } function disableBot( - botId + botProfileId ) { - let bot = thisObject.bots.get(botId) + let bot = thisObject.bots.get(botProfileId) if (bot === undefined) { throw ('Bot Does Not Exist.') } - if (bot.enabled === false) { throw ('Bot Already Disabled.') } - bot.enabled = false } } \ No newline at end of file diff --git a/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json b/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json index 4a78876b0..6c3f2ea63 100644 --- a/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json +++ b/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json @@ -13154,17 +13154,17 @@ "id": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", "savedPayload": { "position": { - "x": 30356, - "y": 23119 + "x": 3571.4285714285716, + "y": 25500 }, "targetPosition": { - "x": 30356, - "y": 23119 + "x": 3571.4285714285716, + "y": 25500 }, "floatingObject": { "isPinned": false, "isFrozen": false, - "isCollapsed": false, + "isCollapsed": true, "angleToParent": 1, "distanceToParent": 3, "arrangementStyle": 0 diff --git a/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js b/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js index 9f9a34b04..991feae51 100644 --- a/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js +++ b/Projects/Governance/UI/Spaces/User-Profile-Space/UserProfile.js @@ -56,7 +56,7 @@ function newGovernanceUserProfileSpace() { const X_STEP = SPACE_WIDTH / (userProfiles.length + 1) const Y_STEP = 3000 - const Y_LEVEL = SPACE_HEIGHT * 0.45 + const Y_LEVEL = SPACE_HEIGHT * 0.425 let xOffset = X_STEP let yOffset = 0 From af332691d50c1be7f4d96d2826eda335b020f1ab Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 29 Aug 2021 09:32:44 +0200 Subject: [PATCH 3/8] Bot Profile Re Implemented --- Network/botProfile.js | 145 ++++++++++++++++------------------------- Network/userProfile.js | 16 +++-- 2 files changed, 64 insertions(+), 97 deletions(-) diff --git a/Network/botProfile.js b/Network/botProfile.js index 121829218..1761781f7 100644 --- a/Network/botProfile.js +++ b/Network/botProfile.js @@ -1,34 +1,30 @@ -exports.newUserProfile = function newUserProfile() { +exports.newBotProfile = function newBotProfile() { let thisObject = { + /* Unique Keys */ botProfileId: undefined, botProfileHandle: undefined, + /* Bot Unitque Properties */ botAsset: undefined, botExchange: undefined, enabled: undefined, - arrays: { - following: undefined, - followers: undefined, - posts: undefined, - bots: undefined - }, - maps: { - following: undefined, - followers: undefined, - posts: undefined, - bots: undefined - }, - followingCount: undefined, - followersCount: undefined, + /* Maps */ + following: undefined, + followers: undefined, + posts: undefined, + bots: undefined, + /* Stats */ emitterEventsCount: undefined, targetEventsCount: undefined, - postsCount: undefined, + /* Post Functions */ addPost: addPost, removePost: removePost, + /* Follow - Unfollow Functions */ addFollowing: addFollowing, removeFollowing: removeFollowing, addFollower: addFollower, removeFollower: removeFollower, + /* Framework Functions */ initialize: initialize, finalize: finalize } @@ -37,43 +33,21 @@ exports.newUserProfile = function newUserProfile() { function finalize() { - thisObject.arrays = { - following: undefined, - followers: undefined, - posts: undefined, - bots: undefined - } + thisObject.following = undefined + thisObject.followers = undefined + thisObject.posts = undefined - thisObject.maps = { - following: undefined, - followers: undefined, - posts: undefined, - bots: undefined - } } function initialize() { - thisObject.arrays = { - following: [], - followers: [], - posts: [] - } - - thisObject.maps = { - following: new Map(), - followers: new Map(), - posts: new Map() - } - - thisObject.followingCount = 0 - thisObject.followersCount = 0 + thisObject.following = new Map() + thisObject.followers = new Map() + thisObject.posts = new Map() thisObject.emitterEventsCount = 0 thisObject.targetEventsCount = 0 - thisObject.postsCount = 0 - thisObject.posts = [] } function addPost( @@ -86,80 +60,71 @@ exports.newUserProfile = function newUserProfile() { postType, timestamp ) { - if (NT.memory.maps.POSTS.get(emitterPostHash) !== undefined) { + if (thisObject.posts.get(emitterPostHash) !== undefined) { throw ('Post Already Exists.') + } else { + let post = NT.modules.POST.newPost() + post.initialize( + emitterUserProfileId, + targetUserProfileId, + emitterBotProfileId, + targetBotProfileId, + emitterPostHash, + targetPostHash, + postType, + timestamp + ) + + thisObject.posts.set(emitterPostHash, post) } - - let post = NT.modules.POST.newPost() - post.initialize( - emitterUserProfileId, - targetUserProfileId, - emitterBotProfileId, - targetBotProfileId, - emitterPostHash, - targetPostHash, - postType, - timestamp - ) - - thisObject.posts.push(post) - NT.memory.maps.POSTS.set(emitterPostHash, post) - thisObject.postsCount++ } function removePost( emitterPostHash ) { - if (NT.memory.maps.POSTS.get(emitterPostHash) === undefined) { + if (thisObject.posts.get(emitterPostHash) === undefined) { throw ('Post Does Not Exist.') + } else { + let post = thisObject.posts.get(emitterPostHash) + post.finalize() + thisObject.posts.delete(emitterPostHash) } - - let post = thisObject.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) - break - } - } - NT.memory.maps.POSTS.delete(emitterPostHash) - thisObject.postsCount-- } function addFollowing( - botProfile + targetUserProfileId ) { - if (thisObject.following.get(botProfile.id) === undefined) { - thisObject.following.set(botProfile.id, botProfile) - thisObject.followingCount++ + if (thisObject.following.get(targetUserProfileId) === undefined) { + thisObject.following.set(targetUserProfileId, targetUserProfileId) + } else { + throw ('Already Following.') } } function removeFollowing( - botProfile + targetUserProfileId ) { - if (thisObject.following.get(botProfile.id) !== undefined) { - thisObject.following.delete(botProfile.id) - thisObject.followingCount-- + if (thisObject.following.get(targetUserProfileId) !== undefined) { + thisObject.following.delete(targetUserProfileId) + } else { + throw ('Not Following.') } } function addFollower( - botProfile + emitterUserProfileId ) { - if (thisObject.followers.get(botProfile.id) === undefined) { - thisObject.followers.set(botProfile.id, botProfile) - thisObject.followersCount++ + if (thisObject.followers.get(emitterUserProfileId) === undefined) { + thisObject.followers.set(emitterUserProfileId, emitterUserProfileId) } } function removeFollower( - botProfile + emitterUserProfileId ) { - if (thisObject.followers.get(botProfile.id) !== undefined) { - thisObject.followers.delete(botProfile.id) - thisObject.followersCount-- + if (thisObject.followers.get(emitterUserProfileId) !== undefined) { + thisObject.followers.delete(emitterUserProfileId) } } } + diff --git a/Network/userProfile.js b/Network/userProfile.js index b245a02d4..f1a2158f5 100644 --- a/Network/userProfile.js +++ b/Network/userProfile.js @@ -1,33 +1,35 @@ exports.newUserProfile = function newUserProfile() { let thisObject = { - + /* Unique Keys */ userProfileId: undefined, userProfileHandle: undefined, + /* User Unitque Properties */ blockchainAccount: undefined, + /* SA Reputation + SA Token Balance */ ranking: undefined, - + /* Maps */ following: undefined, followers: undefined, posts: undefined, bots: undefined, - + /* Stats */ emitterEventsCount: undefined, targetEventsCount: undefined, - + /* Post Functions */ addPost: addPost, removePost: removePost, - + /* Follow - Unfollow Functions */ addFollowing: addFollowing, removeFollowing: removeFollowing, addFollower: addFollower, removeFollower: removeFollower, - + /* Bot Functions */ addBot: addBot, removeBot: removeBot, enableBot: enableBot, disableBot: disableBot, - + /* Framework Functions */ initialize: initialize, finalize: finalize } From 4aa11efddfa31ad357cf51604ae92468b3e2d74b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 29 Aug 2021 10:35:41 +0200 Subject: [PATCH 4/8] Post Re Implemented --- Network/Queries/Events.js | 7 +--- Network/Queries/PostReplies.js | 7 +--- Network/Queries/ProfileFollowers.js | 7 +--- Network/Queries/ProfilePosts.js | 7 +--- Network/botProfile.js | 13 +++++- Network/clientsInterface.js | 1 + Network/event.js | 5 ++- Network/post.js | 62 +++++++++++++++-------------- Network/userProfile.js | 14 ++++--- 9 files changed, 60 insertions(+), 63 deletions(-) diff --git a/Network/Queries/Events.js b/Network/Queries/Events.js index b234d316a..ee80312c7 100644 --- a/Network/Queries/Events.js +++ b/Network/Queries/Events.js @@ -232,13 +232,8 @@ exports.newEvents = function newEvents() { postType: post.postType, timestamp: post.timestamp, repliesCount: post.replies.length, - reactionsCount: [] + reactions: Array.from(post.reactions) } - - for (let i = 0; i < post.reactionTypesCount; i++) { - postResponse.reactionsCount.push(post.reactionsCount.get(i)) - } - return postResponse } } diff --git a/Network/Queries/PostReplies.js b/Network/Queries/PostReplies.js index 788af16b4..4661d692e 100644 --- a/Network/Queries/PostReplies.js +++ b/Network/Queries/PostReplies.js @@ -116,13 +116,8 @@ exports.newPostReplies = function newPostReplies() { postType: post.postType, timestamp: post.timestamp, repliesCount: post.replies.length, - reactionsCount: [] + reactions: Array.from(post.reactions) } - - for (let i = 0; i < post.reactionTypesCount; i++) { - postResponse.reactionsCount.push(post.reactionsCount.get(i)) - } - response.push(postResponse) } } diff --git a/Network/Queries/ProfileFollowers.js b/Network/Queries/ProfileFollowers.js index bf3e14b98..829a5f212 100644 --- a/Network/Queries/ProfileFollowers.js +++ b/Network/Queries/ProfileFollowers.js @@ -129,13 +129,8 @@ exports.newProfileFollowers = function newProfileFollowers() { postType: post.postType, timestamp: post.timestamp, repliesCount: post.replies.length, - reactionsCount: [] + reactions: Array.from(post.reactions) } - - for (let i = 0; i < post.reactionTypesCount; i++) { - postResponse.reactionsCount.push(post.reactionsCount.get(i)) - } - response.push(postResponse) } } diff --git a/Network/Queries/ProfilePosts.js b/Network/Queries/ProfilePosts.js index 3854d476e..b24381946 100644 --- a/Network/Queries/ProfilePosts.js +++ b/Network/Queries/ProfilePosts.js @@ -129,13 +129,8 @@ exports.newProfilePosts = function newProfilePosts() { postType: post.postType, timestamp: post.timestamp, repliesCount: post.replies.length, - reactionsCount: [] + reactions: Array.from(post.reactions) } - - for (let i = 0; i < post.reactionTypesCount; i++) { - postResponse.reactionsCount.push(post.reactionsCount.get(i)) - } - response.push(postResponse) } } diff --git a/Network/botProfile.js b/Network/botProfile.js index 1761781f7..dd28512a4 100644 --- a/Network/botProfile.js +++ b/Network/botProfile.js @@ -7,7 +7,7 @@ exports.newBotProfile = function newBotProfile() { /* Bot Unitque Properties */ botAsset: undefined, botExchange: undefined, - enabled: undefined, + botEnabled: undefined, /* Maps */ following: undefined, followers: undefined, @@ -39,7 +39,16 @@ exports.newBotProfile = function newBotProfile() { } - function initialize() { + function initialize( + botProfileId, + botAsset, + botExchange, + botEnabled + ) { + thisObject.botProfileId = botProfileId + thisObject.botAsset = botAsset + thisObject.botExchange = botExchange + thisObject.botEnabled = botEnabled thisObject.following = new Map() thisObject.followers = new Map() diff --git a/Network/clientsInterface.js b/Network/clientsInterface.js index b7c34d125..66b4c0650 100644 --- a/Network/clientsInterface.js +++ b/Network/clientsInterface.js @@ -62,6 +62,7 @@ exports.newClientInterface = function newClientInterface() { "botId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", "botAsset": "BTC", "botExchange": "Binance", + "botEnabled": true, "initialIndex": 35, "amountRequested": 50, "direction": "Past" diff --git a/Network/event.js b/Network/event.js index 736ea183f..8b2869311 100644 --- a/Network/event.js +++ b/Network/event.js @@ -12,6 +12,7 @@ exports.newEvent = function newEvent() { botId: undefined, botAsset: undefined, botExchange: undefined, + botEnabled: undefined, initialize: initialize, finalize: finalize } @@ -78,6 +79,7 @@ exports.newEvent = function newEvent() { thisObject.botId = eventReceived.botId thisObject.botAsset = eventReceived.botAsset thisObject.botExchange = eventReceived.botExchange + thisObject.botEnabled = eventReceived.botEnabled /* Validate Emitter User Profile. */ @@ -292,7 +294,8 @@ exports.newEvent = function newEvent() { emitterUserProfile.addBot( thisObject.botId, thisObject.botAsset, - thisObject.botExchange + thisObject.botExchange, + thisObject.botEnabled ) break } diff --git a/Network/post.js b/Network/post.js index 9b35c95cb..133ef9da3 100644 --- a/Network/post.js +++ b/Network/post.js @@ -1,19 +1,24 @@ exports.newPost = function newPost() { let thisObject = { + /* Parents Ids */ emitterUserProfileId: undefined, targetUserProfileId: undefined, emitterBotProfileId: undefined, targetBotProfileId: undefined, + /* Unique Keys */ emitterPostHash: undefined, targetPostHash: undefined, + /* Post Unitque Properties */ postType: undefined, timestamp: undefined, + /* Maps */ replies: undefined, - reactionsCount: undefined, - reactionTypesCount: undefined, + reactions: undefined, + /* Reaction Functions */ addReaction: addReaction, removeReactions: removeReaction, + /* Framework Functions */ initialize: initialize, finalize: finalize } @@ -35,29 +40,20 @@ exports.newPost = function newPost() { REACTION_HUG: 6 } - thisObject.reactionTypesCount = 7 - - thisObject.reactionsCount = new Map() - thisObject.reactionsCount.set(REACTION_TYPES.REACTION_LIKE, 0) - thisObject.reactionsCount.set(REACTION_TYPES.REACTION_LOVE, 0) - thisObject.reactionsCount.set(REACTION_TYPES.REACTION_HAHA, 0) - thisObject.reactionsCount.set(REACTION_TYPES.REACTION_WOW, 0) - thisObject.reactionsCount.set(REACTION_TYPES.REACTION_SAD, 0) - thisObject.reactionsCount.set(REACTION_TYPES.REACTION_ANGRY, 0) - thisObject.reactionsCount.set(REACTION_TYPES.REACTION_HUG, 0) + thisObject.reactions = new Map() + thisObject.reactions.set(REACTION_TYPES.REACTION_LIKE, 0) + thisObject.reactions.set(REACTION_TYPES.REACTION_LOVE, 0) + thisObject.reactions.set(REACTION_TYPES.REACTION_HAHA, 0) + thisObject.reactions.set(REACTION_TYPES.REACTION_WOW, 0) + thisObject.reactions.set(REACTION_TYPES.REACTION_SAD, 0) + thisObject.reactions.set(REACTION_TYPES.REACTION_ANGRY, 0) + thisObject.reactions.set(REACTION_TYPES.REACTION_HUG, 0) return thisObject function finalize() { - thisObject.emitterUserProfileId = undefined - thisObject.targetUserProfileId = undefined - thisObject.emitterBotProfileId = undefined - thisObject.targetBotProfileId = undefined - thisObject.emitterPostHash = undefined - thisObject.targetPostHash = undefined - thisObject.postType = undefined - thisObject.timestamp = undefined thisObject.replies = undefined + thisObject.reactions = undefined } function initialize( @@ -79,8 +75,6 @@ exports.newPost = function newPost() { thisObject.targetPostHash = targetPostHash thisObject.postType = postType thisObject.timestamp = timestamp - - thisObject.replies = [] /* Let's find the Target Post */ @@ -89,9 +83,17 @@ exports.newPost = function newPost() { if ( thisObject.postType === POST_TYPES.REPLY_TO_POST || thisObject.postType === POST_TYPES.REPOST_ || - thisObject.postType === POST_TYPES.QUOTE_REPOST_ + thisObject.postType === POST_TYPES.QUOTE_REPOST_ ) { - targetPost = NT.memory.maps.POSTS.get(thisObject.targetPostHash) + /* + Validate Target User Profile. + */ + let targetUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(thisObject.targetUserProfileId) + if (targetUserProfile === undefined) { + throw ('Target User Profile Not Found.') + } + + targetPost = targetUserProfile.posts.get(thisObject.targetPostHash) if (targetPost === undefined) { throw ('Target Post Not Found.') @@ -101,29 +103,29 @@ exports.newPost = function newPost() { Let's add this post to the replies of the Target Post */ if ( - thisObject.postType === POST_TYPES.REPLY_TO_POST + thisObject.postType === POST_TYPES.REPLY_TO_POST ) { - targetPost.replies.push(thisObject) + targetPost.replies.set(thisObject.targetPostHash, thisObject.targetPostHash) } } function addReaction(reactionType) { - let reactionCount = thisObject.reactionsCount.get(reactionType) + let reactionCount = thisObject.reactions.get(reactionType) if (reactionCount === undefined) { throw ('Reaction Type Not Supported.') } - thisObject.reactionsCount.set(reactionType, reactionsCount + 1) + thisObject.reactions.set(reactionType, reactionCount + 1) } function removeReaction(reactionType) { - let reactionCount = thisObject.reactionsCount.get(reactionType) + let reactionCount = thisObject.reactions.get(reactionType) if (reactionCount === undefined) { throw ('Reaction Type Not Supported.') } - thisObject.reactionsCount.set(reactionType, reactionsCount - 1) + thisObject.reactions.set(reactionType, reactionCount - 1) } } \ No newline at end of file diff --git a/Network/userProfile.js b/Network/userProfile.js index f1a2158f5..82f19bc0c 100644 --- a/Network/userProfile.js +++ b/Network/userProfile.js @@ -135,7 +135,8 @@ exports.newUserProfile = function newUserProfile() { function addBot( botProfileId, botAsset, - botExchange + botExchange, + botEnabled ) { let bot = thisObject.bots.get(botProfileId) if (bot !== undefined) { @@ -145,7 +146,8 @@ exports.newUserProfile = function newUserProfile() { bot.initialize( botProfileId, botAsset, - botExchange + botExchange, + botEnabled ) thisObject.bots.set(botProfileId, bot) } @@ -170,10 +172,10 @@ exports.newUserProfile = function newUserProfile() { if (bot === undefined) { throw ('Bot Does Not Exist.') } - if (bot.enabled === true) { + if (bot.botEnabled === true) { throw ('Bot Already Enabled.') } - bot.enabled = true + bot.botEnabled = true } function disableBot( @@ -183,9 +185,9 @@ exports.newUserProfile = function newUserProfile() { if (bot === undefined) { throw ('Bot Does Not Exist.') } - if (bot.enabled === false) { + if (bot.botEnabled === false) { throw ('Bot Already Disabled.') } - bot.enabled = false + bot.botEnabled = false } } \ No newline at end of file From 648f699b56f228aea674f7a044371ca4a41ff513 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 29 Aug 2021 11:45:30 +0200 Subject: [PATCH 5/8] Re Writting Event Processing --- ...NetwokNode.js => SocialGraphNetwokNode.js} | 0 Network/event.js | 456 ++++++++++-------- Network/post.js | 26 +- 3 files changed, 267 insertions(+), 215 deletions(-) rename Network/{NetwokNode.js => SocialGraphNetwokNode.js} (100%) diff --git a/Network/NetwokNode.js b/Network/SocialGraphNetwokNode.js similarity index 100% rename from Network/NetwokNode.js rename to Network/SocialGraphNetwokNode.js diff --git a/Network/event.js b/Network/event.js index 8b2869311..bfdd5aec5 100644 --- a/Network/event.js +++ b/Network/event.js @@ -1,24 +1,37 @@ exports.newEvent = function newEvent() { + /* + An Event is anything that happens system wide that + needs to be delivered to relevant entities via + the Superalgos Network. + An Event (in contrast to a Query) produces a change + on the state of the social graph. + */ let thisObject = { + /* Unique Key */ eventId: undefined, + /* Referenced Entities Unique Keys */ emitterUserProfileId: undefined, targetUserProfileId: undefined, emitterBotProfileId: undefined, targetBotProfileId: undefined, emitterPostHash: undefined, targetPostHash: undefined, + /* Event Unitque Properties */ + eventType: undefined, timestamp: undefined, - botId: undefined, + /* Bot Related Properties */ + botProfileId: undefined, botAsset: undefined, botExchange: undefined, botEnabled: undefined, + /* Framework Functions */ initialize: initialize, finalize: finalize } const EVENT_TYPES = { - + /* Users Posts and Following Events */ NEW_USER_POST: 10, REPLY_TO_USER_POST: 11, REPOST_USER_POST: 12, @@ -26,7 +39,7 @@ exports.newEvent = function newEvent() { 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, @@ -34,34 +47,33 @@ exports.newEvent = function newEvent() { 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_HUG: 106, - + 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_HUG: 206 + REMOVE_REACTION_CARE: 206 } return thisObject function finalize() { - emitterUserProfile = undefined - targetUserProfile = undefined + } function initialize(eventReceived) { @@ -75,250 +87,292 @@ exports.newEvent = function newEvent() { thisObject.targetBotProfileId = eventReceived.targetBotProfileId thisObject.emitterPostHash = eventReceived.emitterPostHash thisObject.targetPostHash = eventReceived.targetPostHash + thisObject.eventType = eventReceived.eventType thisObject.timestamp = eventReceived.timestamp - thisObject.botId = eventReceived.botId + thisObject.botProfileId = eventReceived.botProfileId thisObject.botAsset = eventReceived.botAsset thisObject.botExchange = eventReceived.botExchange thisObject.botEnabled = eventReceived.botEnabled /* + Local Variables + */ + let emitterUserProfile + let targetUserProfile + /* Validate Emitter User Profile. */ - let emitterUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(thisObject.emitterUserProfileId) + if (emitterUserProfileId === undefined) { + throw ('Emitter User Profile Id Not Provided.') + } + emitterUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(thisObject.emitterUserProfileId) if (emitterUserProfile === undefined) { throw ('Emitter User Profile Not Found.') } - emitterUserProfile.emitterEventsCount++ /* Validate Target User Profile. */ - 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 ( - thisObject.eventType !== EVENT_TYPES.NEW_USER_POST && - thisObject.eventType !== EVENT_TYPES.NEW_BOT_POST - ) { + if (thisObject.targetUserProfileId !== undefined) { + targetUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(thisObject.targetUserProfileId) + if (targetUserProfile === undefined) { throw ('Target User Profile Not Found.') } - } else { - targetUserProfile.targetEventsCount++ } /* Validate Emitter Bot Profile. */ if (emitterBotProfileId !== undefined) { let botProfile = emitterUserProfile.bots.get(emitterBotProfileId) - if ( - botProfile === undefined - ) { - throw ('Emitter BOt Profile Not Found.') + if (botProfile === undefined) { + throw ('Emitter Bot Profile Not Found.') } } - /* - 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 - ) { + + postingEvents() + followingEvents() + reactionEvents() + botEvents() + eventCounters() + + function postingEvents() { /* - New User Post + 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 - ) { - emitterUserProfile.addPost( - thisObject.emitterUserProfileId, - thisObject.targetUserProfileId, - thisObject.emitterBotProfileId, - thisObject.targetBotProfileId, - thisObject.emitterPostHash, - thisObject.targetPostHash, - thisObject.eventType - 10, - thisObject.timestamp - ) - return - } - /* - New Bot Post - */ - if ( + 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 ) { - emitterBotProfile.addPost( - thisObject.emitterUserProfileId, - thisObject.targetUserProfileId, - thisObject.emitterBotProfileId, - thisObject.targetBotProfileId, - thisObject.emitterPostHash, - thisObject.targetPostHash, - thisObject.eventType - 20, - thisObject.timestamp - ) - return + /* + 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 + ) { + emitterUserProfile.addPost( + thisObject.emitterUserProfileId, + thisObject.targetUserProfileId, + thisObject.emitterBotProfileId, + thisObject.targetBotProfileId, + thisObject.emitterPostHash, + thisObject.targetPostHash, + thisObject.eventType - 10, + thisObject.timestamp + ) + return + } + /* + 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 + ) { + if (emitterBotProfile === undefined) { + throw ('Emitter Bot Profile Id Not Provided.') + } + + emitterBotProfile.addPost( + thisObject.emitterUserProfileId, + thisObject.targetUserProfileId, + thisObject.emitterBotProfileId, + thisObject.targetBotProfileId, + thisObject.emitterPostHash, + thisObject.targetPostHash, + thisObject.eventType - 20, + thisObject.timestamp + ) + return + } + /* + Remove User Post + */ + if ( + thisObject.eventType === EVENT_TYPES.REMOVE_USER_POST + ) { + emitterUserProfile.removePost( + thisObject.emitterPostHash + ) + return + } + /* + Remove Bot Post + */ + if ( + thisObject.eventType === EVENT_TYPES.REMOVE_BOT_POST + ) { + if (emitterBotProfile === undefined) { + throw ('Emitter Bot Profile Id Not Provided.') + } + + emitterBotProfile.removePost( + thisObject.emitterPostHash + ) + return + } } + } + + function followingEvents() { /* - Remove User Post + Is is a following? */ if ( - thisObject.eventType === EVENT_TYPES.REMOVE_USER_POST + 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 ) { - emitterUserProfile.removePost( - thisObject.emitterPostHash - ) + switch (thisObject.eventType) { + case EVENT_TYPES.FOLLOW_USER_PROFILE: { + + if (thisObject.emitterUserProfileId === undefined) { + throw ('Emitter User Profile Id Not Provided.') + } + + if (thisObject.targetUserProfileId === undefined) { + throw ('Target User Profile Id Not Provided.') + } + + emitterUserProfile.addFollowing( + targetUserProfileId + ) + targetUserProfile.addFollower( + emitterUserProfileId + ) + break + } + case EVENT_TYPES.UNFOLLOW_USER_PROFILE: { + emitterUserProfile.removeFollowing( + targetUserProfileId + ) + targetUserProfile.removeFollower( + emitterUserProfileId + ) + break + } + case EVENT_TYPES.FOLLOW_BOT_PROFILE: { + emitterUserProfile.addTradePostsFollowing( + targetBotProfileId + ) + targetUserProfile.addTradePostsFollower( + emitterUserProfileId + ) + break + } + case EVENT_TYPES.UNFOLLOW_BOT_PROFILE: { + emitterUserProfile.removeTradePostsFollowing( + targetBotProfileId + ) + targetUserProfile.removeTradePostsFollower( + emitterBotProfileId + ) + break + } + } return } + } + + function reactionEvents() { /* - Remove Bot Post + Is is a Reaction? */ if ( - thisObject.eventType === EVENT_TYPES.REMOVE_USER_POST + 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 ) { - emitterBotProfile.removePost( - thisObject.emitterPostHash - ) + let targetPost = NT.memory.maps.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 + ) { + let targetPost = NT.memory.maps.POSTS.get(thisObject.targetPostHash) + + if (targetPost === undefined) { + throw ('Target Post Not Found') + } + + targetPost.removeReaction(thisObject.eventType - 200) return } } - /* - 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 - ) { - switch (thisObject.eventType) { - case EVENT_TYPES.FOLLOW_USER_PROFILE: { - emitterUserProfile.addFollowing( - targetUserProfileId - ) - targetUserProfile.addFollower( - emitterUserProfileId - ) - break - } - case EVENT_TYPES.UNFOLLOW_USER_PROFILE: { - emitterUserProfile.removeFollowing( - targetUserProfileId - ) - targetUserProfile.removeFollower( - emitterUserProfileId - ) - break - } - case EVENT_TYPES.FOLLOW_BOT_PROFILE: { - emitterUserProfile.addTradePostsFollowing( - targetBotProfileId - ) - targetUserProfile.addTradePostsFollower( - emitterUserProfileId - ) - break - } - case EVENT_TYPES.UNFOLLOW_BOT_PROFILE: { - emitterUserProfile.removeTradePostsFollowing( - targetBotProfileId - ) - targetUserProfile.removeTradePostsFollower( - emitterBotProfileId - ) - break + + function botEvents() { + /* + 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 + ) { + switch (thisObject.eventType) { + case EVENT_TYPES.ADD_BOT: { + emitterUserProfile.addBot( + thisObject.botProfileId, + thisObject.botAsset, + thisObject.botExchange, + thisObject.botEnabled + ) + break + } + case EVENT_TYPES.REMOVE_BOT: { + emitterUserProfile.removeBot( + thisObject.botProfileId + ) + break + } + case EVENT_TYPES.ENABLE_BOT: { + emitterUserProfile.enableBot( + thisObject.botProfileId + ) + break + } + case EVENT_TYPES.DISABLE_BOT: { + emitterUserProfile.disableBot( + thisObject.botProfileId + ) + break + } } + return } - return } - /* - Is is a Reaction? - */ - 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_HUG - ) { - let targetPost = NT.memory.maps.POSTS.get(thisObject.targetPostHash) - if (targetPost === undefined) { - throw ('Target Post Not Found') + function eventCounters() { + emitterUserProfile.emitterEventsCount++ + if (targetUserProfile !== undefined) { + targetUserProfile.targetEventsCount++ } - - 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_HUG - ) { - let targetPost = NT.memory.maps.POSTS.get(thisObject.targetPostHash) - - if (targetPost === undefined) { - throw ('Target Post Not Found') - } - - targetPost.removeReaction(thisObject.eventType - 200) - return - } - /* - 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 - ) { - switch (thisObject.eventType) { - case EVENT_TYPES.ADD_BOT: { - emitterUserProfile.addBot( - thisObject.botId, - thisObject.botAsset, - thisObject.botExchange, - thisObject.botEnabled - ) - break - } - case EVENT_TYPES.REMOVE_BOT: { - emitterUserProfile.removeBot( - thisObject.botId - ) - break - } - case EVENT_TYPES.ENABLE_BOT: { - emitterUserProfile.enableBot( - thisObject.botId - ) - break - } - case EVENT_TYPES.DISABLE_BOT: { - emitterUserProfile.disableBot( - thisObject.botId - ) - break - } - } - return } } } \ No newline at end of file diff --git a/Network/post.js b/Network/post.js index 133ef9da3..c95a65ef9 100644 --- a/Network/post.js +++ b/Network/post.js @@ -37,7 +37,7 @@ exports.newPost = function newPost() { REACTION_WOW: 3, REACTION_SAD: 4, REACTION_ANGRY: 5, - REACTION_HUG: 6 + REACTION_CARE: 6 } thisObject.reactions = new Map() @@ -47,7 +47,7 @@ exports.newPost = function newPost() { thisObject.reactions.set(REACTION_TYPES.REACTION_WOW, 0) thisObject.reactions.set(REACTION_TYPES.REACTION_SAD, 0) thisObject.reactions.set(REACTION_TYPES.REACTION_ANGRY, 0) - thisObject.reactions.set(REACTION_TYPES.REACTION_HUG, 0) + thisObject.reactions.set(REACTION_TYPES.REACTION_CARE, 0) return thisObject @@ -78,8 +78,6 @@ exports.newPost = function newPost() { /* Let's find the Target Post */ - let targetPost - if ( thisObject.postType === POST_TYPES.REPLY_TO_POST || thisObject.postType === POST_TYPES.REPOST_ || @@ -91,21 +89,21 @@ exports.newPost = function newPost() { let targetUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(thisObject.targetUserProfileId) if (targetUserProfile === undefined) { throw ('Target User Profile Not Found.') - } + } - targetPost = targetUserProfile.posts.get(thisObject.targetPostHash) + let targetPost = targetUserProfile.posts.get(thisObject.targetPostHash) if (targetPost === undefined) { throw ('Target Post Not Found.') } - } - /* - Let's add this post to the replies of the Target Post - */ - if ( - thisObject.postType === POST_TYPES.REPLY_TO_POST - ) { - targetPost.replies.set(thisObject.targetPostHash, thisObject.targetPostHash) + /* + Let's add this post to the replies of the Target Post + */ + if ( + thisObject.postType === POST_TYPES.REPLY_TO_POST + ) { + targetPost.replies.set(thisObject.targetPostHash, thisObject.targetPostHash) + } } } From 9bb7d70eb680c209376c590f4efc730da9563fce Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 29 Aug 2021 12:35:27 +0200 Subject: [PATCH 6/8] Event, User Profile, Bot Profile, Post re-implementation finished --- Network/botProfile.js | 7 +++- Network/event.js | 92 ++++++++++++++++++++++++++++++------------ Network/post.js | 13 +++++- Network/userProfile.js | 20 ++++++++- 4 files changed, 103 insertions(+), 29 deletions(-) diff --git a/Network/botProfile.js b/Network/botProfile.js index dd28512a4..a85bcfa57 100644 --- a/Network/botProfile.js +++ b/Network/botProfile.js @@ -1,5 +1,10 @@ exports.newBotProfile = function newBotProfile() { - + /* + Users can have a Profile that can: + * follow other bots profiles. + * be followed by other bots profiles. + * have posts linked to the profile. + */ let thisObject = { /* Unique Keys */ botProfileId: undefined, diff --git a/Network/event.js b/Network/event.js index bfdd5aec5..b3329a046 100644 --- a/Network/event.js +++ b/Network/event.js @@ -21,7 +21,6 @@ exports.newEvent = function newEvent() { eventType: undefined, timestamp: undefined, /* Bot Related Properties */ - botProfileId: undefined, botAsset: undefined, botExchange: undefined, botEnabled: undefined, @@ -89,7 +88,6 @@ exports.newEvent = function newEvent() { thisObject.targetPostHash = eventReceived.targetPostHash thisObject.eventType = eventReceived.eventType thisObject.timestamp = eventReceived.timestamp - thisObject.botProfileId = eventReceived.botProfileId thisObject.botAsset = eventReceived.botAsset thisObject.botExchange = eventReceived.botExchange thisObject.botEnabled = eventReceived.botEnabled @@ -98,6 +96,8 @@ exports.newEvent = function newEvent() { */ let emitterUserProfile let targetUserProfile + let emitterBotProfile + let targetBotProfile /* Validate Emitter User Profile. */ @@ -121,11 +121,20 @@ exports.newEvent = function newEvent() { Validate Emitter Bot Profile. */ if (emitterBotProfileId !== undefined) { - let botProfile = emitterUserProfile.bots.get(emitterBotProfileId) - if (botProfile === undefined) { + emitterBotProfile = emitterUserProfile.bots.get(emitterBotProfileId) + if (emitterBotProfile === undefined) { throw ('Emitter Bot Profile Not Found.') } } + /* + Validate Target Bot Profile. + */ + if (targetBotProfileId !== undefined) { + targetBotProfile = emitterUserProfile.bots.get(targetBotProfileId) + if (targetBotProfile === undefined) { + throw ('Target Bot Profile Not Found.') + } + } postingEvents() followingEvents() @@ -252,6 +261,15 @@ exports.newEvent = function newEvent() { break } case EVENT_TYPES.UNFOLLOW_USER_PROFILE: { + + if (thisObject.emitterUserProfileId === undefined) { + throw ('Emitter User Profile Id Not Provided.') + } + + if (thisObject.targetUserProfileId === undefined) { + throw ('Target User Profile Id Not Provided.') + } + emitterUserProfile.removeFollowing( targetUserProfileId ) @@ -261,19 +279,37 @@ exports.newEvent = function newEvent() { break } case EVENT_TYPES.FOLLOW_BOT_PROFILE: { - emitterUserProfile.addTradePostsFollowing( + + if (thisObject.emitterBotProfileId === undefined) { + throw ('Emitter Bot Profile Id Not Provided.') + } + + if (thisObject.targetBotProfileId === undefined) { + throw ('Target Bot Profile Id Not Provided.') + } + + emitterBotProfile.addFollowing( targetBotProfileId ) - targetUserProfile.addTradePostsFollower( - emitterUserProfileId + targetBotProfile.addFollower( + emitterBotProfileId ) break } case EVENT_TYPES.UNFOLLOW_BOT_PROFILE: { - emitterUserProfile.removeTradePostsFollowing( + + if (thisObject.emitterBotProfileId === undefined) { + throw ('Emitter Bot Profile Id Not Provided.') + } + + if (thisObject.targetBotProfileId === undefined) { + throw ('Target Bot Profile Id Not Provided.') + } + + emitterBotProfile.removeFollowing( targetBotProfileId ) - targetUserProfile.removeTradePostsFollower( + targetBotProfile.removeFollower( emitterBotProfileId ) break @@ -287,6 +323,18 @@ exports.newEvent = function newEvent() { /* Is is a Reaction? */ + 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 || @@ -296,12 +344,6 @@ exports.newEvent = function newEvent() { thisObject.eventType === EVENT_TYPES.ADD_REACTION_ANGRY || thisObject.eventType === EVENT_TYPES.ADD_REACTION_CARE ) { - let targetPost = NT.memory.maps.POSTS.get(thisObject.targetPostHash) - - if (targetPost === undefined) { - throw ('Target Post Not Found') - } - targetPost.addReaction(thisObject.eventType - 100) return } @@ -314,12 +356,6 @@ exports.newEvent = function newEvent() { thisObject.eventType === EVENT_TYPES.REMOVE_REACTION_ANGRY || thisObject.eventType === EVENT_TYPES.REMOVE_REACTION_CARE ) { - let targetPost = NT.memory.maps.POSTS.get(thisObject.targetPostHash) - - if (targetPost === undefined) { - throw ('Target Post Not Found') - } - targetPost.removeReaction(thisObject.eventType - 200) return } @@ -338,7 +374,7 @@ exports.newEvent = function newEvent() { switch (thisObject.eventType) { case EVENT_TYPES.ADD_BOT: { emitterUserProfile.addBot( - thisObject.botProfileId, + thisObject.emitterBotProfileId, thisObject.botAsset, thisObject.botExchange, thisObject.botEnabled @@ -347,19 +383,19 @@ exports.newEvent = function newEvent() { } case EVENT_TYPES.REMOVE_BOT: { emitterUserProfile.removeBot( - thisObject.botProfileId + thisObject.emitterBotProfileId ) break } case EVENT_TYPES.ENABLE_BOT: { emitterUserProfile.enableBot( - thisObject.botProfileId + thisObject.emitterBotProfileId ) break } case EVENT_TYPES.DISABLE_BOT: { emitterUserProfile.disableBot( - thisObject.botProfileId + thisObject.emitterBotProfileId ) break } @@ -373,6 +409,12 @@ exports.newEvent = function newEvent() { if (targetUserProfile !== undefined) { targetUserProfile.targetEventsCount++ } + if (emitterBotProfile !== undefined) { + emitterUserProfile.emitterEventsCount++ + } + if (targetBotProfile !== undefined) { + targetBotProfile.targetEventsCount++ + } } } } \ No newline at end of file diff --git a/Network/post.js b/Network/post.js index c95a65ef9..efe1f33f0 100644 --- a/Network/post.js +++ b/Network/post.js @@ -1,5 +1,16 @@ exports.newPost = function newPost() { - + /* + Posts represent a collection of multimedia content sotored somewhere else + and identified by that content hash. Posts might belong to: + * a User Profile. + * a Bot Profile. + + Posts might be linked to other posts when they are a reply or quote. + + Posts migth have: + * replies, when a user or bot replies to a post. + * reactions, when a user or bot reacts to a post. + */ let thisObject = { /* Parents Ids */ emitterUserProfileId: undefined, diff --git a/Network/userProfile.js b/Network/userProfile.js index 82f19bc0c..88a0d26f4 100644 --- a/Network/userProfile.js +++ b/Network/userProfile.js @@ -1,5 +1,11 @@ exports.newUserProfile = function newUserProfile() { - + /* + Users can have a Profile that can: + * follow other user profiles. + * be followed by other user profiles. + * have posts linked to the profile. + * have bots linked to the profile. + */ let thisObject = { /* Unique Keys */ userProfileId: undefined, @@ -45,7 +51,17 @@ exports.newUserProfile = function newUserProfile() { } - function initialize() { + function initialize( + userProfileId, + userProfileHandle, + blockchainAccount, + ranking + ) { + + thisObject.userProfileId = userProfileId + thisObject.userProfileHandle = userProfileHandle + thisObject.blockchainAccount = blockchainAccount + thisObject.ranking = ranking thisObject.following = new Map() thisObject.followers = new Map() From 44219d29391692b9126422e66d35aa164c3b6032 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 29 Aug 2021 12:36:55 +0200 Subject: [PATCH 7/8] Update SocialGraphNetwokNode.js --- Network/SocialGraphNetwokNode.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Network/SocialGraphNetwokNode.js b/Network/SocialGraphNetwokNode.js index 794844275..bfe37a806 100644 --- a/Network/SocialGraphNetwokNode.js +++ b/Network/SocialGraphNetwokNode.js @@ -16,7 +16,7 @@ global.NT = { }, modules: { USER_PROFILE: require('./UserProfile.js'), - BOT: require('./BotProfile.js'), + BOT_PROFILE: require('./BotProfile.js'), EVENT: require('./Event.js'), POST: require('./Post.js'), QUERY: require('./Query.js'), From d42f473a91d95af7397c26892d3272b3f116fa55 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 29 Aug 2021 12:39:54 +0200 Subject: [PATCH 8/8] Superalgos Network: Reimplementing basic concepts --- Network/SocialGraphNetwokNode.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Network/SocialGraphNetwokNode.js b/Network/SocialGraphNetwokNode.js index bfe37a806..c1611edbe 100644 --- a/Network/SocialGraphNetwokNode.js +++ b/Network/SocialGraphNetwokNode.js @@ -9,15 +9,14 @@ global.NT = { 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: { + EVENT: require('./Event.js'), USER_PROFILE: require('./UserProfile.js'), BOT_PROFILE: require('./BotProfile.js'), - EVENT: require('./Event.js'), POST: require('./Post.js'), QUERY: require('./Query.js'), QUERY_USER_PROFILE_STATS: require('./Queries/UserProfileStats.js'),