Superalgos Network: Events Query implemented.
This commit is contained in:
1 parent
94a48d9008
commit
fd3bddf540
3 files changed
+167
-93
No files matched your search
+111
-42
@@ -96,78 +96,147 @@ exports.newEvents = function newEvents() {
|
||||
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
|
||||
let event = NT.memory.arrays.EVENTS[i]
|
||||
if (event === undefined) { break }
|
||||
addToResponse(event)
|
||||
checkEventContext(event)
|
||||
}
|
||||
}
|
||||
case DIRECTION_PAST: {
|
||||
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
|
||||
let event = NT.memory.arrays.EVENTS[i]
|
||||
if (event === undefined) { break }
|
||||
addToResponse(event)
|
||||
checkEventContext(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
return response
|
||||
|
||||
function addToResponse(event) {
|
||||
function checkEventContext(event) {
|
||||
/*
|
||||
For an event to be returned at the response of this query, it needs to be related
|
||||
to the profile making the query. How it can be related?
|
||||
|
||||
1. The Emitter or Target profile must be the same as the Query Profile.
|
||||
2. The Emitter or Traget profile must be at the Following map of the Query Profile.
|
||||
3. The Emmiter or Target post must be belong to any profile at the Following of the Query Profile.
|
||||
|
||||
Any of the above happening, means that indeed it is related.
|
||||
*/
|
||||
let emitterUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(eventReceived.emitterUserProfileId)
|
||||
let targetUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(eventReceived.targetUserProfileId)
|
||||
let emitterPost = NT.memory.maps.POSTS.get(eventReceived.emitterPostHash)
|
||||
let targetPost = NT.memory.maps.POSTS.get(eventReceived.targetPostHash)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
/*
|
||||
Test #1 : The Emitter or Target profile must be the same as the Query Profile.
|
||||
*/
|
||||
if (emitterUserProfile !== undefined) {
|
||||
let query = NT.modules.QUERY_PROFILE_STATS.newProfileStats()
|
||||
query.initialize({ targetUserProfileId: event.emitterUserProfileId })
|
||||
eventResponse.emitterUserProfile = query.execute()
|
||||
if (emitterUserProfile.userProfieId === thisObject.profile.userProfieId) {
|
||||
addToResponse(event)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if (targetUserProfile !== undefined) {
|
||||
let query = NT.modules.QUERY_PROFILE_STATS.newProfileStats()
|
||||
query.initialize({ targetUserProfileId: event.targetUserProfileId })
|
||||
eventResponse.targetUserProfile = query.execute()
|
||||
if (targetUserProfile.userProfieId === thisObject.profile.userProfieId) {
|
||||
addToResponse(event)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Test #2 : The Emitter or Traget profile must be at the Following map of the Query Profile.
|
||||
*/
|
||||
if (emitterUserProfile !== undefined) {
|
||||
if (thisObject.profile.multiMediaPostsFollowing.get(emitterUserProfile.userProfieId) !== undefined) {
|
||||
addToResponse(event)
|
||||
return
|
||||
}
|
||||
}
|
||||
if (targetUserProfile !== undefined) {
|
||||
if (thisObject.profile.multiMediaPostsFollowing.get(targetUserProfile.userProfieId) !== undefined) {
|
||||
addToResponse(event)
|
||||
return
|
||||
}
|
||||
}
|
||||
/*
|
||||
Test #3 : The Emmiter or Target post must be belong to any profile at the Following of the Query Profile.
|
||||
*/
|
||||
if (emitterPost !== undefined) {
|
||||
eventResponse.emitterPost = addPost(emitterPost)
|
||||
if (thisObject.profile.multiMediaPostsFollowing.get(emitterPost.emitterUserProfileId) !== undefined) {
|
||||
addToResponse(event)
|
||||
return
|
||||
}
|
||||
}
|
||||
if (emitterPost !== undefined) {
|
||||
if (thisObject.profile.multiMediaPostsFollowing.get(emitterPost.targetUserProfileId) !== undefined) {
|
||||
addToResponse(event)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if (targetPost !== undefined) {
|
||||
eventResponse.targetPost = addPost(targetPost)
|
||||
if (thisObject.profile.multiMediaPostsFollowing.get(targetPost.emitterUserProfileId) !== undefined) {
|
||||
addToResponse(event)
|
||||
return
|
||||
}
|
||||
}
|
||||
if (targetPost !== undefined) {
|
||||
if (thisObject.profile.multiMediaPostsFollowing.get(targetPost.targetUserProfileId) !== undefined) {
|
||||
addToResponse(event)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
response.push(eventResponse)
|
||||
function addToResponse(event) {
|
||||
|
||||
function addPost(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: []
|
||||
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
|
||||
}
|
||||
|
||||
for (let i = 0; i < post.reactionTypesCount; i++) {
|
||||
postResponse.reactionsCount.push(post.reactionsCount.get(i))
|
||||
if (emitterUserProfile !== undefined) {
|
||||
let query = NT.modules.QUERY_PROFILE_STATS.newProfileStats()
|
||||
query.initialize({ targetUserProfileId: event.emitterUserProfileId })
|
||||
eventResponse.emitterUserProfile = query.execute()
|
||||
}
|
||||
|
||||
return postResponse
|
||||
if (targetUserProfile !== undefined) {
|
||||
let query = NT.modules.QUERY_PROFILE_STATS.newProfileStats()
|
||||
query.initialize({ targetUserProfileId: event.targetUserProfileId })
|
||||
eventResponse.targetUserProfile = query.execute()
|
||||
}
|
||||
|
||||
if (emitterPost !== undefined) {
|
||||
eventResponse.emitterPost = addPost(emitterPost)
|
||||
}
|
||||
|
||||
if (targetPost !== undefined) {
|
||||
eventResponse.targetPost = addPost(targetPost)
|
||||
}
|
||||
|
||||
response.push(eventResponse)
|
||||
|
||||
function addPost(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: []
|
||||
}
|
||||
|
||||
for (let i = 0; i < post.reactionTypesCount; i++) {
|
||||
postResponse.reactionsCount.push(post.reactionsCount.get(i))
|
||||
}
|
||||
|
||||
return postResponse
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+48
-47
@@ -75,7 +75,7 @@ exports.newEvent = function newEvent() {
|
||||
/*
|
||||
Validate Emitter User Profile.
|
||||
*/
|
||||
let emitterUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(eventReceived.emitterUserProfileId)
|
||||
let emitterUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(thisObject.emitterUserProfileId)
|
||||
if (emitterUserProfile === undefined) {
|
||||
throw ('Emitter User Profile Not Found.')
|
||||
}
|
||||
@@ -83,12 +83,12 @@ exports.newEvent = function newEvent() {
|
||||
/*
|
||||
Validate Target User Profile.
|
||||
*/
|
||||
let targetUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(eventReceived.targetUserProfileId)
|
||||
let targetUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(thisObject.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 &&
|
||||
eventReceived.eventType !== EVENT_TYPES.NEW_TRADE_POST
|
||||
thisObject.eventType !== EVENT_TYPES.NEW_MULTI_MEDIA_POST &&
|
||||
thisObject.eventType !== EVENT_TYPES.NEW_TRADE_POST
|
||||
) {
|
||||
throw ('Target User Profile Not Found.')
|
||||
}
|
||||
@@ -99,26 +99,27 @@ exports.newEvent = function newEvent() {
|
||||
Is is a new post?
|
||||
*/
|
||||
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 ||
|
||||
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
|
||||
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
|
||||
) {
|
||||
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.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
|
||||
) {
|
||||
emitterUserProfile.addPost(
|
||||
eventReceived.emitterPostHash,
|
||||
eventReceived.targetPostHash,
|
||||
thisObject.emitterUserProfileId,
|
||||
thisObject.targetUserProfileId,
|
||||
thisObject.emitterPostHash,
|
||||
thisObject.targetPostHash,
|
||||
thisObject.eventType,
|
||||
emitterUserProfile,
|
||||
thisObject.timestamp
|
||||
)
|
||||
}
|
||||
@@ -129,12 +130,12 @@ exports.newEvent = function newEvent() {
|
||||
Is is a following?
|
||||
*/
|
||||
if (
|
||||
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
|
||||
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
|
||||
) {
|
||||
switch (eventReceived.eventType) {
|
||||
switch (thisObject.eventType) {
|
||||
case EVENT_TYPES.FOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS: {
|
||||
emitterUserProfile.addMultiMediaPostsFollowing(
|
||||
targetUserProfile
|
||||
@@ -178,51 +179,51 @@ exports.newEvent = function newEvent() {
|
||||
Is is a Reaction?
|
||||
*/
|
||||
if (
|
||||
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
|
||||
thisObject.eventType === EVENT_TYPES.ADD_REACTION_LIKE ||
|
||||
thisObject.eventType === EVENT_TYPES.ADD_REACTION_LOVE ||
|
||||
thisObject.eventType === EVENT_TYPES.ADD_REACTION_HAHA ||
|
||||
thisObject.eventType === EVENT_TYPES.ADD_REACTION_WOW ||
|
||||
thisObject.eventType === EVENT_TYPES.ADD_REACTION_SAD ||
|
||||
thisObject.eventType === EVENT_TYPES.ADD_REACTION_ANGRY ||
|
||||
thisObject.eventType === EVENT_TYPES.ADD_REACTION_HUG
|
||||
) {
|
||||
let targetPost = NT.memory.maps.POSTS.get(eventReceived.targetPostHash)
|
||||
let targetPost = NT.memory.maps.POSTS.get(thisObject.targetPostHash)
|
||||
|
||||
if (targetPost === undefined) {
|
||||
throw ('Target Post Not Found')
|
||||
}
|
||||
|
||||
targetPost.addReaction(eventReceived.eventType - 100)
|
||||
targetPost.addReaction(thisObject.eventType - 100)
|
||||
return
|
||||
}
|
||||
if (
|
||||
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
|
||||
thisObject.eventType === EVENT_TYPES.REMOVE_REACTION_LIKE ||
|
||||
thisObject.eventType === EVENT_TYPES.REMOVE_REACTION_LOVE ||
|
||||
thisObject.eventType === EVENT_TYPES.REMOVE_REACTION_HAHA ||
|
||||
thisObject.eventType === EVENT_TYPES.REMOVE_REACTION_WOW ||
|
||||
thisObject.eventType === EVENT_TYPES.REMOVE_REACTION_SAD ||
|
||||
thisObject.eventType === EVENT_TYPES.REMOVE_REACTION_ANGRY ||
|
||||
thisObject.eventType === EVENT_TYPES.REMOVE_REACTION_HUG
|
||||
) {
|
||||
let targetPost = NT.memory.maps.POSTS.get(eventReceived.targetPostHash)
|
||||
let targetPost = NT.memory.maps.POSTS.get(thisObject.targetPostHash)
|
||||
|
||||
if (targetPost === undefined) {
|
||||
throw ('Target Post Not Found')
|
||||
}
|
||||
|
||||
targetPost.removeReaction(eventReceived.eventType - 200)
|
||||
targetPost.removeReaction(thisObject.eventType - 200)
|
||||
return
|
||||
}
|
||||
/*
|
||||
Is is a Bot?
|
||||
*/
|
||||
if (
|
||||
eventReceived.eventType === EVENT_TYPES.ADD_BOT ||
|
||||
eventReceived.eventType === EVENT_TYPES.REMOVE_BOT ||
|
||||
eventReceived.eventType === EVENT_TYPES.ENABLE_BOT ||
|
||||
eventReceived.eventType === EVENT_TYPES.DISABLE_BOT
|
||||
thisObject.eventType === EVENT_TYPES.ADD_BOT ||
|
||||
thisObject.eventType === EVENT_TYPES.REMOVE_BOT ||
|
||||
thisObject.eventType === EVENT_TYPES.ENABLE_BOT ||
|
||||
thisObject.eventType === EVENT_TYPES.DISABLE_BOT
|
||||
) {
|
||||
switch (eventReceived.eventType) {
|
||||
switch (thisObject.eventType) {
|
||||
case EVENT_TYPES.ADD_BOT: {
|
||||
emitterUserProfile.addBot(
|
||||
thisObject.botId,
|
||||
|
||||
+8
-4
@@ -1,10 +1,11 @@
|
||||
exports.newPost = function newPost() {
|
||||
|
||||
let thisObject = {
|
||||
emitterUserProfileId: undefined,
|
||||
targetUserProfileId: undefined,
|
||||
emitterPostHash: undefined,
|
||||
targetPostHash: undefined,
|
||||
postType: undefined,
|
||||
userProfile: undefined,
|
||||
timestamp: undefined,
|
||||
replies: undefined,
|
||||
targetPost: undefined,
|
||||
@@ -51,27 +52,30 @@ exports.newPost = function newPost() {
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
thisObject.emitterUserProfileId = undefined
|
||||
thisObject.targetUserProfileId = undefined
|
||||
thisObject.emitterPostHash = undefined
|
||||
thisObject.targetPostHash = undefined
|
||||
thisObject.postType = undefined
|
||||
thisObject.userProfile = undefined
|
||||
thisObject.timestamp = undefined
|
||||
thisObject.replies = undefined
|
||||
thisObject.targetPost = undefined
|
||||
}
|
||||
|
||||
function initialize(
|
||||
emitterUserProfileId,
|
||||
targetUserProfileId,
|
||||
emitterPostHash,
|
||||
targetPostHash,
|
||||
postType,
|
||||
userProfile,
|
||||
timestamp
|
||||
) {
|
||||
|
||||
thisObject.emitterUserProfileId = emitterUserProfileId
|
||||
thisObject.targetUserProfileId = targetUserProfileId
|
||||
thisObject.emitterPostHash = emitterPostHash
|
||||
thisObject.targetPostHash = targetPostHash
|
||||
thisObject.postType = postType
|
||||
thisObject.userProfile = userProfile
|
||||
thisObject.timestamp = timestamp
|
||||
|
||||
thisObject.replies = []
|
||||
|
||||
Reference in new issue
Block a user