From 78ea072b9ff836b1ff833523150cea5929e83f6c Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 27 Aug 2021 20:50:53 +0200 Subject: [PATCH] Post.js supports Users and Bots --- Network/botProfile.js | 5 --- Network/event.js | 76 +++++++++++++++++++++++------------------- Network/post.js | 32 +++++++++--------- Network/userProfile.js | 8 ++++- 4 files changed, 64 insertions(+), 57 deletions(-) diff --git a/Network/botProfile.js b/Network/botProfile.js index 31871927c..643571170 100644 --- a/Network/botProfile.js +++ b/Network/botProfile.js @@ -13,8 +13,6 @@ exports.newUserProfile = function newUserProfile() { emitterEventsCount: undefined, targetEventsCount: undefined, postsCount: undefined, - botsCount: undefined, - bots: undefined, posts: undefined, addPost: addPost, removePost: removePost, @@ -33,7 +31,6 @@ exports.newUserProfile = function newUserProfile() { thisObject.followers = undefined thisObject.posts = undefined - thisObject.bots = undefined } function initialize() { @@ -47,10 +44,8 @@ exports.newUserProfile = function newUserProfile() { thisObject.emitterEventsCount = 0 thisObject.targetEventsCount = 0 thisObject.postsCount = 0 - thisObject.botsCount = 0 thisObject.posts = [] - thisObject.bots = undefined } function addPost( diff --git a/Network/event.js b/Network/event.js index ea61143ba..7cddc9c22 100644 --- a/Network/event.js +++ b/Network/event.js @@ -4,6 +4,8 @@ exports.newEvent = function newEvent() { eventId: undefined, emitterUserProfileId: undefined, targetUserProfileId: undefined, + emitterBotProfileId: undefined, + targetBotProfileId: undefined, emitterPostHash: undefined, targetPostHash: undefined, timestamp: undefined, @@ -16,19 +18,19 @@ 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_USER_POST: 10, + REPLY_TO_USER_POST: 11, + REPOST_USER_POST: 12, + QUOTE_REPOST_USER_POST: 13, + FOLLOW_USER_PROFILE: 14, + UNFOLLOW_USER_PROFILE: 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, + NEW_BOT_POST: 20, + REPLY_TO_BOT_POST: 21, + REPOST_BOT_POST: 22, + QUOTE_REPOST_BOT_POST: 23, + FOLLOW_BOT_PROFILE: 24, + UNFOLLOW_BOT_PROFILE: 25, ADD_BOT: 50, REMOVE_BOT: 51, @@ -66,6 +68,8 @@ exports.newEvent = function newEvent() { thisObject.eventId = eventReceived.eventId thisObject.emitterUserProfileId = eventReceived.emitterUserProfileId thisObject.targetUserProfileId = eventReceived.targetUserProfileId + thisObject.emitterBotProfileId = eventReceived.emitterBotProfileId + thisObject.targetBotProfileId = eventReceived.targetBotProfileId thisObject.emitterPostHash = eventReceived.emitterPostHash thisObject.targetPostHash = eventReceived.targetPostHash thisObject.timestamp = eventReceived.timestamp @@ -87,8 +91,8 @@ exports.newEvent = function newEvent() { 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_MULTI_MEDIA_POST && - thisObject.eventType !== EVENT_TYPES.NEW_TRADE_POST + thisObject.eventType !== EVENT_TYPES.NEW_USER_POST && + thisObject.eventType !== EVENT_TYPES.NEW_BOT_POST ) { throw ('Target User Profile Not Found.') } @@ -99,27 +103,29 @@ exports.newEvent = function newEvent() { Is is a new post? */ if ( - thisObject.eventType === EVENT_TYPES.NEW_MULTI_MEDIA_POST || - thisObject.eventType === EVENT_TYPES.REPLY_TO_MULTI_MEDIA_POST || - thisObject.eventType === EVENT_TYPES.REPOST_MULTI_MEDIA || - thisObject.eventType === EVENT_TYPES.QUOTE_REPOST_MULTI_MEDIA || - thisObject.eventType === EVENT_TYPES.NEW_TRADE_POST || - thisObject.eventType === EVENT_TYPES.REPLY_TO_TRADE_POST || - thisObject.eventType === EVENT_TYPES.RE_POST_TRADE || - thisObject.eventType === EVENT_TYPES.QUOTE_REPOST_TRADE + 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 ) { if ( - thisObject.eventType === EVENT_TYPES.NEW_MULTI_MEDIA_POST || - thisObject.eventType === EVENT_TYPES.REPLY_TO_MULTI_MEDIA_POST || - thisObject.eventType === EVENT_TYPES.REPOST_MULTI_MEDIA || - thisObject.eventType === EVENT_TYPES.QUOTE_REPOST_MULTI_MEDIA + 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, + thisObject.eventType - 10, thisObject.timestamp ) } @@ -130,13 +136,13 @@ exports.newEvent = function newEvent() { Is is a following? */ if ( - thisObject.eventType === EVENT_TYPES.FOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS || - thisObject.eventType === EVENT_TYPES.UNFOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS || - thisObject.eventType === EVENT_TYPES.FOLLOW_USER_PROFILE_TRADE_POSTS || - thisObject.eventType === EVENT_TYPES.UNFOLLOW_USER_PROFILE_TRADE_POSTS + 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_MULTI_MEDIA_POSTS: { + case EVENT_TYPES.FOLLOW_USER_PROFILE: { emitterUserProfile.addFollowing( targetUserProfile ) @@ -145,7 +151,7 @@ exports.newEvent = function newEvent() { ) break } - case EVENT_TYPES.UNFOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS: { + case EVENT_TYPES.UNFOLLOW_USER_PROFILE: { emitterUserProfile.removeFollowing( targetUserProfile ) @@ -154,7 +160,7 @@ exports.newEvent = function newEvent() { ) break } - case EVENT_TYPES.FOLLOW_USER_PROFILE_TRADE_POSTS: { + case EVENT_TYPES.FOLLOW_BOT_PROFILE: { emitterUserProfile.addTradePostsFollowing( targetUserProfile ) @@ -163,7 +169,7 @@ exports.newEvent = function newEvent() { ) break } - case EVENT_TYPES.UNFOLLOW_USER_PROFILE_TRADE_POSTS: { + case EVENT_TYPES.UNFOLLOW_BOT_PROFILE: { emitterUserProfile.removeTradePostsFollowing( targetUserProfile ) diff --git a/Network/post.js b/Network/post.js index f3e3bd873..9b35c95cb 100644 --- a/Network/post.js +++ b/Network/post.js @@ -3,6 +3,8 @@ exports.newPost = function newPost() { let thisObject = { emitterUserProfileId: undefined, targetUserProfileId: undefined, + emitterBotProfileId: undefined, + targetBotProfileId: undefined, emitterPostHash: undefined, targetPostHash: undefined, postType: undefined, @@ -17,14 +19,10 @@ exports.newPost = function newPost() { } const POST_TYPES = { - NEW_MULTI_MEDIA_POST: 10, - REPLY_TO_MULTI_MEDIA_POST: 11, - REPOST_MULTI_MEDIA: 12, - QUOTE_REPOST_MULTI_MEDIA: 13, - NEW_TRADE_POST: 20, - REPLY_TO_TRADE_POST: 21, - RE_POST_TRADE: 22, - QUOTE_REPOST_TRADE: 23 + NEW_POST: 0, + REPLY_TO_POST: 1, + REPOST_: 2, + QUOTE_REPOST_: 3 } const REACTION_TYPES = { @@ -53,6 +51,8 @@ exports.newPost = function newPost() { function finalize() { thisObject.emitterUserProfileId = undefined thisObject.targetUserProfileId = undefined + thisObject.emitterBotProfileId = undefined + thisObject.targetBotProfileId = undefined thisObject.emitterPostHash = undefined thisObject.targetPostHash = undefined thisObject.postType = undefined @@ -63,6 +63,8 @@ exports.newPost = function newPost() { function initialize( emitterUserProfileId, targetUserProfileId, + emitterBotProfileId, + targetBotProfileId, emitterPostHash, targetPostHash, postType, @@ -71,6 +73,8 @@ exports.newPost = function newPost() { thisObject.emitterUserProfileId = emitterUserProfileId thisObject.targetUserProfileId = targetUserProfileId + thisObject.emitterBotProfileId = emitterBotProfileId + thisObject.targetBotProfileId = targetBotProfileId thisObject.emitterPostHash = emitterPostHash thisObject.targetPostHash = targetPostHash thisObject.postType = postType @@ -83,12 +87,9 @@ exports.newPost = function newPost() { let targetPost if ( - event.eventType === POST_TYPES.REPLY_TO_MULTI_MEDIA_POST || - event.eventType === POST_TYPES.REPOST_MULTI_MEDIA || - event.eventType === POST_TYPES.QUOTE_REPOST_MULTI_MEDIA || - event.eventType === POST_TYPES.REPLY_TO_TRADE_POST || - event.eventType === POST_TYPES.RE_POST_TRADE || - event.eventType === POST_TYPES.QUOTE_REPOST_TRADE + thisObject.postType === POST_TYPES.REPLY_TO_POST || + thisObject.postType === POST_TYPES.REPOST_ || + thisObject.postType === POST_TYPES.QUOTE_REPOST_ ) { targetPost = NT.memory.maps.POSTS.get(thisObject.targetPostHash) @@ -100,8 +101,7 @@ exports.newPost = function newPost() { Let's add this post to the replies of the Target Post */ if ( - event.eventType === POST_TYPES.REPLY_TO_MULTI_MEDIA_POST || - event.eventType === POST_TYPES.REPLY_TO_TRADE_POST + thisObject.postType === POST_TYPES.REPLY_TO_POST ) { targetPost.replies.push(thisObject) } diff --git a/Network/userProfile.js b/Network/userProfile.js index cc0f8a315..a7d308cf6 100644 --- a/Network/userProfile.js +++ b/Network/userProfile.js @@ -53,10 +53,12 @@ exports.newUserProfile = function newUserProfile() { thisObject.botsCount = 0 thisObject.posts = [] - thisObject.bots = undefined + thisObject.bots = [] } function addPost( + emitterUserProfileId, + targetUserProfileId, emitterPostHash, targetPostHash, postType, @@ -69,6 +71,10 @@ exports.newUserProfile = function newUserProfile() { let post = NT.modules.POST.newPost() post.initialize( + emitterUserProfileId, + targetUserProfileId, + undefined, + undefined, emitterPostHash, targetPostHash, postType,