Merge pull request #1575 from Luis-Fernando-Molina/develop
Contribution: Superalgos Network: Events Query implemented.
This commit is contained in:
11 files changed
+617
-150
No files matched your search
@@ -211,6 +211,7 @@ exports.newGithubServer = function newGithubServer() {
|
||||
})
|
||||
await getPrList()
|
||||
await mergePrs()
|
||||
await closePrsToMaster()
|
||||
|
||||
async function getPrList() {
|
||||
|
||||
@@ -592,6 +593,61 @@ exports.newGithubServer = function newGithubServer() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function closePrsToMaster() {
|
||||
|
||||
const per_page = 100 // Max
|
||||
let page = 0
|
||||
let lastPage = false
|
||||
|
||||
while (lastPage === false) {
|
||||
try {
|
||||
page++
|
||||
|
||||
await CL.projects.foundations.utilities.asyncFunctions.sleep(GITHUB_API_WAITING_TIME)
|
||||
|
||||
let listResponse = await octokit.rest.pulls.list({
|
||||
owner: owner,
|
||||
repo: repo,
|
||||
state: 'open',
|
||||
head: 'develop',
|
||||
base: 'develop',
|
||||
sort: undefined,
|
||||
direction: undefined,
|
||||
per_page: per_page,
|
||||
page: page
|
||||
});
|
||||
|
||||
if (listResponse.data.length < 100) {
|
||||
lastPage = true
|
||||
}
|
||||
console.log('[INFO] Github Server -> mergeGithubPullRequests -> doGithub -> getPrList -> Receiving Page = ' + page)
|
||||
for (let i = 0; i < listResponse.data.length; i++) {
|
||||
let pullRequest = listResponse.data[i]
|
||||
console.log('[INFO] Github Server -> mergeGithubPullRequests -> doGithub -> getPrList -> Pull Request "' + pullRequest.title + '" found and added to the list to validate. ')
|
||||
githubPrListArray.push(pullRequest)
|
||||
}
|
||||
console.log('[INFO] Github Server -> mergeGithubPullRequests -> doGithub -> getPrList -> Received = ' + listResponse.data.length)
|
||||
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
|
||||
if (err.stack.indexOf('last page') >= 0) {
|
||||
return
|
||||
} else {
|
||||
console.log('[ERROR] Github Server -> mergeGithubPullRequests -> doGithub -> getPrList ->Method call produced an error.')
|
||||
console.log('[ERROR] Github Server -> mergeGithubPullRequests -> doGithub -> getPrList ->err.stack = ' + err.stack)
|
||||
console.log('[ERROR] Github Server -> mergeGithubPullRequests -> doGithub -> getPrList ->repository = ' + repository)
|
||||
console.log('[ERROR] Github Server -> mergeGithubPullRequests -> doGithub -> getPrList ->username = ' + username)
|
||||
console.log('[ERROR] Github Server -> mergeGithubPullRequests -> doGithub -> getPrList ->token starts with = ' + token.substring(0, 10) + '...')
|
||||
console.log('[ERROR] Github Server -> mergeGithubPullRequests -> doGithub -> getPrList ->token ends with = ' + '...' + token.substring(token.length - 10))
|
||||
error = err
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.log('[ERROR] Github Server -> mergeGithubPullRequests -> doGithub -> err.stack = ' + err.stack)
|
||||
}
|
||||
|
||||
+12
-8
@@ -2,13 +2,17 @@
|
||||
|
||||
global.NT = {
|
||||
memory: {
|
||||
USER_PROFILES_BY_ID: new Map(), // Here we will store the user profiles by User Profile Id.
|
||||
USER_PROFILES_BY_HANDLE: new Map(), // Here we will store the user profiles by User Profile Handle.
|
||||
POSTS: new Map(), // This are all the posts we are keeping track of.
|
||||
EVENTS: new Map(), // This is the registry of all events received that prevents processing them more than once.
|
||||
TIMELINE: [], // A time ordered list of Posts and Trades.
|
||||
NETWORK_CLIENTS: [], // These are the Network Clients connected to this Network Node.
|
||||
NETWORK_PEERS: [], // These are the Network Peers connected to this Network Node.
|
||||
maps: {
|
||||
USER_PROFILES_BY_ID: new Map(), // Here we will store the user profiles by User Profile Id.
|
||||
USER_PROFILES_BY_HANDLE: new Map(), // Here we will store the user profiles by User Profile Handle.
|
||||
POSTS: new Map(), // This are all the posts we are keeping track of.
|
||||
EVENTS: new Map(), // This is the registry of all events received that prevents processing them more than once.
|
||||
},
|
||||
arrays: {
|
||||
EVENTS: [], // A time ordered list of events.
|
||||
NETWORK_CLIENTS: [], // These are the Network Clients connected to this Network Node ordered by Ranking.
|
||||
NETWORK_PEERS: [], // These are the Network Peers connected to this Network Node ordered by Ranking.
|
||||
}
|
||||
},
|
||||
modules: {
|
||||
USER_PROFILE: require('./UserProfile.js'),
|
||||
@@ -19,6 +23,6 @@ global.NT = {
|
||||
QUERY_PROFILE_STATS: require('./Queries/ProfileStats.js'),
|
||||
QUERY_PROFILE_POSTS: require('./Queries/ProfilePosts.js'),
|
||||
QUERY_POST_REPLIES: require('./Queries/ProfileReplies.js'),
|
||||
QUERY_TIMELINE_CHUNK: require('./Queries/TimelineChunk.js')
|
||||
QUERY_EVENTS: require('./Queries/Events.js')
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
exports.newEvents = function newEvents() {
|
||||
|
||||
let thisObject = {
|
||||
profile: undefined,
|
||||
initialIndex: undefined,
|
||||
amountRequested: undefined,
|
||||
direction: undefined,
|
||||
execute: execute,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
const INITIAL_EVENT_INDEX_FIRST = 'First'
|
||||
const INITIAL_EVENT_INDEX_LAST = 'Last'
|
||||
const MIN_AMOUNT_REQUESTED = 1
|
||||
const MAX_AMOUNT_REQUESTED = 100
|
||||
const DIRECTION_FUTURE = 'Future'
|
||||
const DIRECTION_PAST = 'Past'
|
||||
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
thisObject.profile = undefined
|
||||
}
|
||||
|
||||
function initialize(queryReceived) {
|
||||
/*
|
||||
Validate User Profile
|
||||
*/
|
||||
if (queryReceived.emitterUserProfileId !== undefined) {
|
||||
thisObject.profile = NT.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.emitterUserProfileId)
|
||||
} else {
|
||||
thisObject.profile = NT.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.emitterUserProfileHandle)
|
||||
}
|
||||
|
||||
if (thisObject.profile === undefined) {
|
||||
throw ('Emitter User Profile Not Found.')
|
||||
}
|
||||
/*
|
||||
Validate Initial Index
|
||||
*/
|
||||
if (queryReceived.initialIndex === undefined) {
|
||||
throw ('Initial Index Undefined.')
|
||||
}
|
||||
|
||||
if (queryReceived.initialIndex === INITIAL_EVENT_INDEX_LAST) {
|
||||
queryReceived.initialIndex = thisObject.profile.posts.length - 1
|
||||
}
|
||||
|
||||
if (queryReceived.initialIndex === INITIAL_EVENT_INDEX_FIRST) {
|
||||
queryReceived.initialIndex = 0
|
||||
}
|
||||
|
||||
if (isNaN(queryReceived.initialIndex) === true) {
|
||||
throw ('Initial Event Is Not a Number.')
|
||||
}
|
||||
|
||||
thisObject.initialIndex = queryReceived.initialIndex
|
||||
/*
|
||||
Validate Amount Requested
|
||||
*/
|
||||
if (queryReceived.amountRequested === undefined) {
|
||||
throw ('Amount Requested Undefined.')
|
||||
}
|
||||
|
||||
if (isNaN(queryReceived.amountRequested) === true) {
|
||||
throw ('Amount Requested Is Not a Number.')
|
||||
}
|
||||
|
||||
if (queryReceived.amountRequested < MIN_AMOUNT_REQUESTED) {
|
||||
throw ('Amount Requested Below Min.')
|
||||
}
|
||||
|
||||
if (queryReceived.amountRequested > MAX_AMOUNT_REQUESTED) {
|
||||
throw ('Amount Requested Above Max.')
|
||||
}
|
||||
/*
|
||||
Validate Direction
|
||||
*/
|
||||
if (queryReceived.direction === undefined) {
|
||||
throw ('Direction Undefined.')
|
||||
}
|
||||
|
||||
if (queryReceived.direction !== DIRECTION_FUTURE && queryReceived.direction !== DIRECTION_PAST) {
|
||||
throw ('Direction Not Supported.')
|
||||
}
|
||||
|
||||
thisObject.direction = queryReceived.direction
|
||||
|
||||
}
|
||||
|
||||
function execute() {
|
||||
let response = []
|
||||
switch (thisObject.direction) {
|
||||
case DIRECTION_FUTURE: {
|
||||
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
|
||||
let event = NT.memory.arrays.EVENTS[i]
|
||||
if (event === undefined) { break }
|
||||
checkEventContext(event)
|
||||
}
|
||||
break
|
||||
}
|
||||
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 }
|
||||
checkEventContext(event)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
return response
|
||||
|
||||
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)
|
||||
/*
|
||||
Test #1 : The Emitter or Target profile must be the same as the Query Profile.
|
||||
*/
|
||||
if (emitterUserProfile !== undefined) {
|
||||
if (emitterUserProfile.userProfieId === thisObject.profile.userProfieId) {
|
||||
addToResponse(event)
|
||||
return
|
||||
}
|
||||
}
|
||||
if (targetUserProfile !== undefined) {
|
||||
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) {
|
||||
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) {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
if (emitterUserProfile !== undefined) {
|
||||
let query = NT.modules.QUERY_PROFILE_STATS.newProfileStats()
|
||||
query.initialize({ targetUserProfileId: event.emitterUserProfileId })
|
||||
eventResponse.emitterUserProfile = query.execute()
|
||||
}
|
||||
|
||||
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 = {
|
||||
emitterUserProfileId: post.emitterUserProfileId,
|
||||
targetUserProfileId: post.targetUserProfileId,
|
||||
emitterPostHash: post.emitterPostHash,
|
||||
targetPostHash: post.targetPostHash,
|
||||
postType: post.postType,
|
||||
timestamp: post.timestamp,
|
||||
repliesCount: post.replies.length,
|
||||
reactionsCount: []
|
||||
}
|
||||
|
||||
for (let i = 0; i < post.reactionTypesCount; i++) {
|
||||
postResponse.reactionsCount.push(post.reactionsCount.get(i))
|
||||
}
|
||||
|
||||
return postResponse
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
exports.newPostReplies = function newPostReplies() {
|
||||
|
||||
let thisObject = {
|
||||
post: undefined,
|
||||
initialIndex: undefined,
|
||||
amountRequested: undefined,
|
||||
direction: undefined,
|
||||
execute: execute,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
const INITIAL_REPLY_INDEX_FIRST = 'First'
|
||||
const INITIAL_REPLY_INDEX_LAST = 'Last'
|
||||
const MIN_AMOUNT_REQUESTED = 1
|
||||
const MAX_AMOUNT_REQUESTED = 100
|
||||
const DIRECTION_FUTURE = 'Future'
|
||||
const DIRECTION_PAST = 'Past'
|
||||
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
thisObject.post = undefined
|
||||
}
|
||||
|
||||
function initialize(queryReceived) {
|
||||
/*
|
||||
Validate Post
|
||||
*/
|
||||
thisObject.post = NT.memory.maps.POSTS.get(queryReceived.targetPostHash)
|
||||
|
||||
if (thisObject.post === undefined) {
|
||||
throw ('Target Post Not Found.')
|
||||
}
|
||||
/*
|
||||
Validate Initial Index
|
||||
*/
|
||||
if (queryReceived.initialIndex === undefined) {
|
||||
throw ('Initial Index Undefined.')
|
||||
}
|
||||
|
||||
if (queryReceived.initialIndex === INITIAL_REPLY_INDEX_LAST) {
|
||||
queryReceived.initialIndex = thisObject.poat.replies.length - 1
|
||||
}
|
||||
|
||||
if (queryReceived.initialIndex === INITIAL_REPLY_INDEX_FIRST) {
|
||||
queryReceived.initialIndex = 0
|
||||
}
|
||||
|
||||
if (isNaN(queryReceived.initialIndex) === true) {
|
||||
throw ('Initial Reply Is Not a Number.')
|
||||
}
|
||||
|
||||
thisObject.initialIndex = queryReceived.initialIndex
|
||||
/*
|
||||
Validate Amount Requested
|
||||
*/
|
||||
if (queryReceived.amountRequested === undefined) {
|
||||
throw ('Amount Requested Undefined.')
|
||||
}
|
||||
|
||||
if (isNaN(queryReceived.amountRequested) === true) {
|
||||
throw ('Amount Requested Is Not a Number.')
|
||||
}
|
||||
|
||||
if (queryReceived.amountRequested < MIN_AMOUNT_REQUESTED) {
|
||||
throw ('Amount Requested Below Min.')
|
||||
}
|
||||
|
||||
if (queryReceived.amountRequested > MAX_AMOUNT_REQUESTED) {
|
||||
throw ('Amount Requested Above Max.')
|
||||
}
|
||||
/*
|
||||
Validate Direction
|
||||
*/
|
||||
if (queryReceived.direction === undefined) {
|
||||
throw ('Direction Undefined.')
|
||||
}
|
||||
|
||||
if (queryReceived.direction !== DIRECTION_FUTURE && queryReceived.direction !== DIRECTION_PAST) {
|
||||
throw ('Direction Not Supported.')
|
||||
}
|
||||
|
||||
thisObject.direction = queryReceived.direction
|
||||
|
||||
}
|
||||
|
||||
function execute() {
|
||||
let response = []
|
||||
switch (thisObject.direction) {
|
||||
case DIRECTION_FUTURE: {
|
||||
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
|
||||
let post = thisObject.post.replies[i]
|
||||
if (post === undefined) { break }
|
||||
addToResponse(post)
|
||||
}
|
||||
break
|
||||
}
|
||||
case DIRECTION_PAST: {
|
||||
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
|
||||
let post = thisObject.post.replies[i]
|
||||
if (post === undefined) { break }
|
||||
addToResponse(post)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
return response
|
||||
|
||||
function addToResponse(post) {
|
||||
let postResponse = {
|
||||
emitterUserProfileId: post.emitterUserProfileId,
|
||||
targetUserProfileId: post.targetUserProfileId,
|
||||
emitterPostHash: post.emitterPostHash,
|
||||
targetPostHash: post.targetPostHash,
|
||||
postType: post.postType,
|
||||
timestamp: post.timestamp,
|
||||
repliesCount: post.replies.length,
|
||||
reactionsCount: []
|
||||
}
|
||||
|
||||
for (let i = 0; i < post.reactionTypesCount; i++) {
|
||||
postResponse.reactionsCount.push(post.reactionsCount.get(i))
|
||||
}
|
||||
|
||||
response.push(postResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ exports.newProfilePosts = function newProfilePosts() {
|
||||
|
||||
let thisObject = {
|
||||
profile: undefined,
|
||||
initialPostIndex: undefined,
|
||||
initialIndex: undefined,
|
||||
amountRequested: undefined,
|
||||
direction: undefined,
|
||||
execute: execute,
|
||||
@@ -20,7 +20,7 @@ exports.newProfilePosts = function newProfilePosts() {
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
|
||||
thisObject.profile = undefined
|
||||
}
|
||||
|
||||
function initialize(queryReceived) {
|
||||
@@ -28,34 +28,34 @@ exports.newProfilePosts = function newProfilePosts() {
|
||||
Validate User Profile
|
||||
*/
|
||||
if (queryReceived.targetUserProfileId !== undefined) {
|
||||
thisObject.profile = NT.memory.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId)
|
||||
thisObject.profile = NT.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId)
|
||||
} else {
|
||||
thisObject.profile = NT.memory.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle)
|
||||
thisObject.profile = NT.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle)
|
||||
}
|
||||
|
||||
if (thisObject.profile === undefined) {
|
||||
throw ('Target User Profile Not Found.')
|
||||
}
|
||||
/*
|
||||
Validate Initial Post Index
|
||||
Validate Initial Index
|
||||
*/
|
||||
if (queryReceived.initialPostIndex === undefined) {
|
||||
throw ('Initial Post Index Undefined.')
|
||||
if (queryReceived.initialIndex === undefined) {
|
||||
throw ('Initial Index Undefined.')
|
||||
}
|
||||
|
||||
if (queryReceived.initialPostIndex === INITIAL_POST_INDEX_LAST) {
|
||||
queryReceived.initialPostIndex = thisObject.posts.length - 1
|
||||
if (queryReceived.initialIndex === INITIAL_POST_INDEX_LAST) {
|
||||
queryReceived.initialIndex = thisObject.profile.posts.length - 1
|
||||
}
|
||||
|
||||
if (queryReceived.initialPostIndex === INITIAL_POST_INDEX_FIRST) {
|
||||
queryReceived.initialPostIndex = 0
|
||||
if (queryReceived.initialIndex === INITIAL_POST_INDEX_FIRST) {
|
||||
queryReceived.initialIndex = 0
|
||||
}
|
||||
|
||||
if (isNaN(queryReceived.initialPostIndex) === true) {
|
||||
if (isNaN(queryReceived.initialIndex) === true) {
|
||||
throw ('Initial Post Is Not a Number.')
|
||||
}
|
||||
|
||||
thisObject.initialPostIndex = queryReceived.initialPostIndex
|
||||
thisObject.initialIndex = queryReceived.initialIndex
|
||||
/*
|
||||
Validate Amount Requested
|
||||
*/
|
||||
@@ -75,7 +75,7 @@ exports.newProfilePosts = function newProfilePosts() {
|
||||
throw ('Amount Requested Above Max.')
|
||||
}
|
||||
/*
|
||||
Validate Amount Requested
|
||||
Validate Direction
|
||||
*/
|
||||
if (queryReceived.direction === undefined) {
|
||||
throw ('Direction Undefined.')
|
||||
@@ -90,33 +90,44 @@ exports.newProfilePosts = function newProfilePosts() {
|
||||
}
|
||||
|
||||
function execute() {
|
||||
|
||||
let response = []
|
||||
switch (thisObject.direction) {
|
||||
case DIRECTION_FUTURE: {
|
||||
for (let i = thisObject.initialPostIndex; i < thisObject.initialPostIndex + thisObject.amountRequested; i++) {
|
||||
for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) {
|
||||
let post = thisObject.profile.posts[i]
|
||||
if (post === undefined) { break }
|
||||
|
||||
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))
|
||||
}
|
||||
|
||||
response.push(postResponse)
|
||||
addToResponse(post)
|
||||
}
|
||||
break
|
||||
}
|
||||
case DIRECTION_PAST: {
|
||||
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
|
||||
let post = thisObject.profile.posts[i]
|
||||
if (post === undefined) { break }
|
||||
addToResponse(post)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
return response
|
||||
|
||||
function addToResponse(post) {
|
||||
let postResponse = {
|
||||
emitterUserProfileId: post.emitterUserProfileId,
|
||||
targetUserProfileId: post.targetUserProfileId,
|
||||
emitterPostHash: post.emitterPostHash,
|
||||
targetPostHash: post.targetPostHash,
|
||||
postType: post.postType,
|
||||
timestamp: post.timestamp,
|
||||
repliesCount: post.replies.length,
|
||||
reactionsCount: []
|
||||
}
|
||||
|
||||
for (let i = 0; i < post.reactionTypesCount; i++) {
|
||||
postResponse.reactionsCount.push(post.reactionsCount.get(i))
|
||||
}
|
||||
|
||||
response.push(postResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,9 +18,9 @@ exports.newProfileStats = function newProfileStats() {
|
||||
Validate User Profile
|
||||
*/
|
||||
if (queryReceived.targetUserProfileId !== undefined) {
|
||||
thisObject.profile = NT.memory.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId)
|
||||
thisObject.profile = NT.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId)
|
||||
} else {
|
||||
thisObject.profile = NT.memory.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle)
|
||||
thisObject.profile = NT.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle)
|
||||
}
|
||||
|
||||
if (thisObject.profile === undefined) {
|
||||
|
||||
+3
-3
@@ -13,7 +13,7 @@ exports.newQuery = function newQuery() {
|
||||
PROFILE_STATS: 0,
|
||||
PROFILE_POSTS: 1,
|
||||
POST_REPLIES: 2,
|
||||
TIMELINE_CHUNK: 3
|
||||
EVENTS: 3
|
||||
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@ exports.newQuery = function newQuery() {
|
||||
break
|
||||
}
|
||||
|
||||
case QUERY_TYPES.TIMELINE_CHUNK: {
|
||||
thisObject.query = NT.modules.QUERY_TIMELINE_CHUNK.newTimelineChunk()
|
||||
case QUERY_TYPES.maps.EVENTS: {
|
||||
thisObject.query = NT.modules.QUERY_EVENTS.newEvents()
|
||||
query.initialize(queryReceived)
|
||||
break
|
||||
}
|
||||
|
||||
@@ -36,13 +36,13 @@ exports.newClientInterface = function newClientInterface() {
|
||||
*/
|
||||
|
||||
let eventReceived = JSON.parse(eventMessage)
|
||||
if (NT.memory.EVENTS.get(eventReceived.eventId) !== undefined) {
|
||||
if (NT.memory.maps.EVENTS.get(eventReceived.eventId) !== undefined) {
|
||||
throw ('Event Already Exists.')
|
||||
}
|
||||
|
||||
let event = NT.modules.EVENT.newEvent()
|
||||
event.initialize(eventReceived)
|
||||
NT.memory.EVENTS.set(eventReceived.eventId, event)
|
||||
NT.memory.maps.EVENTS.set(eventReceived.eventId, event)
|
||||
}
|
||||
|
||||
function queryReceived(queryMessage) {
|
||||
@@ -61,7 +61,10 @@ exports.newClientInterface = function newClientInterface() {
|
||||
"timestamp": 124234234234,
|
||||
"botId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"botAsset": "BTC",
|
||||
"botExchange": "Binance"
|
||||
"botExchange": "Binance",
|
||||
"initialIndex": 35,
|
||||
"amountRequested": 50,
|
||||
"direction": "Past"
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
+100
-85
@@ -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,59 +55,71 @@ 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.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(thisObject.emitterUserProfileId)
|
||||
if (emitterUserProfile === undefined) {
|
||||
throw ('Emitter User Profile Not Found.')
|
||||
}
|
||||
thisObject.emitterUserProfile.emitterEventsCount++
|
||||
|
||||
thisObject.targetUserProfile = NT.memory.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(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.')
|
||||
}
|
||||
} 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?
|
||||
*/
|
||||
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
|
||||
) {
|
||||
thisObject.emitterUserProfile.addPost(
|
||||
eventReceived.emitterPostHash,
|
||||
eventReceived.targetPostHash,
|
||||
emitterUserProfile.addPost(
|
||||
thisObject.emitterUserProfileId,
|
||||
thisObject.targetUserProfileId,
|
||||
thisObject.emitterPostHash,
|
||||
thisObject.targetPostHash,
|
||||
thisObject.eventType,
|
||||
thisObject.emitterUserProfile,
|
||||
thisObject.timestamp
|
||||
)
|
||||
}
|
||||
@@ -115,45 +130,45 @@ 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: {
|
||||
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
|
||||
}
|
||||
@@ -164,53 +179,53 @@ 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.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.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: {
|
||||
thisObject.emitterUserProfile.addBot(
|
||||
emitterUserProfile.addBot(
|
||||
thisObject.botId,
|
||||
thisObject.botAsset,
|
||||
thisObject.botExchange
|
||||
@@ -218,19 +233,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
|
||||
|
||||
+14
-10
@@ -1,15 +1,15 @@
|
||||
exports.newPost = function newPost() {
|
||||
|
||||
let thisObject = {
|
||||
emitterUserProfileId: undefined,
|
||||
targetUserProfileId: undefined,
|
||||
emitterPostHash: undefined,
|
||||
targetPostHash: undefined,
|
||||
postType: undefined,
|
||||
userProfile: undefined,
|
||||
timestamp: undefined,
|
||||
replies: undefined,
|
||||
targetPost: undefined,
|
||||
reactionsCount: undefined,
|
||||
reactionTypesCount: undefined,
|
||||
reactionTypesCount: undefined,
|
||||
addReaction: addReaction,
|
||||
removeReactions: removeReaction,
|
||||
initialize: initialize,
|
||||
@@ -51,33 +51,37 @@ 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 = []
|
||||
/*
|
||||
Let's find the Target Post
|
||||
*/
|
||||
let targetPost
|
||||
|
||||
if (
|
||||
event.eventType === POST_TYPES.REPLY_TO_MULTI_MEDIA_POST ||
|
||||
event.eventType === POST_TYPES.REPOST_MULTI_MEDIA ||
|
||||
@@ -86,9 +90,9 @@ exports.newPost = function newPost() {
|
||||
event.eventType === POST_TYPES.RE_POST_TRADE ||
|
||||
event.eventType === POST_TYPES.QUOTE_REPOST_TRADE
|
||||
) {
|
||||
thisObject.targetPost = NT.memory.POSTS.get(thisObject.targetPostHash)
|
||||
targetPost = NT.memory.maps.POSTS.get(thisObject.targetPostHash)
|
||||
|
||||
if (thisObject.targetPost === undefined) {
|
||||
if (targetPost === undefined) {
|
||||
throw ('Target Post Not Found.')
|
||||
}
|
||||
}
|
||||
@@ -99,7 +103,7 @@ exports.newPost = function newPost() {
|
||||
event.eventType === POST_TYPES.REPLY_TO_MULTI_MEDIA_POST ||
|
||||
event.eventType === POST_TYPES.REPLY_TO_TRADE_POST
|
||||
) {
|
||||
thisObject.targetPost.replies.push(thisObject)
|
||||
targetPost.replies.push(thisObject)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ exports.newUserProfile = function newUserProfile() {
|
||||
userProfile,
|
||||
timestamp
|
||||
) {
|
||||
if (NT.memory.POSTS.get(emitterPostHash) !== undefined) {
|
||||
if (NT.memory.maps.POSTS.get(emitterPostHash) !== undefined) {
|
||||
throw ('Post Already Exists.')
|
||||
}
|
||||
|
||||
@@ -91,28 +91,28 @@ exports.newUserProfile = function newUserProfile() {
|
||||
timestamp
|
||||
)
|
||||
|
||||
thisObject.posts.push(post)
|
||||
NT.memory.POSTS.set(emitterPostHash, post)
|
||||
thisObject.maps.POSTS.push(post)
|
||||
NT.memory.maps.POSTS.set(emitterPostHash, post)
|
||||
thisObject.postsCount++
|
||||
}
|
||||
|
||||
function removePost(
|
||||
emitterPostHash
|
||||
) {
|
||||
if (NT.memory.POSTS.get(emitterPostHash) === undefined) {
|
||||
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-- {
|
||||
for (let i = thisObject.posts.length - 1; i >= 0; i--) {
|
||||
if (thisObject.posts[i].emitterPostHash === emitterPostHash) {
|
||||
thisObject.posts.splice(i, 1)
|
||||
break
|
||||
}
|
||||
}
|
||||
NT.memory.POSTS.delete(emitterPostHash)
|
||||
NT.memory.maps.POSTS.delete(emitterPostHash)
|
||||
thisObject.postsCount--
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user