Post Re Implemented

This commit is contained in:
Luis Fernando Molina committed 2021-08-29 10:35:41 +02:00
1 parent af332691d5
commit 4aa11efddf
9 files changed
+60 -63

No files matched your search

+1 -6
View File
@@ -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
}
}
+1 -6
View File
@@ -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)
}
}
+1 -6
View File
@@ -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)
}
}
+1 -6
View File
@@ -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)
}
}
+11 -2
View File
@@ -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()
+1
View File
@@ -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"
+4 -1
View File
@@ -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
}
+32 -30
View File
@@ -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)
}
}
+8 -6
View File
@@ -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
}
}