diff --git a/Network/botProfile.js b/Network/botProfile.js index a1c1b80c7..31871927c 100644 --- a/Network/botProfile.js +++ b/Network/botProfile.js @@ -1,11 +1,27 @@ -exports.newBot = function newBot() { +exports.newUserProfile = function newUserProfile() { let thisObject = { - botId: undefined, + botProfileId: undefined, botProfileHandle: undefined, botAsset: undefined, botExchange: undefined, enabled: undefined, + following: undefined, + followers: undefined, + followingCount: undefined, + followersCount: 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, initialize: initialize, finalize: finalize } @@ -13,17 +29,108 @@ exports.newBot = function newBot() { return thisObject function finalize() { + thisObject.following = undefined + thisObject.followers = undefined + thisObject.posts = undefined + thisObject.bots = undefined } - function initialize( - botId, - botAsset, - botExchange + function initialize() { + + thisObject.following = new Map() + thisObject.followers = new Map() + + thisObject.followingCount = 0 + thisObject.followersCount = 0 + + thisObject.emitterEventsCount = 0 + thisObject.targetEventsCount = 0 + thisObject.postsCount = 0 + thisObject.botsCount = 0 + + thisObject.posts = [] + thisObject.bots = undefined + } + + function addPost( + emitterPostHash, + targetPostHash, + postType, + botProfile, + timestamp ) { - thisObject.botId = botId - thisObject.botAsset = botAsset - thisObject.botExchange = botExchange - thisObject.enabled = true + if (NT.memory.maps.POSTS.get(emitterPostHash) !== undefined) { + throw ('Post Already Exists.') + } + + let post = NT.modules.POST.newPost() + post.initialize( + emitterPostHash, + targetPostHash, + postType, + botProfile, + timestamp + ) + + thisObject.maps.POSTS.push(post) + NT.memory.maps.POSTS.set(emitterPostHash, post) + thisObject.postsCount++ } -} \ No newline at end of file + + function removePost( + emitterPostHash + ) { + if (NT.memory.maps.POSTS.get(emitterPostHash) === undefined) { + throw ('Post Does Not Exist.') + } + + 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 + ) { + if (thisObject.following.get(botProfile.id) === undefined) { + thisObject.following.set(botProfile.id, botProfile) + thisObject.followingCount++ + } + } + + function removeFollowing( + botProfile + ) { + if (thisObject.following.get(botProfile.id) !== undefined) { + thisObject.following.delete(botProfile.id) + thisObject.followingCount-- + } + } + + function addFollower( + botProfile + ) { + if (thisObject.followers.get(botProfile.id) === undefined) { + thisObject.followers.set(botProfile.id, botProfile) + thisObject.followersCount++ + } + } + + function removeFollower( + botProfile + ) { + if (thisObject.followers.get(botProfile.id) !== undefined) { + thisObject.followers.delete(botProfile.id) + thisObject.followersCount-- + } + } +}