From 9a4aadc14de984577aab702317bfd56acd0819b3 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 26 Aug 2021 12:23:23 +0200 Subject: [PATCH 1/6] Event Counters --- Network/event.js | 11 +++++++---- Network/userProfile.js | 9 ++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Network/event.js b/Network/event.js index ae9c7c74f..864b1b6b9 100644 --- a/Network/event.js +++ b/Network/event.js @@ -67,9 +67,9 @@ exports.newEvent = function newEvent() { thisObject.emitterUserProfile = NT.memory.USER_PROFILES.get(event.emitterUserProfileId) if (thisObject.emitterUserProfile === undefined) { - /* The message is ignored */ - return + throw ('Emitter User Profile Not Found.') } + thisObject.emitterUserProfile.emitterEventsCount++ thisObject.targetUserProfile = NT.memory.USER_PROFILES.get(event.targetUserProfileId) if (thisObject.targetUserProfile === undefined) { @@ -77,8 +77,11 @@ exports.newEvent = function newEvent() { if ( event.eventType !== EVENT_TYPES.NEW_MULTI_MEDIA_POST && event.eventType !== EVENT_TYPES.NEW_TRADE_POST - ) - throw ('Target User Profile Not Found.') + ) { + throw ('Target User Profile Not Found.') + } + } else { + thisObject.targetUserProfile.targetEventsCount++ } thisObject.eventId = event.eventId diff --git a/Network/userProfile.js b/Network/userProfile.js index 03bd37aa4..476397d58 100644 --- a/Network/userProfile.js +++ b/Network/userProfile.js @@ -9,12 +9,12 @@ exports.newUserProfile = function newUserProfile() { tradePostsFollowing: undefined, tradePostsFollowers: undefined, ranking: undefined, - events: undefined, multiMediaPostFollowingCount: undefined, multiMediaPostFollowersCount: undefined, tradePostsFollowingCount: undefined, tradePostsFollowersCount: undefined, - eventsCount: undefined, + emitterEventsCount: undefined, + targetEventsCount: undefined, postsCount: undefined, addMultiMediaPostsFollowing: addMultiMediaPostsFollowing, removeMultiMediaPostsFollowing: removeMultiMediaPostsFollowing, @@ -42,13 +42,12 @@ exports.newUserProfile = function newUserProfile() { thisObject.tradePostsFollowing = new Map() thisObject.tradePostsFollowers = new Map() - thisObject.events = [] // Dont know what this is - thisObject.multiMediaPostFollowingCount = 0 thisObject.multiMediaPostFollowersCount = 0 thisObject.tradePostsFollowingCount = 0 thisObject.tradePostsFollowersCount = 0 - thisObject.eventsCount = 0 + thisObject.emitterEventsCount = 0 + thisObject.targetEventsCount = 0 thisObject.postsCount = 0 } From 99eead96408de297b8e4c00ae607a72dc5f5ce52 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 26 Aug 2021 13:04:44 +0200 Subject: [PATCH 2/6] Adding, Removing, Enabling and Deleting Bots --- Network/{node.js => NetwokNode.js} | 6 ++- Network/bot.js | 28 +++++++++++ Network/event.js | 61 ++++++++++++++++++++--- Network/events.json | 10 ---- Network/graph.json | 20 -------- Network/profiles.json | 22 --------- Network/timeline.json | 27 ----------- Network/userProfile.js | 78 ++++++++++++++++++++++++++++-- 8 files changed, 161 insertions(+), 91 deletions(-) rename Network/{node.js => NetwokNode.js} (78%) create mode 100644 Network/bot.js delete mode 100644 Network/events.json delete mode 100644 Network/graph.json delete mode 100644 Network/profiles.json delete mode 100644 Network/timeline.json diff --git a/Network/node.js b/Network/NetwokNode.js similarity index 78% rename from Network/node.js rename to Network/NetwokNode.js index e218c488c..ff93a2489 100644 --- a/Network/node.js +++ b/Network/NetwokNode.js @@ -8,8 +8,10 @@ global.NT = { TIMELINE: [] // A time ordered list of Posts and Trades. }, modules: { - EVENT: require('./event.js'), - POST: require('./post.js') + EVENT: require('./UserProfile.js'), + EVENT: require('./Event.js'), + POST: require('./Post.js'), + BOT: require('./Bot.js') } } diff --git a/Network/bot.js b/Network/bot.js new file mode 100644 index 000000000..b6ad63f2b --- /dev/null +++ b/Network/bot.js @@ -0,0 +1,28 @@ +exports.newBot = function newBot() { + + let thisObject = { + botId: undefined, + botAsset: undefined, + botExchange: undefined, + enabled: undefined, + initialize: initialize, + finalize: finalize + } + + return thisObject + + function finalize() { + + } + + function initialize( + botId, + botAsset, + botExchange + ) { + thisObject.botId = botId + thisObject.botAsset = botAsset + thisObject.botExchange = botExchange + thisObject.enabled = true + } +} \ No newline at end of file diff --git a/Network/event.js b/Network/event.js index 864b1b6b9..fe2311e53 100644 --- a/Network/event.js +++ b/Network/event.js @@ -12,18 +12,26 @@ exports.newEvent = function newEvent() { } const EVENT_TYPES = { + NEW_MULTI_MEDIA_POST: 10, REPLY_TO_MULTI_MEDIA_POST: 11, REPOST_MULTI_MEDIA: 12, QUOTE_REPOST_MULTI_MEDIA: 13, FOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS: 14, UNFOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS: 15, + NEW_TRADE_POST: 20, REPLY_TO_TRADE_POST: 21, RE_POST_TRADE: 22, QUOTE_REPOST_TRADE: 23, FOLLOW_USER_PROFILE_TRADE_POSTS: 24, UNFOLLOW_USER_PROFILE_TRADE_POSTS: 25, + + ADD_BOT: 50, + REMOVE_BOT: 51, + ENABLE_BOT: 52, + DISABLE_BOT: 53, + ADD_REACTION_LIKE: 100, ADD_REACTION_LOVE: 101, ADD_REACTION_HAHA: 102, @@ -31,6 +39,7 @@ exports.newEvent = function newEvent() { ADD_REACTION_SAD: 104, ADD_REACTION_ANGRY: 105, ADD_REACTION_HUG: 106, + REMOVE_REACTION_LIKE: 200, REMOVE_REACTION_LOVE: 201, REMOVE_REACTION_HAHA: 202, @@ -58,8 +67,10 @@ exports.newEvent = function newEvent() { "targetUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", "emitterPostHash": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", "targetPostHash": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", - "asset": "BTC", - "timestamp": 124234234234 + "timestamp": 124234234234, + "botId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", + "botAsset": "BTC", + "botExchange": "Binance" } */ @@ -77,9 +88,9 @@ exports.newEvent = function newEvent() { if ( event.eventType !== EVENT_TYPES.NEW_MULTI_MEDIA_POST && event.eventType !== EVENT_TYPES.NEW_TRADE_POST - ) { - throw ('Target User Profile Not Found.') - } + ) { + throw ('Target User Profile Not Found.') + } } else { thisObject.targetUserProfile.targetEventsCount++ } @@ -88,7 +99,6 @@ exports.newEvent = function newEvent() { thisObject.eventType = event.eventType thisObject.asset = event.asset thisObject.timestamp = event.timestamp - /* Is is a new post? */ @@ -201,5 +211,44 @@ exports.newEvent = function newEvent() { targetPost.removeReaction(event.eventType - 200) return } + /* + Is is a Bot? + */ + if ( + event.eventType === EVENT_TYPES.ADD_BOT || + event.eventType === EVENT_TYPES.REMOVE_BOT || + event.eventType === EVENT_TYPES.ENABLE_BOT || + event.eventType === EVENT_TYPES.DISABLE_BOT + ) { + switch (event.eventType) { + case EVENT_TYPES.ADD_BOT: { + thisObject.emitterUserProfile.addBot( + thisObject.botId, + thisObject.botAsset, + thisObject.botExchange + ) + break + } + case EVENT_TYPES.REMOVE_BOT: { + thisObject.emitterUserProfile.removeBot( + thisObject.botId + ) + break + } + case EVENT_TYPES.ENABLE_BOT: { + thisObject.emitterUserProfile.enableBot( + thisObject.botId + ) + break + } + case EVENT_TYPES.DISABLE_BOT: { + thisObject.emitterUserProfile.disableBot( + thisObject.botId + ) + break + } + } + return + } } } \ No newline at end of file diff --git a/Network/events.json b/Network/events.json deleted file mode 100644 index 6eb03cb88..000000000 --- a/Network/events.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "eventId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", - "eventType": 10, - "emitterUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", - "targetUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", - "asset": "BTC", - "timestamp": 124234234234, - "postHash": "dasdhqJKGdadjlasgjaGSHAJGSDjhagsg", - "postId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db" -} diff --git a/Network/graph.json b/Network/graph.json deleted file mode 100644 index a3bb947fa..000000000 --- a/Network/graph.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "userProfiles": [ - { - "username": "Luis-Fernando-Molina", - "id": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", - "posts": [ - { - "id": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", - "replyTo": "a8de78f0-c3e4-4a2a-b7e8-f659073969db" - } - ], - "replies": [ - { - "id": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", - "replyTo": "a8de78f0-c3e4-4a2a-b7e8-f659073969db" - } - ] - } - ] -} \ No newline at end of file diff --git a/Network/profiles.json b/Network/profiles.json deleted file mode 100644 index fd6386178..000000000 --- a/Network/profiles.json +++ /dev/null @@ -1,22 +0,0 @@ -[ - { - "userProfile": "Luis-Fernando-Molina", - "id": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", - "followers": 0, - "following": 0, - "ranking": 0, - "joined": 123423423423, - "account": "asd23123aff23q2bcaa21447567" - }, - { - "userProfile": "Luis-Fernando-Molina", - "id": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", - "followers": 0, - "following": 0, - "ranking": 0, - "joined": 123423423423, - "account": "asd23123aff23q2bcaa21447567" - } -] - -// a map by userProfile would be needed. \ No newline at end of file diff --git a/Network/timeline.json b/Network/timeline.json deleted file mode 100644 index f7e9ab17c..000000000 --- a/Network/timeline.json +++ /dev/null @@ -1,27 +0,0 @@ -[ - { - "type": "post", - "timestamp": 12343242342, - "userProfile": "Luis-Fernando-Molina", - "hash": "dhaHSkjasdmwhdajSHSJhewshed" - }, - { - "type": "post", - "timestamp": 12343242342, - "userProfile": "Luis-Fernando-Molina", - "hash": "dhaHSkjasdmwhdajSHSJhewshed", - "relatedEvent": "daawerewdhkasdSdGHGjdsasd" - }, - { - "type": "trade", - "timestamp": 12343242342, - "userProfile": "Luis-Fernando-Molina", - "hash": "dhaHSkjasdmwhdajSHSJhewshed" - }, - { - "type": "post", - "timestamp": 12343242342, - "userProfile": "Luis-Fernando-Molina", - "hash": "dhaHSkjasdmwhdajSHSJhewshed" - } -] \ No newline at end of file diff --git a/Network/userProfile.js b/Network/userProfile.js index 476397d58..40208b147 100644 --- a/Network/userProfile.js +++ b/Network/userProfile.js @@ -16,14 +16,19 @@ exports.newUserProfile = function newUserProfile() { emitterEventsCount: undefined, targetEventsCount: undefined, postsCount: undefined, - addMultiMediaPostsFollowing: addMultiMediaPostsFollowing, - removeMultiMediaPostsFollowing: removeMultiMediaPostsFollowing, - addTradePostsFollowing: addTradePostsFollowing, + bots: undefined, + addMultiMediaPostsFollowing: addMultiMediaPostsFollowing, + removeMultiMediaPostsFollowing: removeMultiMediaPostsFollowing, + addTradePostsFollowing: addTradePostsFollowing, removeTradePostsFollowing: removeTradePostsFollowing, addMultiMediaPostsFollower: addMultiMediaPostsFollower, removeMultiMediaPostsFollower: removeMultiMediaPostsFollower, addTradePostsFollower: addTradePostsFollower, removeTradePostsFollower: removeTradePostsFollower, + addBot: addBot, + removeBot: removeBot, + enableBot: enableBot, + disableBot: disableBot, initialize: initialize, finalize: finalize } @@ -31,7 +36,13 @@ exports.newUserProfile = function newUserProfile() { return thisObject function finalize() { + thisObject.multiMediaPostsFollowing = undefined + thisObject.multiMediaPostsFollowers = undefined + thisObject.tradePostsFollowing = undefined + thisObject.tradePostsFollowers = undefined + + thisObject.bots = undefined } function initialize() { @@ -50,8 +61,9 @@ exports.newUserProfile = function newUserProfile() { thisObject.targetEventsCount = 0 thisObject.postsCount = 0 + thisObject.bots = new Map() } - + function addMultiMediaPostsFollowing( userProfile ) { @@ -123,4 +135,62 @@ exports.newUserProfile = function newUserProfile() { thisObject.tradePostsFollowersCount-- } } + + function addBot( + botId, + botAsset, + botExchange + ) { + if (thisObject.bots.get(botId) !== undefined) { + throw ('Bot Already Exists.') + } + + let bot = NT.modules.BOTS.newBot() + bot.initialize( + botId, + botAsset, + botExchange + ) + thisObject.bots.set(botId, bot) + } + + function removeBot( + botId + ) { + if (thisObject.bots.get(botId) === undefined) { + throw ('Bot Does Not Exist.') + } + + thisObject.bots.delete(botId) + } + + function enableBot( + botId + ) { + let bot = thisObject.bots.get(botId) + if (bot === undefined) { + throw ('Bot Does Not Exist.') + } + + if (bot.enabled === true) { + throw ('Bot Already Enabled.') + } + + bot.enabled = true + } + + function disableBot( + botId + ) { + let bot = thisObject.bots.get(botId) + 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 From 6c8f75d3e7acd06d8d60e38803fb0f1ea6408930 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 26 Aug 2021 16:44:39 +0200 Subject: [PATCH 3/6] Queries --- Network/NetwokNode.js | 20 +++--- Network/ProfileStatsQuery.js | 43 ++++++++++++ Network/Query.js | 63 +++++++++++++++++ Network/clientsInterface.js | 59 ++++++++++++++-- Network/event.js | 132 ++++++++++++++++------------------- Network/post.js | 12 ++-- Network/userProfile.js | 61 +++++++++++++++- 7 files changed, 296 insertions(+), 94 deletions(-) create mode 100644 Network/ProfileStatsQuery.js create mode 100644 Network/Query.js diff --git a/Network/NetwokNode.js b/Network/NetwokNode.js index ff93a2489..f7ed65049 100644 --- a/Network/NetwokNode.js +++ b/Network/NetwokNode.js @@ -5,17 +5,19 @@ global.NT = { USER_PROFILES: new Map(), // Here we will store the user profiles and their statistics. POSTS: new Map(), // This are all the posts we are keeping track of. EVENTS: new Map(), // This is the registry of all events received that prevents processing them more than once. - TIMELINE: [] // A time ordered list of Posts and Trades. + TIMELINE: [], // A time ordered list of Posts and Trades. + NETWORK_CLIENTS: [], // These are the Network Clients connected to this Network Node. + NETWORK_PEERS: [], // These are the Network Peers connected to this Network Node. }, modules: { - EVENT: require('./UserProfile.js'), + USER_PROFILE: require('./UserProfile.js'), EVENT: require('./Event.js'), POST: require('./Post.js'), - BOT: require('./Bot.js') + BOT: require('./Bot.js'), + QUERY: require('./Query.js'), + PROFILE_STATS_QUERY: require('./ProfileStatsQuery.js'), + PROFILE_POSTS_QUERY: require('./ProfilePostsQuery.js'), + POST_REPLIES_QUERY: require('./ProfileRepliesQuery.js'), + TIMELINE_CHUNK_QUERY: require('./TimelineChunkQuery.js') } -} - -/* - We will add this event to the timeline -*/ -NT.memory.TIMELINE.push() \ No newline at end of file +} \ No newline at end of file diff --git a/Network/ProfileStatsQuery.js b/Network/ProfileStatsQuery.js new file mode 100644 index 000000000..459cb7179 --- /dev/null +++ b/Network/ProfileStatsQuery.js @@ -0,0 +1,43 @@ +exports.newProfileStatsQuery = function newProfileStatsQuery() { + + let thisObject = { + profile: undefined, + execute: execute, + initialize: initialize, + finalize: finalize + } + + return thisObject + + function finalize() { + + } + + function initialize(queryReceived) { + + thisObject.profile = NT.memory.PROFILES.get(queryReceived.targetUserProfileId) + + if (thisObject.profile === undefined) { + throw ('Target User Profile Not Found.') + } + + } + + function execute() { + + return { + "userProfieId": thisObject.profile.userProfieId, + "githubUsername": thisObject.profile.githubUsername, + "blockchainAccount": thisObject.profile.blockchainAccount, + "ranking": thisObject.profile.ranking, + "multiMediaPostFollowingCount": thisObject.profile.multiMediaPostFollowingCount, + "multiMediaPostFollowersCount": thisObject.profile.multiMediaPostFollowersCount, + "tradePostsFollowingCount": thisObject.profile.tradePostsFollowingCount, + "tradePostsFollowersCount": thisObject.profile.tradePostsFollowersCount, + "emitterEventsCount": thisObject.profile.emitterEventsCount, + "targetEventsCount": thisObject.profile.targetEventsCount, + "postsCount": thisObject.profile.postsCount, + "botsCount": thisObject.profile.botsCount + } + } +} \ No newline at end of file diff --git a/Network/Query.js b/Network/Query.js new file mode 100644 index 000000000..a77806943 --- /dev/null +++ b/Network/Query.js @@ -0,0 +1,63 @@ +exports.newQuery = function newQuery() { + + let thisObject = { + query: undefined, + queryType: undefined, + execute: execute, + initialize: initialize, + finalize: finalize + } + + const QUERY_TYPES = { + + PROFILE_STATS: 0, + PROFILE_POSTS: 1, + POST_REPLIES: 2, + TIMELINE_CHUNK: 3 + + } + + return thisObject + + function finalize() { + thisObject.query = undefined + thisObject.queryType = undefined + } + + function initialize(queryReceived) { + + thisObject.queryType = queryReceived.queryType + + switch (thisObject.queryType) { + + case QUERY_TYPES.PROFILE_STATS: { + thisObject.query = NT.modules.PROFILE_STATS_QUERY.newProfileStatsQuery() + query.initialize(queryReceived) + break + } + + case QUERY_TYPES.PROFILE_POSTS: { + thisObject.query = NT.modules.PROFILE_POSTS_QUERY.newProfileStatsQuery() + query.initialize(queryReceived) + break + } + + case QUERY_TYPES.POST_REPLIES: { + thisObject.query = NT.modules.POST_REPLIES_QUERY.newProfileStatsQuery() + query.initialize(queryReceived) + break + } + + case QUERY_TYPES.TIMELINE_CHUNK: { + thisObject.query = NT.modules.TIMELINE_CHUNK_QUERY.newProfileStatsQuery() + query.initialize(queryReceived) + break + } + default: throw('Query Type Not Supported.') + } + } + + function execute() { + return thisObject.query.execute() + } +} \ No newline at end of file diff --git a/Network/clientsInterface.js b/Network/clientsInterface.js index 09f12e545..d5d222802 100644 --- a/Network/clientsInterface.js +++ b/Network/clientsInterface.js @@ -1,9 +1,10 @@ exports.newClientInterface = function newClientInterface() { let thisObject = { + eventReceived: eventReceived, + queryReceived: queryReceived, initialize: initialize, - finalize: finalize, - run: run + finalize: finalize } return thisObject @@ -16,7 +17,55 @@ exports.newClientInterface = function newClientInterface() { } - function run() { - - } + function eventReceived(eventMessage) { + /* + We expect here a JSON string with the following properties: + + { + "eventId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", + "eventType": 10, + "emitterUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", + "targetUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", + "emitterPostHash": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", + "targetPostHash": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", + "timestamp": 124234234234, + "botId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", + "botAsset": "BTC", + "botExchange": "Binance" + } + */ + + let eventReceived = JSON.parse(eventMessage) + if (NT.memory.EVENTS.get(eventReceived.eventId) !== undefined) { + throw ('Event Already Exists.') + } + + let event = NT.modules.EVENT.newEvent() + event.initialize(eventReceived) + NT.memory.EVENTS.set(eventReceived.eventId, event) + } + + function queryReceived(queryMessage) { + /* + We expect here a JSON string with the following properties: + + { + "equeryId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", + "queryType": 10, + "emitterUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", + "targetUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", + "emitterPostHash": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", + "targetPostHash": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", + "timestamp": 124234234234, + "botId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", + "botAsset": "BTC", + "botExchange": "Binance" + } + */ + + let queryReceived = JSON.parse(queryMessage) + let query = NT.modules.QUERY.newQuery() + query.initialize(queryReceived) + return query.execute() + } } \ No newline at end of file diff --git a/Network/event.js b/Network/event.js index fe2311e53..4e4785d39 100644 --- a/Network/event.js +++ b/Network/event.js @@ -56,38 +56,20 @@ exports.newEvent = function newEvent() { thisObject.targetUserProfile = undefined } - function initialize(eventMessage) { - /* - We expect here a JSON string with the following properties: + function initialize(eventReceived) { - { - "eventId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", - "eventType": 10, - "emitterUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", - "targetUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", - "emitterPostHash": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", - "targetPostHash": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", - "timestamp": 124234234234, - "botId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", - "botAsset": "BTC", - "botExchange": "Binance" - } - */ - - let event = JSON.parse(eventMessage) - - thisObject.emitterUserProfile = NT.memory.USER_PROFILES.get(event.emitterUserProfileId) + thisObject.emitterUserProfile = NT.memory.USER_PROFILES.get(eventReceived.emitterUserProfileId) if (thisObject.emitterUserProfile === undefined) { throw ('Emitter User Profile Not Found.') } thisObject.emitterUserProfile.emitterEventsCount++ - thisObject.targetUserProfile = NT.memory.USER_PROFILES.get(event.targetUserProfileId) + thisObject.targetUserProfile = NT.memory.USER_PROFILES.get(eventReceived.targetUserProfileId) if (thisObject.targetUserProfile === undefined) { /* We thow an exception when it does not have a target user profile and is required*/ if ( - event.eventType !== EVENT_TYPES.NEW_MULTI_MEDIA_POST && - event.eventType !== EVENT_TYPES.NEW_TRADE_POST + eventReceived.eventType !== EVENT_TYPES.NEW_MULTI_MEDIA_POST && + eventReceived.eventType !== EVENT_TYPES.NEW_TRADE_POST ) { throw ('Target User Profile Not Found.') } @@ -95,44 +77,50 @@ exports.newEvent = function newEvent() { thisObject.targetUserProfile.targetEventsCount++ } - thisObject.eventId = event.eventId - thisObject.eventType = event.eventType - thisObject.asset = event.asset - thisObject.timestamp = event.timestamp + thisObject.eventId = eventReceived.eventId + thisObject.eventType = eventReceived.eventType + thisObject.asset = eventReceived.asset + thisObject.timestamp = eventReceived.timestamp /* Is is a new post? */ if ( - event.eventType === EVENT_TYPES.NEW_MULTI_MEDIA_POST || - event.eventType === EVENT_TYPES.REPLY_TO_MULTI_MEDIA_POST || - event.eventType === EVENT_TYPES.REPOST_MULTI_MEDIA || - event.eventType === EVENT_TYPES.QUOTE_REPOST_MULTI_MEDIA || - event.eventType === EVENT_TYPES.NEW_TRADE_POST || - event.eventType === EVENT_TYPES.REPLY_TO_TRADE_POST || - event.eventType === EVENT_TYPES.RE_POST_TRADE || - event.eventType === EVENT_TYPES.QUOTE_REPOST_TRADE + eventReceived.eventType === EVENT_TYPES.NEW_MULTI_MEDIA_POST || + eventReceived.eventType === EVENT_TYPES.REPLY_TO_MULTI_MEDIA_POST || + eventReceived.eventType === EVENT_TYPES.REPOST_MULTI_MEDIA || + eventReceived.eventType === EVENT_TYPES.QUOTE_REPOST_MULTI_MEDIA || + eventReceived.eventType === EVENT_TYPES.NEW_TRADE_POST || + eventReceived.eventType === EVENT_TYPES.REPLY_TO_TRADE_POST || + eventReceived.eventType === EVENT_TYPES.RE_POST_TRADE || + eventReceived.eventType === EVENT_TYPES.QUOTE_REPOST_TRADE ) { - let post = NT.modules.POST.newPost() - post.initialize( - event.emitterPostHash, - event.targetPostHash, - thisObject.eventType, - thisObject.emitterUserProfile, - thisObject.asset, - thisObject.timestamp - ) + if ( + eventReceived.eventType === EVENT_TYPES.NEW_MULTI_MEDIA_POST || + eventReceived.eventType === EVENT_TYPES.REPLY_TO_MULTI_MEDIA_POST || + eventReceived.eventType === EVENT_TYPES.REPOST_MULTI_MEDIA || + eventReceived.eventType === EVENT_TYPES.QUOTE_REPOST_MULTI_MEDIA + ) { + thisObject.emitterUserProfile.addPost( + eventReceived.emitterPostHash, + eventReceived.targetPostHash, + thisObject.eventType, + thisObject.emitterUserProfile, + thisObject.timestamp + ) + } + return } /* Is is a following? */ if ( - event.eventType === EVENT_TYPES.FOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS || - event.eventType === EVENT_TYPES.UNFOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS || - event.eventType === EVENT_TYPES.FOLLOW_USER_PROFILE_TRADE_POSTS || - event.eventType === EVENT_TYPES.UNFOLLOW_USER_PROFILE_TRADE_POSTS + eventReceived.eventType === EVENT_TYPES.FOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS || + eventReceived.eventType === EVENT_TYPES.UNFOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS || + eventReceived.eventType === EVENT_TYPES.FOLLOW_USER_PROFILE_TRADE_POSTS || + eventReceived.eventType === EVENT_TYPES.UNFOLLOW_USER_PROFILE_TRADE_POSTS ) { - switch (event.eventType) { + switch (eventReceived.eventType) { case EVENT_TYPES.FOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS: { thisObject.emitterUserProfile.addMultiMediaPostsFollowing( thisObject.targetUserProfile @@ -176,51 +164,51 @@ exports.newEvent = function newEvent() { Is is a Reaction? */ if ( - event.eventType === EVENT_TYPES.ADD_REACTION_LIKE || - event.eventType === EVENT_TYPES.ADD_REACTION_LOVE || - event.eventType === EVENT_TYPES.ADD_REACTION_HAHA || - event.eventType === EVENT_TYPES.ADD_REACTION_WOW || - event.eventType === EVENT_TYPES.ADD_REACTION_SAD || - event.eventType === EVENT_TYPES.ADD_REACTION_ANGRY || - event.eventType === EVENT_TYPES.ADD_REACTION_HUG + eventReceived.eventType === EVENT_TYPES.ADD_REACTION_LIKE || + eventReceived.eventType === EVENT_TYPES.ADD_REACTION_LOVE || + eventReceived.eventType === EVENT_TYPES.ADD_REACTION_HAHA || + eventReceived.eventType === EVENT_TYPES.ADD_REACTION_WOW || + eventReceived.eventType === EVENT_TYPES.ADD_REACTION_SAD || + eventReceived.eventType === EVENT_TYPES.ADD_REACTION_ANGRY || + eventReceived.eventType === EVENT_TYPES.ADD_REACTION_HUG ) { - let targetPost = NT.memory.POSTS.get(event.targetPostHash) + let targetPost = NT.memory.POSTS.get(eventReceived.targetPostHash) if (targetPost === undefined) { throw ('Target Post Not Found') } - targetPost.addReaction(event.eventType - 100) + targetPost.addReaction(eventReceived.eventType - 100) return } if ( - event.eventType === EVENT_TYPES.REMOVE_REACTION_LIKE || - event.eventType === EVENT_TYPES.REMOVE_REACTION_LOVE || - event.eventType === EVENT_TYPES.REMOVE_REACTION_HAHA || - event.eventType === EVENT_TYPES.REMOVE_REACTION_WOW || - event.eventType === EVENT_TYPES.REMOVE_REACTION_SAD || - event.eventType === EVENT_TYPES.REMOVE_REACTION_ANGRY || - event.eventType === EVENT_TYPES.REMOVE_REACTION_HUG + eventReceived.eventType === EVENT_TYPES.REMOVE_REACTION_LIKE || + eventReceived.eventType === EVENT_TYPES.REMOVE_REACTION_LOVE || + eventReceived.eventType === EVENT_TYPES.REMOVE_REACTION_HAHA || + eventReceived.eventType === EVENT_TYPES.REMOVE_REACTION_WOW || + eventReceived.eventType === EVENT_TYPES.REMOVE_REACTION_SAD || + eventReceived.eventType === EVENT_TYPES.REMOVE_REACTION_ANGRY || + eventReceived.eventType === EVENT_TYPES.REMOVE_REACTION_HUG ) { - let targetPost = NT.memory.POSTS.get(event.targetPostHash) + let targetPost = NT.memory.POSTS.get(eventReceived.targetPostHash) if (targetPost === undefined) { throw ('Target Post Not Found') } - targetPost.removeReaction(event.eventType - 200) + targetPost.removeReaction(eventReceived.eventType - 200) return } /* Is is a Bot? */ if ( - event.eventType === EVENT_TYPES.ADD_BOT || - event.eventType === EVENT_TYPES.REMOVE_BOT || - event.eventType === EVENT_TYPES.ENABLE_BOT || - event.eventType === EVENT_TYPES.DISABLE_BOT + eventReceived.eventType === EVENT_TYPES.ADD_BOT || + eventReceived.eventType === EVENT_TYPES.REMOVE_BOT || + eventReceived.eventType === EVENT_TYPES.ENABLE_BOT || + eventReceived.eventType === EVENT_TYPES.DISABLE_BOT ) { - switch (event.eventType) { + switch (eventReceived.eventType) { case EVENT_TYPES.ADD_BOT: { thisObject.emitterUserProfile.addBot( thisObject.botId, diff --git a/Network/post.js b/Network/post.js index 95bbe1eb1..809f70c0f 100644 --- a/Network/post.js +++ b/Network/post.js @@ -1,10 +1,10 @@ exports.newPost = function newPost() { let thisObject = { - postHash: undefined, + emitterPostHash: undefined, + targetPostHash: undefined, postType: undefined, userProfile: undefined, - asset: undefined, timestamp: undefined, replies: undefined, targetPost: undefined, @@ -48,10 +48,10 @@ exports.newPost = function newPost() { return thisObject function finalize() { - thisObject.postHash = undefined + thisObject.emitterPostHash = undefined + thisObject.targetPostHash = undefined thisObject.postType = undefined thisObject.userProfile = undefined - thisObject.asset = undefined thisObject.timestamp = undefined thisObject.replies = undefined thisObject.targetPost = undefined @@ -62,7 +62,6 @@ exports.newPost = function newPost() { targetPostHash, postType, userProfile, - asset, timestamp ) { @@ -70,8 +69,9 @@ exports.newPost = function newPost() { thisObject.targetPostHash = targetPostHash thisObject.postType = postType thisObject.userProfile = userProfile - thisObject.asset = asset thisObject.timestamp = timestamp + + thisObject.replies = [] /* Let's find the Target Post */ diff --git a/Network/userProfile.js b/Network/userProfile.js index 40208b147..ec935aabf 100644 --- a/Network/userProfile.js +++ b/Network/userProfile.js @@ -16,7 +16,11 @@ exports.newUserProfile = function newUserProfile() { emitterEventsCount: undefined, targetEventsCount: undefined, postsCount: undefined, + botsCount: undefined, bots: undefined, + posts: undefined, + addPost: addPost, + removePost: removePost, addMultiMediaPostsFollowing: addMultiMediaPostsFollowing, removeMultiMediaPostsFollowing: removeMultiMediaPostsFollowing, addTradePostsFollowing: addTradePostsFollowing, @@ -42,6 +46,7 @@ exports.newUserProfile = function newUserProfile() { thisObject.tradePostsFollowing = undefined thisObject.tradePostsFollowers = undefined + thisObject.posts = undefined thisObject.bots = undefined } @@ -60,8 +65,58 @@ exports.newUserProfile = function newUserProfile() { thisObject.emitterEventsCount = 0 thisObject.targetEventsCount = 0 thisObject.postsCount = 0 + thisObject.botsCount = 0 - thisObject.bots = new Map() + thisObject.posts = undefined + thisObject.bots = undefined + } + + function addPost( + emitterPostHash, + targetPostHash, + postType, + userProfile, + timestamp + ) { + if (thisObject.posts.get(emitterPostHash) !== undefined) { + throw ('Post Already Exists.') + } + + if (NT.memory.POSTS.get(emitterPostHash) !== undefined) { + throw ('Post Already Exists.') + } + + let post = NT.modules.POST.newPost() + post.initialize( + emitterPostHash, + targetPostHash, + postType, + userProfile, + timestamp + ) + + thisObject.posts.set(emitterPostHash, post) + NT.memory.POSTS.set(emitterPostHash, post) + thisObject.postsCount++ + } + + function removePost( + emitterPostHash + ) { + if (thisObject.posts.get(emitterPostHash) === undefined) { + throw ('Post Does Not Exist.') + } + + if (NT.memory.POSTS.get(emitterPostHash) === undefined) { + throw ('Post Does Not Exist.') + } + + let post = thisObject.posts.get(emitterPostHash) + post.finalize() + + thisObject.posts.delete(emitterPostHash) + NT.memory.POSTS.delete(emitterPostHash) + thisObject.postsCount-- } function addMultiMediaPostsFollowing( @@ -152,6 +207,7 @@ exports.newUserProfile = function newUserProfile() { botExchange ) thisObject.bots.set(botId, bot) + thisObject.botsCount++ } function removeBot( @@ -160,8 +216,9 @@ exports.newUserProfile = function newUserProfile() { if (thisObject.bots.get(botId) === undefined) { throw ('Bot Does Not Exist.') } - + thisObject.bots.get(botId).finalize() thisObject.bots.delete(botId) + thisObject.botsCount-- } function enableBot( From dba49aa67d9d0c7cd936a38081e115482ef4a1ee Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 26 Aug 2021 16:54:05 +0200 Subject: [PATCH 4/6] Profile Handle --- Network/NetwokNode.js | 13 +++++++------ Network/ProfileStatsQuery.js | 10 +++++++--- Network/clientsInterface.js | 2 ++ Network/event.js | 4 ++-- Network/userProfile.js | 2 +- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Network/NetwokNode.js b/Network/NetwokNode.js index f7ed65049..4bb49d8da 100644 --- a/Network/NetwokNode.js +++ b/Network/NetwokNode.js @@ -2,12 +2,13 @@ global.NT = { memory: { - USER_PROFILES: new Map(), // Here we will store the user profiles and their statistics. - POSTS: new Map(), // This are all the posts we are keeping track of. - EVENTS: new Map(), // This is the registry of all events received that prevents processing them more than once. - TIMELINE: [], // A time ordered list of Posts and Trades. - NETWORK_CLIENTS: [], // These are the Network Clients connected to this Network Node. - NETWORK_PEERS: [], // These are the Network Peers connected to this Network Node. + USER_PROFILES_BY_ID: new Map(), // Here we will store the user profiles by User Profile Id. + USER_PROFILES_BY_HANDLE: new Map(), // Here we will store the user profiles by User Profile Handle. + POSTS: new Map(), // This are all the posts we are keeping track of. + EVENTS: new Map(), // This is the registry of all events received that prevents processing them more than once. + TIMELINE: [], // A time ordered list of Posts and Trades. + NETWORK_CLIENTS: [], // These are the Network Clients connected to this Network Node. + NETWORK_PEERS: [], // These are the Network Peers connected to this Network Node. }, modules: { USER_PROFILE: require('./UserProfile.js'), diff --git a/Network/ProfileStatsQuery.js b/Network/ProfileStatsQuery.js index 459cb7179..2de22735e 100644 --- a/Network/ProfileStatsQuery.js +++ b/Network/ProfileStatsQuery.js @@ -15,8 +15,12 @@ exports.newProfileStatsQuery = function newProfileStatsQuery() { function initialize(queryReceived) { - thisObject.profile = NT.memory.PROFILES.get(queryReceived.targetUserProfileId) - + if (queryReceived.targetUserProfileId !== undefined) { + thisObject.profile = NT.memory.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) + } else { + thisObject.profile = NT.memory.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileHandle) + } + if (thisObject.profile === undefined) { throw ('Target User Profile Not Found.') } @@ -27,7 +31,7 @@ exports.newProfileStatsQuery = function newProfileStatsQuery() { return { "userProfieId": thisObject.profile.userProfieId, - "githubUsername": thisObject.profile.githubUsername, + "userHandle": thisObject.profile.userHandle, "blockchainAccount": thisObject.profile.blockchainAccount, "ranking": thisObject.profile.ranking, "multiMediaPostFollowingCount": thisObject.profile.multiMediaPostFollowingCount, diff --git a/Network/clientsInterface.js b/Network/clientsInterface.js index d5d222802..4f25230c6 100644 --- a/Network/clientsInterface.js +++ b/Network/clientsInterface.js @@ -54,6 +54,8 @@ exports.newClientInterface = function newClientInterface() { "queryType": 10, "emitterUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", "targetUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", + "emitterUserProfileHandle": "Luis-Fernando-Molina", + "targetUserProfileHandle": "Luis-Fernando-Molina", "emitterPostHash": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", "targetPostHash": "a8de78f0-c3e4-4a2a-b7e8-f659073969db", "timestamp": 124234234234, diff --git a/Network/event.js b/Network/event.js index 4e4785d39..50988a5c7 100644 --- a/Network/event.js +++ b/Network/event.js @@ -58,13 +58,13 @@ exports.newEvent = function newEvent() { function initialize(eventReceived) { - thisObject.emitterUserProfile = NT.memory.USER_PROFILES.get(eventReceived.emitterUserProfileId) + thisObject.emitterUserProfile = NT.memory.USER_PROFILES_BY_ID.get(eventReceived.emitterUserProfileId) if (thisObject.emitterUserProfile === undefined) { throw ('Emitter User Profile Not Found.') } thisObject.emitterUserProfile.emitterEventsCount++ - thisObject.targetUserProfile = NT.memory.USER_PROFILES.get(eventReceived.targetUserProfileId) + thisObject.targetUserProfile = NT.memory.USER_PROFILES_BY_ID.get(eventReceived.targetUserProfileId) if (thisObject.targetUserProfile === undefined) { /* We thow an exception when it does not have a target user profile and is required*/ if ( diff --git a/Network/userProfile.js b/Network/userProfile.js index ec935aabf..ab4a3fe50 100644 --- a/Network/userProfile.js +++ b/Network/userProfile.js @@ -2,7 +2,7 @@ exports.newUserProfile = function newUserProfile() { let thisObject = { userProfieId: undefined, - githubUsername: undefined, + userHandle: undefined, blockchainAccount: undefined, multiMediaPostsFollowing: undefined, multiMediaPostsFollowers: undefined, From 685c2b30d6b8e954f81e2ac0412503c72596b177 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 26 Aug 2021 18:20:07 +0200 Subject: [PATCH 5/6] Profile Posts Query Implemented --- Network/NetwokNode.js | 8 +- Network/Queries/ProfilePosts.js | 122 ++++++++++++++++++ .../ProfileStats.js} | 10 +- Network/Query.js | 8 +- Network/post.js | 3 + Network/userProfile.js | 21 ++- 6 files changed, 148 insertions(+), 24 deletions(-) create mode 100644 Network/Queries/ProfilePosts.js rename Network/{ProfileStatsQuery.js => Queries/ProfileStats.js} (83%) diff --git a/Network/NetwokNode.js b/Network/NetwokNode.js index 4bb49d8da..20a2d0fef 100644 --- a/Network/NetwokNode.js +++ b/Network/NetwokNode.js @@ -16,9 +16,9 @@ global.NT = { POST: require('./Post.js'), BOT: require('./Bot.js'), QUERY: require('./Query.js'), - PROFILE_STATS_QUERY: require('./ProfileStatsQuery.js'), - PROFILE_POSTS_QUERY: require('./ProfilePostsQuery.js'), - POST_REPLIES_QUERY: require('./ProfileRepliesQuery.js'), - TIMELINE_CHUNK_QUERY: require('./TimelineChunkQuery.js') + QUERY_PROFILE_STATS: require('./Queries/ProfileStats.js'), + QUERY_PROFILE_POSTS: require('./Queries/ProfilePosts.js'), + QUERY_POST_REPLIES: require('./Queries/ProfileReplies.js'), + QUERY_TIMELINE_CHUNK: require('./Queries/TimelineChunk.js') } } \ No newline at end of file diff --git a/Network/Queries/ProfilePosts.js b/Network/Queries/ProfilePosts.js new file mode 100644 index 000000000..e80302005 --- /dev/null +++ b/Network/Queries/ProfilePosts.js @@ -0,0 +1,122 @@ +exports.newProfilePosts = function newProfilePosts() { + + let thisObject = { + profile: undefined, + initialPostIndex: 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() { + + } + + function initialize(queryReceived) { + /* + Validate User Profile + */ + if (queryReceived.targetUserProfileId !== undefined) { + thisObject.profile = NT.memory.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) + } else { + thisObject.profile = NT.memory.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle) + } + + if (thisObject.profile === undefined) { + throw ('Target User Profile Not Found.') + } + /* + Validate Initial Post Index + */ + if (queryReceived.initialPostIndex === undefined) { + throw ('Initial Post Index Undefined.') + } + + if (queryReceived.initialPostIndex === INITIAL_POST_INDEX_LAST) { + queryReceived.initialPostIndex = thisObject.posts.length - 1 + } + + if (queryReceived.initialPostIndex === INITIAL_POST_INDEX_FIRST) { + queryReceived.initialPostIndex = 0 + } + + if (isNaN(queryReceived.initialPostIndex) === true) { + throw ('Initial Post Is Not a Number.') + } + + thisObject.initialPostIndex = queryReceived.initialPostIndex + /* + 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 Amount Requested + */ + 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.initialPostIndex; i < thisObject.initialPostIndex + thisObject.amountRequested; i++) { + let post = thisObject.profile.posts[i] + if (post === undefined) { break } + + let postResponse = { + "emitterPostHash": post.emitterPostHash, + "targetPostHash": post.targetPostHash, + "postType": post.postType, + "userProfile": post.userProfile.userProfieId, + "timestamp": post.timestamp, + "repliesCount": post.replies.length, + "targetPostHash": post.targetPost.emitterPostHash, + "reactionsCount": [] + } + + for (let i = 0; i < post.reactionTypesCount; i++) { + postResponse.reactionsCount.push(post.reactionsCount.get(i)) + } + + response.push(postResponse) + } + } + } + return response + } +} \ No newline at end of file diff --git a/Network/ProfileStatsQuery.js b/Network/Queries/ProfileStats.js similarity index 83% rename from Network/ProfileStatsQuery.js rename to Network/Queries/ProfileStats.js index 2de22735e..f4bb73e19 100644 --- a/Network/ProfileStatsQuery.js +++ b/Network/Queries/ProfileStats.js @@ -1,4 +1,4 @@ -exports.newProfileStatsQuery = function newProfileStatsQuery() { +exports.newProfileStats = function newProfileStats() { let thisObject = { profile: undefined, @@ -14,11 +14,13 @@ exports.newProfileStatsQuery = function newProfileStatsQuery() { } function initialize(queryReceived) { - + /* + Validate User Profile + */ if (queryReceived.targetUserProfileId !== undefined) { thisObject.profile = NT.memory.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) } else { - thisObject.profile = NT.memory.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileHandle) + thisObject.profile = NT.memory.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle) } if (thisObject.profile === undefined) { @@ -31,7 +33,7 @@ exports.newProfileStatsQuery = function newProfileStatsQuery() { return { "userProfieId": thisObject.profile.userProfieId, - "userHandle": thisObject.profile.userHandle, + "userProfileHandle": thisObject.profile.userProfileHandle, "blockchainAccount": thisObject.profile.blockchainAccount, "ranking": thisObject.profile.ranking, "multiMediaPostFollowingCount": thisObject.profile.multiMediaPostFollowingCount, diff --git a/Network/Query.js b/Network/Query.js index a77806943..aa852b0e6 100644 --- a/Network/Query.js +++ b/Network/Query.js @@ -31,25 +31,25 @@ exports.newQuery = function newQuery() { switch (thisObject.queryType) { case QUERY_TYPES.PROFILE_STATS: { - thisObject.query = NT.modules.PROFILE_STATS_QUERY.newProfileStatsQuery() + thisObject.query = NT.modules.QUERY_PROFILE_STATS.newProfileStats() query.initialize(queryReceived) break } case QUERY_TYPES.PROFILE_POSTS: { - thisObject.query = NT.modules.PROFILE_POSTS_QUERY.newProfileStatsQuery() + thisObject.query = NT.modules.QUERY_PROFILE_POSTS.newProfilePosts() query.initialize(queryReceived) break } case QUERY_TYPES.POST_REPLIES: { - thisObject.query = NT.modules.POST_REPLIES_QUERY.newProfileStatsQuery() + thisObject.query = NT.modules.QUERY_POST_REPLIES.newPostReplies() query.initialize(queryReceived) break } case QUERY_TYPES.TIMELINE_CHUNK: { - thisObject.query = NT.modules.TIMELINE_CHUNK_QUERY.newProfileStatsQuery() + thisObject.query = NT.modules.QUERY_TIMELINE_CHUNK.newTimelineChunk() query.initialize(queryReceived) break } diff --git a/Network/post.js b/Network/post.js index 809f70c0f..97509e6e3 100644 --- a/Network/post.js +++ b/Network/post.js @@ -9,6 +9,7 @@ exports.newPost = function newPost() { replies: undefined, targetPost: undefined, reactionsCount: undefined, + reactionTypesCount: undefined, addReaction: addReaction, removeReactions: removeReaction, initialize: initialize, @@ -36,6 +37,8 @@ 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) diff --git a/Network/userProfile.js b/Network/userProfile.js index ab4a3fe50..d1f2863e1 100644 --- a/Network/userProfile.js +++ b/Network/userProfile.js @@ -2,7 +2,7 @@ exports.newUserProfile = function newUserProfile() { let thisObject = { userProfieId: undefined, - userHandle: undefined, + userProfileHandle: undefined, blockchainAccount: undefined, multiMediaPostsFollowing: undefined, multiMediaPostsFollowers: undefined, @@ -67,7 +67,7 @@ exports.newUserProfile = function newUserProfile() { thisObject.postsCount = 0 thisObject.botsCount = 0 - thisObject.posts = undefined + thisObject.posts = [] thisObject.bots = undefined } @@ -78,10 +78,6 @@ exports.newUserProfile = function newUserProfile() { userProfile, timestamp ) { - if (thisObject.posts.get(emitterPostHash) !== undefined) { - throw ('Post Already Exists.') - } - if (NT.memory.POSTS.get(emitterPostHash) !== undefined) { throw ('Post Already Exists.') } @@ -95,7 +91,7 @@ exports.newUserProfile = function newUserProfile() { timestamp ) - thisObject.posts.set(emitterPostHash, post) + thisObject.posts.push(post) NT.memory.POSTS.set(emitterPostHash, post) thisObject.postsCount++ } @@ -103,10 +99,6 @@ exports.newUserProfile = function newUserProfile() { function removePost( emitterPostHash ) { - if (thisObject.posts.get(emitterPostHash) === undefined) { - throw ('Post Does Not Exist.') - } - if (NT.memory.POSTS.get(emitterPostHash) === undefined) { throw ('Post Does Not Exist.') } @@ -114,7 +106,12 @@ exports.newUserProfile = function newUserProfile() { let post = thisObject.posts.get(emitterPostHash) post.finalize() - thisObject.posts.delete(emitterPostHash) + for (let i = thisObject.posts.length - 1; i >= 0; i-- { + if (thisObject.posts[i].emitterPostHash === emitterPostHash) { + thisObject.posts.splice(i, 1) + break + } + } NT.memory.POSTS.delete(emitterPostHash) thisObject.postsCount-- } From 2aa4eebc909f90f94ed29264600b69488fbd1624 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 26 Aug 2021 18:37:02 +0200 Subject: [PATCH 6/6] Governance: More Delegation --- .../User-Profiles/Luis-Fernando-Molina.json | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json b/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json index 2cdfb8bee..dbedf69ff 100644 --- a/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json +++ b/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json @@ -539,7 +539,7 @@ "votesAndClaimsPrograms": { "type": "Votes And Claims Programs", "name": "New Votes And Claims Programs", - "config": "{\n \"percentage\": 50\n}", + "config": "{\n \"percentage\": 10\n}", "project": "Governance", "votingProgram": { "type": "Voting Program", @@ -12078,7 +12078,7 @@ "floatingObject": { "isPinned": false, "isFrozen": false, - "isCollapsed": false, + "isCollapsed": true, "angleToParent": 2, "distanceToParent": 3, "arrangementStyle": 0 @@ -12435,7 +12435,7 @@ "floatingObject": { "isPinned": false, "isFrozen": false, - "isCollapsed": true, + "isCollapsed": false, "angleToParent": 2, "distanceToParent": 3, "arrangementStyle": 0 @@ -12471,7 +12471,7 @@ "financialPrograms": { "type": "Financial Programs", "name": "New Financial Programs", - "config": "{\n \"percentage\": 30\n}", + "config": "{\n \"percentage\": 70\n}", "project": "Governance", "stakingProgram": { "type": "Staking Program", @@ -12543,7 +12543,7 @@ { "type": "Delegate Power Switch", "name": "Phill", - "config": "{\n \"percentage\": 30\n}", + "config": "{\n \"percentage\": 35\n}", "project": "Governance", "delegatePowerSwitch": [], "userDelegates": [ @@ -12759,7 +12759,7 @@ { "type": "Delegate Power Switch", "name": "Carl", - "config": "{\n \"percentage\": 5\n}", + "config": "{\n \"percentage\": 0\n}", "project": "Governance", "delegatePowerSwitch": [], "userDelegates": [ @@ -12797,7 +12797,9 @@ "referenceParentCombinedNodePath": [ [ "cozed-gh", - "User Profile" + "User Profile", + "Governance", + "07f0b13a-a50f-4488-8a2c-a3f8f08e889d" ] ] } @@ -13162,7 +13164,7 @@ "floatingObject": { "isPinned": false, "isFrozen": false, - "isCollapsed": true, + "isCollapsed": false, "angleToParent": 1, "distanceToParent": 3, "arrangementStyle": 0