From 9bb7d70eb680c209376c590f4efc730da9563fce Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 29 Aug 2021 12:35:27 +0200 Subject: [PATCH] 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()