Event Module Fixed, withoout unnecesary references
This commit is contained in:
1 parent
777b57703a
commit
96535a2dd4
6 files changed
+124
-96
No files matched your search
+33
-19
@@ -44,7 +44,7 @@ exports.newEvents = function newEvents() {
|
||||
}
|
||||
|
||||
if (queryReceived.initialIndex === INITIAL_EVENT_INDEX_LAST) {
|
||||
queryReceived.initialIndex = thisObject.profile.maps.POSTS.length - 1
|
||||
queryReceived.initialIndex = thisObject.profile.posts.length - 1
|
||||
}
|
||||
|
||||
if (queryReceived.initialIndex === INITIAL_EVENT_INDEX_FIRST) {
|
||||
@@ -94,38 +94,52 @@ exports.newEvents = function newEvents() {
|
||||
switch (thisObject.direction) {
|
||||
case DIRECTION_FUTURE: {
|
||||
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
|
||||
let post = thisObject.profile.maps.POSTS[i]
|
||||
if (post === undefined) { break }
|
||||
addPostToResponse(post)
|
||||
let event = NT.memory.arrays.EVENTS[i]
|
||||
if (event === undefined) { break }
|
||||
addToResponse(event)
|
||||
}
|
||||
}
|
||||
case DIRECTION_PAST: {
|
||||
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
|
||||
let post = thisObject.profile.maps.POSTS[i]
|
||||
if (post === undefined) { break }
|
||||
addPostToResponse(post)
|
||||
let event = NT.memory.arrays.EVENTS[i]
|
||||
if (event === undefined) { break }
|
||||
addToResponse(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
return response
|
||||
|
||||
function addPostToResponse(post) {
|
||||
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": []
|
||||
function addToResponse(event) {
|
||||
let eventResponse = {
|
||||
eventId: event.eventId,
|
||||
eventType: event.eventType,
|
||||
emitterUserProfileId: event.emitterUserProfileId,
|
||||
targetUserProfileId: event.targetUserProfileId,
|
||||
emitterPostHash: event.emitterPostHash,
|
||||
targetPostHash: event.targetPostHash,
|
||||
timestamp: event.timestamp,
|
||||
botId: event.botId,
|
||||
botAsset: event.botAsset,
|
||||
botExchange: event.botExchange,
|
||||
emitterUserProfile: {
|
||||
|
||||
},
|
||||
targetUserProfile: {
|
||||
|
||||
},
|
||||
emitterPost: {
|
||||
|
||||
},
|
||||
targetPost: {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < post.reactionTypesCount; i++) {
|
||||
postResponse.reactionsCount.push(post.reactionsCount.get(i))
|
||||
eventResponse.reactionsCount.push(post.reactionsCount.get(i))
|
||||
}
|
||||
|
||||
response.push(postResponse)
|
||||
response.push(eventResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,29 +92,29 @@ exports.newPostReplies = function newPostReplies() {
|
||||
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
|
||||
let post = thisObject.post.replies[i]
|
||||
if (post === undefined) { break }
|
||||
addPostToResponse(post)
|
||||
addToResponse(post)
|
||||
}
|
||||
}
|
||||
case DIRECTION_PAST: {
|
||||
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
|
||||
let post = thisObject.post.replies[i]
|
||||
if (post === undefined) { break }
|
||||
addPostToResponse(post)
|
||||
addToResponse(post)
|
||||
}
|
||||
}
|
||||
}
|
||||
return response
|
||||
|
||||
function addPostToResponse(post) {
|
||||
function addToResponse(post) {
|
||||
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": []
|
||||
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++) {
|
||||
|
||||
@@ -44,7 +44,7 @@ exports.newProfilePosts = function newProfilePosts() {
|
||||
}
|
||||
|
||||
if (queryReceived.initialIndex === INITIAL_POST_INDEX_LAST) {
|
||||
queryReceived.initialIndex = thisObject.profile.maps.POSTS.length - 1
|
||||
queryReceived.initialIndex = thisObject.profile.posts.length - 1
|
||||
}
|
||||
|
||||
if (queryReceived.initialIndex === INITIAL_POST_INDEX_FIRST) {
|
||||
@@ -94,31 +94,31 @@ exports.newProfilePosts = function newProfilePosts() {
|
||||
switch (thisObject.direction) {
|
||||
case DIRECTION_FUTURE: {
|
||||
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
|
||||
let post = thisObject.profile.maps.POSTS[i]
|
||||
let post = thisObject.profile.posts[i]
|
||||
if (post === undefined) { break }
|
||||
addPostToResponse(post)
|
||||
addToResponse(post)
|
||||
}
|
||||
}
|
||||
case DIRECTION_PAST: {
|
||||
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
|
||||
let post = thisObject.profile.maps.POSTS[i]
|
||||
let post = thisObject.profile.posts[i]
|
||||
if (post === undefined) { break }
|
||||
addPostToResponse(post)
|
||||
addToResponse(post)
|
||||
}
|
||||
}
|
||||
}
|
||||
return response
|
||||
|
||||
function addPostToResponse(post) {
|
||||
function addToResponse(post) {
|
||||
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": []
|
||||
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++) {
|
||||
|
||||
@@ -42,7 +42,7 @@ exports.newProfileStats = function newProfileStats() {
|
||||
"tradePostsFollowersCount": thisObject.profile.tradePostsFollowersCount,
|
||||
"emitterEventsCount": thisObject.profile.emitterEventsCount,
|
||||
"targetEventsCount": thisObject.profile.targetEventsCount,
|
||||
"postsCount": thisObject.profile.maps.POSTSCount,
|
||||
"postsCount": thisObject.profile.postsCount,
|
||||
"botsCount": thisObject.profile.botsCount
|
||||
}
|
||||
}
|
||||
|
||||
+56
-42
@@ -2,11 +2,14 @@ exports.newEvent = function newEvent() {
|
||||
|
||||
let thisObject = {
|
||||
eventId: undefined,
|
||||
eventType: undefined,
|
||||
emitterUserProfile: undefined,
|
||||
targetUserProfile: undefined,
|
||||
asset: undefined,
|
||||
emitterUserProfileId: undefined,
|
||||
targetUserProfileId: undefined,
|
||||
emitterPostHash: undefined,
|
||||
targetPostHash: undefined,
|
||||
timestamp: undefined,
|
||||
botId: undefined,
|
||||
botAsset: undefined,
|
||||
botExchange: undefined,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
@@ -52,20 +55,36 @@ exports.newEvent = function newEvent() {
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
thisObject.emitterUserProfile = undefined
|
||||
thisObject.targetUserProfile = undefined
|
||||
emitterUserProfile = undefined
|
||||
targetUserProfile = undefined
|
||||
}
|
||||
|
||||
function initialize(eventReceived) {
|
||||
|
||||
thisObject.emitterUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(eventReceived.emitterUserProfileId)
|
||||
if (thisObject.emitterUserProfile === undefined) {
|
||||
/*
|
||||
Store the message properties into this object properties.
|
||||
*/
|
||||
thisObject.eventId = eventReceived.eventId
|
||||
thisObject.emitterUserProfileId = eventReceived.emitterUserProfileId
|
||||
thisObject.targetUserProfileId = eventReceived.targetUserProfileId
|
||||
thisObject.emitterPostHash = eventReceived.emitterPostHash
|
||||
thisObject.targetPostHash = eventReceived.targetPostHash
|
||||
thisObject.timestamp = eventReceived.timestamp
|
||||
thisObject.botId = eventReceived.botId
|
||||
thisObject.botAsset = eventReceived.botAsset
|
||||
thisObject.botExchange = eventReceived.botExchange
|
||||
/*
|
||||
Validate Emitter User Profile.
|
||||
*/
|
||||
let emitterUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(eventReceived.emitterUserProfileId)
|
||||
if (emitterUserProfile === undefined) {
|
||||
throw ('Emitter User Profile Not Found.')
|
||||
}
|
||||
thisObject.emitterUserProfile.emitterEventsCount++
|
||||
|
||||
thisObject.targetUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(eventReceived.targetUserProfileId)
|
||||
if (thisObject.targetUserProfile === undefined) {
|
||||
emitterUserProfile.emitterEventsCount++
|
||||
/*
|
||||
Validate Target User Profile.
|
||||
*/
|
||||
let targetUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(eventReceived.targetUserProfileId)
|
||||
if (targetUserProfile === undefined) {
|
||||
/* We thow an exception when it does not have a target user profile and is required*/
|
||||
if (
|
||||
eventReceived.eventType !== EVENT_TYPES.NEW_MULTI_MEDIA_POST &&
|
||||
@@ -74,13 +93,8 @@ exports.newEvent = function newEvent() {
|
||||
throw ('Target User Profile Not Found.')
|
||||
}
|
||||
} else {
|
||||
thisObject.targetUserProfile.targetEventsCount++
|
||||
targetUserProfile.targetEventsCount++
|
||||
}
|
||||
|
||||
thisObject.eventId = eventReceived.eventId
|
||||
thisObject.eventType = eventReceived.eventType
|
||||
thisObject.asset = eventReceived.asset
|
||||
thisObject.timestamp = eventReceived.timestamp
|
||||
/*
|
||||
Is is a new post?
|
||||
*/
|
||||
@@ -98,13 +112,13 @@ exports.newEvent = function newEvent() {
|
||||
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.QUOTE_REPOST_MULTI_MEDIA
|
||||
) {
|
||||
thisObject.emitterUserProfile.addPost(
|
||||
emitterUserProfile.addPost(
|
||||
eventReceived.emitterPostHash,
|
||||
eventReceived.targetPostHash,
|
||||
thisObject.eventType,
|
||||
thisObject.emitterUserProfile,
|
||||
emitterUserProfile,
|
||||
thisObject.timestamp
|
||||
)
|
||||
}
|
||||
@@ -122,38 +136,38 @@ exports.newEvent = function newEvent() {
|
||||
) {
|
||||
switch (eventReceived.eventType) {
|
||||
case EVENT_TYPES.FOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS: {
|
||||
thisObject.emitterUserProfile.addMultiMediaPostsFollowing(
|
||||
thisObject.targetUserProfile
|
||||
emitterUserProfile.addMultiMediaPostsFollowing(
|
||||
targetUserProfile
|
||||
)
|
||||
thisObject.targetUserProfile.addMultiMediaPostsFollower(
|
||||
thisObject.emitterUserProfile
|
||||
targetUserProfile.addMultiMediaPostsFollower(
|
||||
emitterUserProfile
|
||||
)
|
||||
break
|
||||
}
|
||||
case EVENT_TYPES.UNFOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS: {
|
||||
thisObject.emitterUserProfile.removeMultiMediaPostsFollowing(
|
||||
thisObject.targetUserProfile
|
||||
emitterUserProfile.removeMultiMediaPostsFollowing(
|
||||
targetUserProfile
|
||||
)
|
||||
thisObject.targetUserProfile.removeMultiMediaPostsFollower(
|
||||
thisObject.emitterUserProfile
|
||||
targetUserProfile.removeMultiMediaPostsFollower(
|
||||
emitterUserProfile
|
||||
)
|
||||
break
|
||||
}
|
||||
case EVENT_TYPES.FOLLOW_USER_PROFILE_TRADE_POSTS: {
|
||||
thisObject.emitterUserProfile.addTradePostsFollowing(
|
||||
thisObject.targetUserProfile
|
||||
emitterUserProfile.addTradePostsFollowing(
|
||||
targetUserProfile
|
||||
)
|
||||
thisObject.targetUserProfile.addTradePostsFollower(
|
||||
thisObject.emitterUserProfile
|
||||
targetUserProfile.addTradePostsFollower(
|
||||
emitterUserProfile
|
||||
)
|
||||
break
|
||||
}
|
||||
case EVENT_TYPES.UNFOLLOW_USER_PROFILE_TRADE_POSTS: {
|
||||
thisObject.emitterUserProfile.removeTradePostsFollowing(
|
||||
thisObject.targetUserProfile
|
||||
emitterUserProfile.removeTradePostsFollowing(
|
||||
targetUserProfile
|
||||
)
|
||||
thisObject.targetUserProfile.removeTradePostsFollower(
|
||||
thisObject.emitterUserProfile
|
||||
targetUserProfile.removeTradePostsFollower(
|
||||
emitterUserProfile
|
||||
)
|
||||
break
|
||||
}
|
||||
@@ -210,7 +224,7 @@ exports.newEvent = function newEvent() {
|
||||
) {
|
||||
switch (eventReceived.eventType) {
|
||||
case EVENT_TYPES.ADD_BOT: {
|
||||
thisObject.emitterUserProfile.addBot(
|
||||
emitterUserProfile.addBot(
|
||||
thisObject.botId,
|
||||
thisObject.botAsset,
|
||||
thisObject.botExchange
|
||||
@@ -218,19 +232,19 @@ exports.newEvent = function newEvent() {
|
||||
break
|
||||
}
|
||||
case EVENT_TYPES.REMOVE_BOT: {
|
||||
thisObject.emitterUserProfile.removeBot(
|
||||
emitterUserProfile.removeBot(
|
||||
thisObject.botId
|
||||
)
|
||||
break
|
||||
}
|
||||
case EVENT_TYPES.ENABLE_BOT: {
|
||||
thisObject.emitterUserProfile.enableBot(
|
||||
emitterUserProfile.enableBot(
|
||||
thisObject.botId
|
||||
)
|
||||
break
|
||||
}
|
||||
case EVENT_TYPES.DISABLE_BOT: {
|
||||
thisObject.emitterUserProfile.disableBot(
|
||||
emitterUserProfile.disableBot(
|
||||
thisObject.botId
|
||||
)
|
||||
break
|
||||
|
||||
@@ -46,7 +46,7 @@ exports.newUserProfile = function newUserProfile() {
|
||||
thisObject.tradePostsFollowing = undefined
|
||||
thisObject.tradePostsFollowers = undefined
|
||||
|
||||
thisObject.maps.POSTS = undefined
|
||||
thisObject.posts = undefined
|
||||
thisObject.bots = undefined
|
||||
}
|
||||
|
||||
@@ -64,10 +64,10 @@ exports.newUserProfile = function newUserProfile() {
|
||||
thisObject.tradePostsFollowersCount = 0
|
||||
thisObject.emitterEventsCount = 0
|
||||
thisObject.targetEventsCount = 0
|
||||
thisObject.maps.POSTSCount = 0
|
||||
thisObject.postsCount = 0
|
||||
thisObject.botsCount = 0
|
||||
|
||||
thisObject.maps.POSTS = []
|
||||
thisObject.posts = []
|
||||
thisObject.bots = undefined
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ exports.newUserProfile = function newUserProfile() {
|
||||
|
||||
thisObject.maps.POSTS.push(post)
|
||||
NT.memory.maps.POSTS.set(emitterPostHash, post)
|
||||
thisObject.maps.POSTSCount++
|
||||
thisObject.postsCount++
|
||||
}
|
||||
|
||||
function removePost(
|
||||
@@ -103,17 +103,17 @@ exports.newUserProfile = function newUserProfile() {
|
||||
throw ('Post Does Not Exist.')
|
||||
}
|
||||
|
||||
let post = thisObject.maps.POSTS.get(emitterPostHash)
|
||||
let post = thisObject.posts.get(emitterPostHash)
|
||||
post.finalize()
|
||||
|
||||
for (let i = thisObject.maps.POSTS.length - 1; i >= 0; i--) {
|
||||
if (thisObject.maps.POSTS[i].emitterPostHash === emitterPostHash) {
|
||||
thisObject.maps.POSTS.splice(i, 1)
|
||||
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.maps.POSTSCount--
|
||||
thisObject.postsCount--
|
||||
}
|
||||
|
||||
function addMultiMediaPostsFollowing(
|
||||
|
||||
Reference in new issue
Block a user