Merge pull request #1600 from Luis-Fernando-Molina/develop
Contribution: Superalgos Network: Reimplementing basic concepts
This commit is contained in:
15 files changed
+789
-443
No files matched your search
@@ -0,0 +1,51 @@
|
||||
exports.newBotProfileStats = function newBotProfileStats() {
|
||||
|
||||
let thisObject = {
|
||||
profile: undefined,
|
||||
execute: execute,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
thisObject.profile = undefined
|
||||
}
|
||||
|
||||
function initialize(queryReceived) {
|
||||
/*
|
||||
Validate Bot Profile
|
||||
*/
|
||||
let userProfile
|
||||
if (queryReceived.targetBotProfileId !== undefined) {
|
||||
userProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId)
|
||||
} else {
|
||||
userProfile = NT.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileId)
|
||||
}
|
||||
|
||||
if (userProfile === undefined) {
|
||||
throw ('Target User Profile Not Found.')
|
||||
}
|
||||
/*
|
||||
Validate Bot Profile
|
||||
*/
|
||||
thisObject.profile = userProfile.bots.get(queryReceived.targetBotProfileId)
|
||||
if (thisObject.profile === undefined) {
|
||||
throw ('Target Bot Profile Not Found.')
|
||||
}
|
||||
}
|
||||
|
||||
function execute() {
|
||||
|
||||
return {
|
||||
"botProfileId": thisObject.profile.botProfileId,
|
||||
"botProfileHandle": thisObject.profile.botProfileHandle,
|
||||
"followingCount": thisObject.profile.followingCount,
|
||||
"followersCount": thisObject.profile.followersCount,
|
||||
"emitterEventsCount": thisObject.profile.emitterEventsCount,
|
||||
"targetEventsCount": thisObject.profile.targetEventsCount,
|
||||
"postsCount": thisObject.profile.postsCount
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -130,13 +130,13 @@ exports.newEvents = function newEvents() {
|
||||
Test #1 : The Emitter or Target profile must be the same as the Query Profile.
|
||||
*/
|
||||
if (emitterUserProfile !== undefined) {
|
||||
if (emitterUserProfile.userProfieId === thisObject.profile.userProfieId) {
|
||||
if (emitterUserProfile.userProfileId === thisObject.profile.userProfileId) {
|
||||
addToResponse(event)
|
||||
return
|
||||
}
|
||||
}
|
||||
if (targetUserProfile !== undefined) {
|
||||
if (targetUserProfile.userProfieId === thisObject.profile.userProfieId) {
|
||||
if (targetUserProfile.userProfileId === thisObject.profile.userProfileId) {
|
||||
addToResponse(event)
|
||||
return
|
||||
}
|
||||
@@ -145,13 +145,13 @@ exports.newEvents = function newEvents() {
|
||||
Test #2 : The Emitter or Traget profile must be at the Following map of the Query Profile.
|
||||
*/
|
||||
if (emitterUserProfile !== undefined) {
|
||||
if (thisObject.profile.following.get(emitterUserProfile.userProfieId) !== undefined) {
|
||||
if (thisObject.profile.following.get(emitterUserProfile.userProfileId) !== undefined) {
|
||||
addToResponse(event)
|
||||
return
|
||||
}
|
||||
}
|
||||
if (targetUserProfile !== undefined) {
|
||||
if (thisObject.profile.following.get(targetUserProfile.userProfieId) !== undefined) {
|
||||
if (thisObject.profile.following.get(targetUserProfile.userProfileId) !== undefined) {
|
||||
addToResponse(event)
|
||||
return
|
||||
}
|
||||
@@ -200,15 +200,17 @@ exports.newEvents = function newEvents() {
|
||||
}
|
||||
|
||||
if (emitterUserProfile !== undefined) {
|
||||
let query = NT.modules.QUERY_PROFILE_STATS.newProfileStats()
|
||||
let query = NT.modules.QUERY_PROFILE_STATS.newUserProfileStats()
|
||||
query.initialize({ targetUserProfileId: event.emitterUserProfileId })
|
||||
eventResponse.emitterUserProfile = query.execute()
|
||||
query.finalize()
|
||||
}
|
||||
|
||||
if (targetUserProfile !== undefined) {
|
||||
let query = NT.modules.QUERY_PROFILE_STATS.newProfileStats()
|
||||
let query = NT.modules.QUERY_PROFILE_STATS.newUserProfileStats()
|
||||
query.initialize({ targetUserProfileId: event.targetUserProfileId })
|
||||
eventResponse.targetUserProfile = query.execute()
|
||||
query.finalize()
|
||||
}
|
||||
|
||||
if (emitterPost !== undefined) {
|
||||
@@ -230,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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
exports.newProfileFollowers = function newProfileFollowers() {
|
||||
|
||||
let thisObject = {
|
||||
profile: undefined,
|
||||
initialIndex: undefined,
|
||||
amountRequested: undefined,
|
||||
direction: undefined,
|
||||
execute: execute,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
const INITIAL_POST_INDEX_FIRST = 'First'
|
||||
const INITIAL_POST_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.targetUserProfileId !== undefined) {
|
||||
thisObject.profile = NT.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId)
|
||||
} else {
|
||||
thisObject.profile = NT.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle)
|
||||
}
|
||||
|
||||
if (thisObject.profile === undefined) {
|
||||
throw ('Target User Profile Not Found.')
|
||||
}
|
||||
/*
|
||||
Validate Bot Profile
|
||||
*/
|
||||
if (queryReceived.targetBotProfileId !== undefined) {
|
||||
thisObject.profile = thisObject.profile.bots.get(queryReceived.targetBotProfileId)
|
||||
if (thisObject.profile === undefined) {
|
||||
throw ('Target Bot Profile Not Found.')
|
||||
}
|
||||
}
|
||||
/*
|
||||
Validate Initial Index
|
||||
*/
|
||||
if (queryReceived.initialIndex === undefined) {
|
||||
throw ('Initial Index Undefined.')
|
||||
}
|
||||
|
||||
if (queryReceived.initialIndex === INITIAL_POST_INDEX_LAST) {
|
||||
queryReceived.initialIndex = thisObject.profile.posts.length - 1
|
||||
}
|
||||
|
||||
if (queryReceived.initialIndex === INITIAL_POST_INDEX_FIRST) {
|
||||
queryReceived.initialIndex = 0
|
||||
}
|
||||
|
||||
if (isNaN(queryReceived.initialIndex) === true) {
|
||||
throw ('Initial Post 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 arrayItem = thisObject.profile.arrays.followers[i]
|
||||
if (arrayItem === undefined) { break }
|
||||
addToResponse(arrayItem)
|
||||
}
|
||||
break
|
||||
}
|
||||
case DIRECTION_PAST: {
|
||||
for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) {
|
||||
let arrayItem = thisObject.profile.arrays.followers[i]
|
||||
if (arrayItem === undefined) { break }
|
||||
addToResponse(arrayItem)
|
||||
}
|
||||
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,
|
||||
reactions: Array.from(post.reactions)
|
||||
}
|
||||
response.push(postResponse)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,15 @@ exports.newProfilePosts = function newProfilePosts() {
|
||||
if (thisObject.profile === undefined) {
|
||||
throw ('Target User Profile Not Found.')
|
||||
}
|
||||
/*
|
||||
Validate Bot Profile
|
||||
*/
|
||||
if (queryReceived.targetBotProfileId !== undefined) {
|
||||
thisObject.profile = thisObject.profile.bots.get(queryReceived.targetBotProfileId)
|
||||
if (thisObject.profile === undefined) {
|
||||
throw ('Target Bot Profile Not Found.')
|
||||
}
|
||||
}
|
||||
/*
|
||||
Validate Initial Index
|
||||
*/
|
||||
@@ -94,17 +103,17 @@ 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.posts[i]
|
||||
if (post === undefined) { break }
|
||||
addToResponse(post)
|
||||
let arrayItem = thisObject.profile.arrays.posts[i]
|
||||
if (arrayItem === undefined) { break }
|
||||
addToResponse(arrayItem)
|
||||
}
|
||||
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)
|
||||
let arrayItem = thisObject.profile.arrays.posts[i]
|
||||
if (arrayItem === undefined) { break }
|
||||
addToResponse(arrayItem)
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -120,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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
exports.newProfileStats = function newProfileStats() {
|
||||
exports.newUserProfileStats = function newUserProfileStats() {
|
||||
|
||||
let thisObject = {
|
||||
profile: undefined,
|
||||
@@ -10,7 +10,7 @@ exports.newProfileStats = function newProfileStats() {
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
|
||||
thisObject.profile = undefined
|
||||
}
|
||||
|
||||
function initialize(queryReceived) {
|
||||
@@ -32,7 +32,7 @@ exports.newProfileStats = function newProfileStats() {
|
||||
function execute() {
|
||||
|
||||
return {
|
||||
"userProfieId": thisObject.profile.userProfieId,
|
||||
"userProfileId": thisObject.profile.userProfileId,
|
||||
"userProfileHandle": thisObject.profile.userProfileHandle,
|
||||
"blockchainAccount": thisObject.profile.blockchainAccount,
|
||||
"ranking": thisObject.profile.ranking,
|
||||
+34
-6
@@ -10,10 +10,13 @@ exports.newQuery = function newQuery() {
|
||||
|
||||
const QUERY_TYPES = {
|
||||
|
||||
PROFILE_STATS: 0,
|
||||
PROFILE_POSTS: 1,
|
||||
POST_REPLIES: 2,
|
||||
EVENTS: 3
|
||||
USER_PROFILE_STATS: 0,
|
||||
BOT_PROFILE_STATS: 1,
|
||||
PROFILE_POSTS: 2,
|
||||
PROFILE_FOLLOWERS: 3,
|
||||
PROFILE_FOLLOWING: 4,
|
||||
POST_REPLIES: 5,
|
||||
EVENTS: 6
|
||||
|
||||
}
|
||||
|
||||
@@ -30,27 +33,52 @@ exports.newQuery = function newQuery() {
|
||||
|
||||
switch (thisObject.queryType) {
|
||||
|
||||
case QUERY_TYPES.PROFILE_STATS: {
|
||||
thisObject.query = NT.modules.QUERY_PROFILE_STATS.newProfileStats()
|
||||
case QUERY_TYPES.USER_PROFILE_STATS: {
|
||||
thisObject.query = NT.modules.QUERY_USER_PROFILE_STATS.newUserProfileStats()
|
||||
query.initialize(queryReceived)
|
||||
query.finalize()
|
||||
break
|
||||
}
|
||||
|
||||
case QUERY_TYPES.BOT_PROFILE_STATS: {
|
||||
thisObject.query = NT.modules.QUERY_BOT_PROFILE_STATS.newBotProfileStats()
|
||||
query.initialize(queryReceived)
|
||||
query.finalize()
|
||||
break
|
||||
}
|
||||
|
||||
case QUERY_TYPES.PROFILE_POSTS: {
|
||||
thisObject.query = NT.modules.QUERY_PROFILE_POSTS.newProfilePosts()
|
||||
query.initialize(queryReceived)
|
||||
query.finalize()
|
||||
break
|
||||
}
|
||||
|
||||
case QUERY_TYPES.POST_REPLIES: {
|
||||
thisObject.query = NT.modules.QUERY_POST_REPLIES.newPostReplies()
|
||||
query.initialize(queryReceived)
|
||||
query.finalize()
|
||||
break
|
||||
}
|
||||
|
||||
case QUERY_TYPES.PROFILE_FOLLOWERS: {
|
||||
thisObject.query = NT.modules.QUERY_PROFILE_FOLLOWERS.newProfileFollowers()
|
||||
query.initialize(queryReceived)
|
||||
query.finalize()
|
||||
break
|
||||
}
|
||||
|
||||
case QUERY_TYPES.PROFILE_FOLLOWING: {
|
||||
thisObject.query = NT.modules.QUERY_PROFILE_FOLLOWING.newProfileFollowing()
|
||||
query.initialize(queryReceived)
|
||||
query.finalize()
|
||||
break
|
||||
}
|
||||
|
||||
case QUERY_TYPES.maps.EVENTS: {
|
||||
thisObject.query = NT.modules.QUERY_EVENTS.newEvents()
|
||||
query.initialize(queryReceived)
|
||||
query.finalize()
|
||||
break
|
||||
}
|
||||
default: throw('Query Type Not Supported.')
|
||||
|
||||
@@ -9,20 +9,30 @@ global.NT = {
|
||||
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'),
|
||||
BOT: require('./BotProfile.js'),
|
||||
EVENT: require('./Event.js'),
|
||||
USER_PROFILE: require('./UserProfile.js'),
|
||||
BOT_PROFILE: require('./BotProfile.js'),
|
||||
POST: require('./Post.js'),
|
||||
QUERY: require('./Query.js'),
|
||||
QUERY_PROFILE_STATS: require('./Queries/ProfileStats.js'),
|
||||
QUERY_USER_PROFILE_STATS: require('./Queries/UserProfileStats.js'),
|
||||
QUERY_BOT_PROFILE_STATS: require('./Queries/BotProfileStats.js'),
|
||||
QUERY_PROFILE_POSTS: require('./Queries/ProfilePosts.js'),
|
||||
QUERY_POST_REPLIES: require('./Queries/ProfileReplies.js'),
|
||||
QUERY_PROFILE_FOLLOWERS: require('./Queries/ProfileFollowers.js'),
|
||||
//QUERY_PROFILE_FOLLOWING: require('./Queries/ProfileFollowing.js'),
|
||||
//QUERY_POST_REPLIES: require('./Queries/ProfileReplies.js'),
|
||||
QUERY_EVENTS: require('./Queries/Events.js')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const map = new Map([[1, { a: 2 }], [2, { a: 4 }], [4, { a: 8 }]])
|
||||
map.set(3, { a: 6 })
|
||||
map.delete(2)
|
||||
map.set(2, { a: 12 })
|
||||
let array = Array.from(map)
|
||||
|
||||
console.log(JSON.stringify(array))
|
||||
+67
-60
@@ -1,25 +1,35 @@
|
||||
exports.newUserProfile = function newUserProfile() {
|
||||
|
||||
exports.newBotProfile = function newBotProfile() {
|
||||
/*
|
||||
Users can have a Profile that can:
|
||||
* follow other bots profiles.
|
||||
* be followed by other bots profiles.
|
||||
* have posts linked to the profile.
|
||||
*/
|
||||
let thisObject = {
|
||||
/* Unique Keys */
|
||||
botProfileId: undefined,
|
||||
botProfileHandle: undefined,
|
||||
/* Bot Unitque Properties */
|
||||
botAsset: undefined,
|
||||
botExchange: undefined,
|
||||
enabled: undefined,
|
||||
botEnabled: undefined,
|
||||
/* Maps */
|
||||
following: undefined,
|
||||
followers: undefined,
|
||||
followingCount: undefined,
|
||||
followersCount: undefined,
|
||||
posts: undefined,
|
||||
bots: undefined,
|
||||
/* Stats */
|
||||
emitterEventsCount: undefined,
|
||||
targetEventsCount: undefined,
|
||||
postsCount: undefined,
|
||||
posts: undefined,
|
||||
/* Post Functions */
|
||||
addPost: addPost,
|
||||
removePost: removePost,
|
||||
/* Follow - Unfollow Functions */
|
||||
addFollowing: addFollowing,
|
||||
removeFollowing: removeFollowing,
|
||||
addFollower: addFollower,
|
||||
removeFollower: removeFollower,
|
||||
/* Framework Functions */
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
@@ -27,25 +37,31 @@ exports.newUserProfile = function newUserProfile() {
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
|
||||
thisObject.following = undefined
|
||||
thisObject.followers = undefined
|
||||
|
||||
thisObject.posts = undefined
|
||||
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
thisObject.followingCount = 0
|
||||
thisObject.followersCount = 0
|
||||
thisObject.posts = new Map()
|
||||
|
||||
thisObject.emitterEventsCount = 0
|
||||
thisObject.targetEventsCount = 0
|
||||
thisObject.postsCount = 0
|
||||
|
||||
thisObject.posts = []
|
||||
}
|
||||
|
||||
function addPost(
|
||||
@@ -58,80 +74,71 @@ exports.newUserProfile = function newUserProfile() {
|
||||
postType,
|
||||
timestamp
|
||||
) {
|
||||
if (NT.memory.maps.POSTS.get(emitterPostHash) !== undefined) {
|
||||
if (thisObject.posts.get(emitterPostHash) !== undefined) {
|
||||
throw ('Post Already Exists.')
|
||||
} else {
|
||||
let post = NT.modules.POST.newPost()
|
||||
post.initialize(
|
||||
emitterUserProfileId,
|
||||
targetUserProfileId,
|
||||
emitterBotProfileId,
|
||||
targetBotProfileId,
|
||||
emitterPostHash,
|
||||
targetPostHash,
|
||||
postType,
|
||||
timestamp
|
||||
)
|
||||
|
||||
thisObject.posts.set(emitterPostHash, post)
|
||||
}
|
||||
|
||||
let post = NT.modules.POST.newPost()
|
||||
post.initialize(
|
||||
emitterUserProfileId,
|
||||
targetUserProfileId,
|
||||
emitterBotProfileId,
|
||||
targetBotProfileId,
|
||||
emitterPostHash,
|
||||
targetPostHash,
|
||||
postType,
|
||||
timestamp
|
||||
)
|
||||
|
||||
thisObject.posts.push(post)
|
||||
NT.memory.maps.POSTS.set(emitterPostHash, post)
|
||||
thisObject.postsCount++
|
||||
}
|
||||
|
||||
function removePost(
|
||||
emitterPostHash
|
||||
) {
|
||||
if (NT.memory.maps.POSTS.get(emitterPostHash) === undefined) {
|
||||
if (thisObject.posts.get(emitterPostHash) === undefined) {
|
||||
throw ('Post Does Not Exist.')
|
||||
} else {
|
||||
let post = thisObject.posts.get(emitterPostHash)
|
||||
post.finalize()
|
||||
thisObject.posts.delete(emitterPostHash)
|
||||
}
|
||||
|
||||
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
|
||||
targetUserProfileId
|
||||
) {
|
||||
if (thisObject.following.get(botProfile.id) === undefined) {
|
||||
thisObject.following.set(botProfile.id, botProfile)
|
||||
thisObject.followingCount++
|
||||
if (thisObject.following.get(targetUserProfileId) === undefined) {
|
||||
thisObject.following.set(targetUserProfileId, targetUserProfileId)
|
||||
} else {
|
||||
throw ('Already Following.')
|
||||
}
|
||||
}
|
||||
|
||||
function removeFollowing(
|
||||
botProfile
|
||||
targetUserProfileId
|
||||
) {
|
||||
if (thisObject.following.get(botProfile.id) !== undefined) {
|
||||
thisObject.following.delete(botProfile.id)
|
||||
thisObject.followingCount--
|
||||
if (thisObject.following.get(targetUserProfileId) !== undefined) {
|
||||
thisObject.following.delete(targetUserProfileId)
|
||||
} else {
|
||||
throw ('Not Following.')
|
||||
}
|
||||
}
|
||||
|
||||
function addFollower(
|
||||
botProfile
|
||||
emitterUserProfileId
|
||||
) {
|
||||
if (thisObject.followers.get(botProfile.id) === undefined) {
|
||||
thisObject.followers.set(botProfile.id, botProfile)
|
||||
thisObject.followersCount++
|
||||
if (thisObject.followers.get(emitterUserProfileId) === undefined) {
|
||||
thisObject.followers.set(emitterUserProfileId, emitterUserProfileId)
|
||||
}
|
||||
}
|
||||
|
||||
function removeFollower(
|
||||
botProfile
|
||||
emitterUserProfileId
|
||||
) {
|
||||
if (thisObject.followers.get(botProfile.id) !== undefined) {
|
||||
thisObject.followers.delete(botProfile.id)
|
||||
thisObject.followersCount--
|
||||
if (thisObject.followers.get(emitterUserProfileId) !== undefined) {
|
||||
thisObject.followers.delete(emitterUserProfileId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
+299
-200
@@ -1,23 +1,36 @@
|
||||
exports.newEvent = function newEvent() {
|
||||
/*
|
||||
An Event is anything that happens system wide that
|
||||
needs to be delivered to relevant entities via
|
||||
the Superalgos Network.
|
||||
|
||||
An Event (in contrast to a Query) produces a change
|
||||
on the state of the social graph.
|
||||
*/
|
||||
let thisObject = {
|
||||
/* Unique Key */
|
||||
eventId: undefined,
|
||||
/* Referenced Entities Unique Keys */
|
||||
emitterUserProfileId: undefined,
|
||||
targetUserProfileId: undefined,
|
||||
emitterBotProfileId: undefined,
|
||||
targetBotProfileId: undefined,
|
||||
emitterPostHash: undefined,
|
||||
targetPostHash: undefined,
|
||||
/* Event Unitque Properties */
|
||||
eventType: undefined,
|
||||
timestamp: undefined,
|
||||
botId: undefined,
|
||||
/* Bot Related Properties */
|
||||
botAsset: undefined,
|
||||
botExchange: undefined,
|
||||
botEnabled: undefined,
|
||||
/* Framework Functions */
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
const EVENT_TYPES = {
|
||||
|
||||
/* Users Posts and Following Events */
|
||||
NEW_USER_POST: 10,
|
||||
REPLY_TO_USER_POST: 11,
|
||||
REPOST_USER_POST: 12,
|
||||
@@ -25,7 +38,7 @@ exports.newEvent = function newEvent() {
|
||||
REMOVE_USER_POST: 14,
|
||||
FOLLOW_USER_PROFILE: 15,
|
||||
UNFOLLOW_USER_PROFILE: 16,
|
||||
|
||||
/* Bots Posts and Following Events */
|
||||
NEW_BOT_POST: 20,
|
||||
REPLY_TO_BOT_POST: 21,
|
||||
REPOST_BOT_POST: 22,
|
||||
@@ -33,34 +46,33 @@ exports.newEvent = function newEvent() {
|
||||
REMOVE_BOT_POST: 24,
|
||||
FOLLOW_BOT_PROFILE: 25,
|
||||
UNFOLLOW_BOT_PROFILE: 26,
|
||||
|
||||
/* Bots Management Events */
|
||||
ADD_BOT: 50,
|
||||
REMOVE_BOT: 51,
|
||||
ENABLE_BOT: 52,
|
||||
DISABLE_BOT: 53,
|
||||
|
||||
/* Add Reaction to Posts Events */
|
||||
ADD_REACTION_LIKE: 100,
|
||||
ADD_REACTION_LOVE: 101,
|
||||
ADD_REACTION_HAHA: 102,
|
||||
ADD_REACTION_WOW: 103,
|
||||
ADD_REACTION_SAD: 104,
|
||||
ADD_REACTION_ANGRY: 105,
|
||||
ADD_REACTION_HUG: 106,
|
||||
|
||||
ADD_REACTION_CARE: 106,
|
||||
/* Remove Reaction to Posts Events */
|
||||
REMOVE_REACTION_LIKE: 200,
|
||||
REMOVE_REACTION_LOVE: 201,
|
||||
REMOVE_REACTION_HAHA: 202,
|
||||
REMOVE_REACTION_WOW: 203,
|
||||
REMOVE_REACTION_SAD: 204,
|
||||
REMOVE_REACTION_ANGRY: 205,
|
||||
REMOVE_REACTION_HUG: 206
|
||||
REMOVE_REACTION_CARE: 206
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
emitterUserProfile = undefined
|
||||
targetUserProfile = undefined
|
||||
|
||||
}
|
||||
|
||||
function initialize(eventReceived) {
|
||||
@@ -74,248 +86,335 @@ exports.newEvent = function newEvent() {
|
||||
thisObject.targetBotProfileId = eventReceived.targetBotProfileId
|
||||
thisObject.emitterPostHash = eventReceived.emitterPostHash
|
||||
thisObject.targetPostHash = eventReceived.targetPostHash
|
||||
thisObject.eventType = eventReceived.eventType
|
||||
thisObject.timestamp = eventReceived.timestamp
|
||||
thisObject.botId = eventReceived.botId
|
||||
thisObject.botAsset = eventReceived.botAsset
|
||||
thisObject.botExchange = eventReceived.botExchange
|
||||
thisObject.botEnabled = eventReceived.botEnabled
|
||||
/*
|
||||
Local Variables
|
||||
*/
|
||||
let emitterUserProfile
|
||||
let targetUserProfile
|
||||
let emitterBotProfile
|
||||
let targetBotProfile
|
||||
/*
|
||||
Validate Emitter User Profile.
|
||||
*/
|
||||
let emitterUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(thisObject.emitterUserProfileId)
|
||||
if (emitterUserProfileId === undefined) {
|
||||
throw ('Emitter User Profile Id Not Provided.')
|
||||
}
|
||||
emitterUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(thisObject.emitterUserProfileId)
|
||||
if (emitterUserProfile === undefined) {
|
||||
throw ('Emitter User Profile Not Found.')
|
||||
}
|
||||
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 (
|
||||
thisObject.eventType !== EVENT_TYPES.NEW_USER_POST &&
|
||||
thisObject.eventType !== EVENT_TYPES.NEW_BOT_POST
|
||||
) {
|
||||
if (thisObject.targetUserProfileId !== undefined) {
|
||||
targetUserProfile = NT.memory.maps.USER_PROFILES_BY_ID.get(thisObject.targetUserProfileId)
|
||||
if (targetUserProfile === undefined) {
|
||||
throw ('Target User Profile Not Found.')
|
||||
}
|
||||
} else {
|
||||
targetUserProfile.targetEventsCount++
|
||||
}
|
||||
/*
|
||||
Validate Emitter Bot Profile.
|
||||
*/
|
||||
if (emitterBotProfileId !== undefined) {
|
||||
let botProfile = emitterUserProfile.bots.get(emitterBotProfileId)
|
||||
if (
|
||||
emitterBotProfile === undefined
|
||||
) {
|
||||
throw ('Emitter BOt Profile Not Found.')
|
||||
emitterBotProfile = emitterUserProfile.bots.get(emitterBotProfileId)
|
||||
if (emitterBotProfile === undefined) {
|
||||
throw ('Emitter Bot Profile Not Found.')
|
||||
}
|
||||
}
|
||||
/*
|
||||
Is is related to Posting?
|
||||
Validate Target Bot Profile.
|
||||
*/
|
||||
if (
|
||||
thisObject.eventType === EVENT_TYPES.NEW_USER_POST ||
|
||||
thisObject.eventType === EVENT_TYPES.REPLY_TO_USER_POST ||
|
||||
thisObject.eventType === EVENT_TYPES.REPOST_USER_POST ||
|
||||
thisObject.eventType === EVENT_TYPES.QUOTE_REPOST_USER_POST ||
|
||||
thisObject.eventType === EVENT_TYPES.NEW_BOT_POST ||
|
||||
thisObject.eventType === EVENT_TYPES.REPLY_TO_BOT_POST ||
|
||||
thisObject.eventType === EVENT_TYPES.REPOST_BOT_POST ||
|
||||
thisObject.eventType === EVENT_TYPES.QUOTE_REPOST_BOT_POST
|
||||
) {
|
||||
if (targetBotProfileId !== undefined) {
|
||||
targetBotProfile = emitterUserProfile.bots.get(targetBotProfileId)
|
||||
if (targetBotProfile === undefined) {
|
||||
throw ('Target Bot Profile Not Found.')
|
||||
}
|
||||
}
|
||||
|
||||
postingEvents()
|
||||
followingEvents()
|
||||
reactionEvents()
|
||||
botEvents()
|
||||
eventCounters()
|
||||
|
||||
function postingEvents() {
|
||||
/*
|
||||
New User Post
|
||||
Is is related to Posting?
|
||||
*/
|
||||
if (
|
||||
thisObject.eventType === EVENT_TYPES.NEW_USER_POST ||
|
||||
thisObject.eventType === EVENT_TYPES.REPLY_TO_USER_POST ||
|
||||
thisObject.eventType === EVENT_TYPES.REPOST_USER_POST ||
|
||||
thisObject.eventType === EVENT_TYPES.QUOTE_REPOST_USER_POST
|
||||
) {
|
||||
emitterUserProfile.addPost(
|
||||
thisObject.emitterUserProfileId,
|
||||
thisObject.targetUserProfileId,
|
||||
thisObject.emitterBotProfileId,
|
||||
thisObject.targetBotProfileId,
|
||||
thisObject.emitterPostHash,
|
||||
thisObject.targetPostHash,
|
||||
thisObject.eventType - 10,
|
||||
thisObject.timestamp
|
||||
)
|
||||
return
|
||||
}
|
||||
/*
|
||||
New Bot Post
|
||||
*/
|
||||
if (
|
||||
thisObject.eventType === EVENT_TYPES.QUOTE_REPOST_USER_POST ||
|
||||
thisObject.eventType === EVENT_TYPES.NEW_BOT_POST ||
|
||||
thisObject.eventType === EVENT_TYPES.REPLY_TO_BOT_POST ||
|
||||
thisObject.eventType === EVENT_TYPES.REPOST_BOT_POST ||
|
||||
thisObject.eventType === EVENT_TYPES.QUOTE_REPOST_BOT_POST
|
||||
) {
|
||||
emitterBotProfile.addPost(
|
||||
thisObject.emitterUserProfileId,
|
||||
thisObject.targetUserProfileId,
|
||||
thisObject.emitterBotProfileId,
|
||||
thisObject.targetBotProfileId,
|
||||
thisObject.emitterPostHash,
|
||||
thisObject.targetPostHash,
|
||||
thisObject.eventType - 20,
|
||||
thisObject.timestamp
|
||||
)
|
||||
return
|
||||
/*
|
||||
New User Post
|
||||
*/
|
||||
if (
|
||||
thisObject.eventType === EVENT_TYPES.NEW_USER_POST ||
|
||||
thisObject.eventType === EVENT_TYPES.REPLY_TO_USER_POST ||
|
||||
thisObject.eventType === EVENT_TYPES.REPOST_USER_POST ||
|
||||
thisObject.eventType === EVENT_TYPES.QUOTE_REPOST_USER_POST
|
||||
) {
|
||||
emitterUserProfile.addPost(
|
||||
thisObject.emitterUserProfileId,
|
||||
thisObject.targetUserProfileId,
|
||||
thisObject.emitterBotProfileId,
|
||||
thisObject.targetBotProfileId,
|
||||
thisObject.emitterPostHash,
|
||||
thisObject.targetPostHash,
|
||||
thisObject.eventType - 10,
|
||||
thisObject.timestamp
|
||||
)
|
||||
return
|
||||
}
|
||||
/*
|
||||
New Bot Post
|
||||
*/
|
||||
if (
|
||||
thisObject.eventType === EVENT_TYPES.NEW_BOT_POST ||
|
||||
thisObject.eventType === EVENT_TYPES.REPLY_TO_BOT_POST ||
|
||||
thisObject.eventType === EVENT_TYPES.REPOST_BOT_POST ||
|
||||
thisObject.eventType === EVENT_TYPES.QUOTE_REPOST_BOT_POST
|
||||
) {
|
||||
if (emitterBotProfile === undefined) {
|
||||
throw ('Emitter Bot Profile Id Not Provided.')
|
||||
}
|
||||
|
||||
emitterBotProfile.addPost(
|
||||
thisObject.emitterUserProfileId,
|
||||
thisObject.targetUserProfileId,
|
||||
thisObject.emitterBotProfileId,
|
||||
thisObject.targetBotProfileId,
|
||||
thisObject.emitterPostHash,
|
||||
thisObject.targetPostHash,
|
||||
thisObject.eventType - 20,
|
||||
thisObject.timestamp
|
||||
)
|
||||
return
|
||||
}
|
||||
/*
|
||||
Remove User Post
|
||||
*/
|
||||
if (
|
||||
thisObject.eventType === EVENT_TYPES.REMOVE_USER_POST
|
||||
) {
|
||||
emitterUserProfile.removePost(
|
||||
thisObject.emitterPostHash
|
||||
)
|
||||
return
|
||||
}
|
||||
/*
|
||||
Remove Bot Post
|
||||
*/
|
||||
if (
|
||||
thisObject.eventType === EVENT_TYPES.REMOVE_BOT_POST
|
||||
) {
|
||||
if (emitterBotProfile === undefined) {
|
||||
throw ('Emitter Bot Profile Id Not Provided.')
|
||||
}
|
||||
|
||||
emitterBotProfile.removePost(
|
||||
thisObject.emitterPostHash
|
||||
)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function followingEvents() {
|
||||
/*
|
||||
Remove User Post
|
||||
Is is a following?
|
||||
*/
|
||||
if (
|
||||
thisObject.eventType === EVENT_TYPES.REMOVE_USER_POST
|
||||
thisObject.eventType === EVENT_TYPES.FOLLOW_USER_PROFILE ||
|
||||
thisObject.eventType === EVENT_TYPES.UNFOLLOW_USER_PROFILE ||
|
||||
thisObject.eventType === EVENT_TYPES.FOLLOW_BOT_PROFILE ||
|
||||
thisObject.eventType === EVENT_TYPES.UNFOLLOW_BOT_PROFILE
|
||||
) {
|
||||
emitterUserProfile.removePost(
|
||||
thisObject.emitterPostHash
|
||||
)
|
||||
return
|
||||
}
|
||||
/*
|
||||
Remove Bot Post
|
||||
*/
|
||||
if (
|
||||
thisObject.eventType === EVENT_TYPES.REMOVE_USER_POST
|
||||
) {
|
||||
emitterBotProfile.removePost(
|
||||
thisObject.emitterPostHash
|
||||
)
|
||||
switch (thisObject.eventType) {
|
||||
case EVENT_TYPES.FOLLOW_USER_PROFILE: {
|
||||
|
||||
if (thisObject.emitterUserProfileId === undefined) {
|
||||
throw ('Emitter User Profile Id Not Provided.')
|
||||
}
|
||||
|
||||
if (thisObject.targetUserProfileId === undefined) {
|
||||
throw ('Target User Profile Id Not Provided.')
|
||||
}
|
||||
|
||||
emitterUserProfile.addFollowing(
|
||||
targetUserProfileId
|
||||
)
|
||||
targetUserProfile.addFollower(
|
||||
emitterUserProfileId
|
||||
)
|
||||
break
|
||||
}
|
||||
case EVENT_TYPES.UNFOLLOW_USER_PROFILE: {
|
||||
|
||||
if (thisObject.emitterUserProfileId === undefined) {
|
||||
throw ('Emitter User Profile Id Not Provided.')
|
||||
}
|
||||
|
||||
if (thisObject.targetUserProfileId === undefined) {
|
||||
throw ('Target User Profile Id Not Provided.')
|
||||
}
|
||||
|
||||
emitterUserProfile.removeFollowing(
|
||||
targetUserProfileId
|
||||
)
|
||||
targetUserProfile.removeFollower(
|
||||
emitterUserProfileId
|
||||
)
|
||||
break
|
||||
}
|
||||
case EVENT_TYPES.FOLLOW_BOT_PROFILE: {
|
||||
|
||||
if (thisObject.emitterBotProfileId === undefined) {
|
||||
throw ('Emitter Bot Profile Id Not Provided.')
|
||||
}
|
||||
|
||||
if (thisObject.targetBotProfileId === undefined) {
|
||||
throw ('Target Bot Profile Id Not Provided.')
|
||||
}
|
||||
|
||||
emitterBotProfile.addFollowing(
|
||||
targetBotProfileId
|
||||
)
|
||||
targetBotProfile.addFollower(
|
||||
emitterBotProfileId
|
||||
)
|
||||
break
|
||||
}
|
||||
case EVENT_TYPES.UNFOLLOW_BOT_PROFILE: {
|
||||
|
||||
if (thisObject.emitterBotProfileId === undefined) {
|
||||
throw ('Emitter Bot Profile Id Not Provided.')
|
||||
}
|
||||
|
||||
if (thisObject.targetBotProfileId === undefined) {
|
||||
throw ('Target Bot Profile Id Not Provided.')
|
||||
}
|
||||
|
||||
emitterBotProfile.removeFollowing(
|
||||
targetBotProfileId
|
||||
)
|
||||
targetBotProfile.removeFollower(
|
||||
emitterBotProfileId
|
||||
)
|
||||
break
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
/*
|
||||
Is is a following?
|
||||
*/
|
||||
if (
|
||||
thisObject.eventType === EVENT_TYPES.FOLLOW_USER_PROFILE ||
|
||||
thisObject.eventType === EVENT_TYPES.UNFOLLOW_USER_PROFILE ||
|
||||
thisObject.eventType === EVENT_TYPES.FOLLOW_BOT_PROFILE ||
|
||||
thisObject.eventType === EVENT_TYPES.UNFOLLOW_BOT_PROFILE
|
||||
) {
|
||||
switch (thisObject.eventType) {
|
||||
case EVENT_TYPES.FOLLOW_USER_PROFILE: {
|
||||
emitterUserProfile.addFollowing(
|
||||
targetUserProfile
|
||||
)
|
||||
targetUserProfile.addFollower(
|
||||
emitterUserProfile
|
||||
)
|
||||
break
|
||||
}
|
||||
case EVENT_TYPES.UNFOLLOW_USER_PROFILE: {
|
||||
emitterUserProfile.removeFollowing(
|
||||
targetUserProfile
|
||||
)
|
||||
targetUserProfile.removeFollower(
|
||||
emitterUserProfile
|
||||
)
|
||||
break
|
||||
}
|
||||
case EVENT_TYPES.FOLLOW_BOT_PROFILE: {
|
||||
emitterUserProfile.addTradePostsFollowing(
|
||||
targetUserProfile
|
||||
)
|
||||
targetUserProfile.addTradePostsFollower(
|
||||
emitterUserProfile
|
||||
)
|
||||
break
|
||||
}
|
||||
case EVENT_TYPES.UNFOLLOW_BOT_PROFILE: {
|
||||
emitterUserProfile.removeTradePostsFollowing(
|
||||
targetUserProfile
|
||||
)
|
||||
targetUserProfile.removeTradePostsFollower(
|
||||
emitterUserProfile
|
||||
)
|
||||
break
|
||||
}
|
||||
|
||||
function reactionEvents() {
|
||||
/*
|
||||
Is is a Reaction?
|
||||
*/
|
||||
let targetPost
|
||||
|
||||
if (targetBotProfile !== undefined) {
|
||||
targetPost = targetBotProfile.posts.get(thisObject.targetPostHash)
|
||||
} else {
|
||||
targetPost = targetUserProfile.posts.get(thisObject.targetPostHash)
|
||||
}
|
||||
return
|
||||
}
|
||||
/*
|
||||
Is is a Reaction?
|
||||
*/
|
||||
if (
|
||||
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(thisObject.targetPostHash)
|
||||
|
||||
if (targetPost === undefined) {
|
||||
throw ('Target Post Not Found')
|
||||
}
|
||||
|
||||
targetPost.addReaction(thisObject.eventType - 100)
|
||||
return
|
||||
}
|
||||
if (
|
||||
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(thisObject.targetPostHash)
|
||||
|
||||
if (targetPost === undefined) {
|
||||
throw ('Target Post Not Found')
|
||||
if (
|
||||
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_CARE
|
||||
) {
|
||||
targetPost.addReaction(thisObject.eventType - 100)
|
||||
return
|
||||
}
|
||||
if (
|
||||
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_CARE
|
||||
) {
|
||||
targetPost.removeReaction(thisObject.eventType - 200)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
targetPost.removeReaction(thisObject.eventType - 200)
|
||||
return
|
||||
function botEvents() {
|
||||
/*
|
||||
Is is a Bot?
|
||||
*/
|
||||
if (
|
||||
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 (thisObject.eventType) {
|
||||
case EVENT_TYPES.ADD_BOT: {
|
||||
emitterUserProfile.addBot(
|
||||
thisObject.emitterBotProfileId,
|
||||
thisObject.botAsset,
|
||||
thisObject.botExchange,
|
||||
thisObject.botEnabled
|
||||
)
|
||||
break
|
||||
}
|
||||
case EVENT_TYPES.REMOVE_BOT: {
|
||||
emitterUserProfile.removeBot(
|
||||
thisObject.emitterBotProfileId
|
||||
)
|
||||
break
|
||||
}
|
||||
case EVENT_TYPES.ENABLE_BOT: {
|
||||
emitterUserProfile.enableBot(
|
||||
thisObject.emitterBotProfileId
|
||||
)
|
||||
break
|
||||
}
|
||||
case EVENT_TYPES.DISABLE_BOT: {
|
||||
emitterUserProfile.disableBot(
|
||||
thisObject.emitterBotProfileId
|
||||
)
|
||||
break
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
/*
|
||||
Is is a Bot?
|
||||
*/
|
||||
if (
|
||||
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 (thisObject.eventType) {
|
||||
case EVENT_TYPES.ADD_BOT: {
|
||||
emitterUserProfile.addBot(
|
||||
thisObject.botId,
|
||||
thisObject.botAsset,
|
||||
thisObject.botExchange
|
||||
)
|
||||
break
|
||||
}
|
||||
case EVENT_TYPES.REMOVE_BOT: {
|
||||
emitterUserProfile.removeBot(
|
||||
thisObject.botId
|
||||
)
|
||||
break
|
||||
}
|
||||
case EVENT_TYPES.ENABLE_BOT: {
|
||||
emitterUserProfile.enableBot(
|
||||
thisObject.botId
|
||||
)
|
||||
break
|
||||
}
|
||||
case EVENT_TYPES.DISABLE_BOT: {
|
||||
emitterUserProfile.disableBot(
|
||||
thisObject.botId
|
||||
)
|
||||
break
|
||||
}
|
||||
|
||||
function eventCounters() {
|
||||
emitterUserProfile.emitterEventsCount++
|
||||
if (targetUserProfile !== undefined) {
|
||||
targetUserProfile.targetEventsCount++
|
||||
}
|
||||
if (emitterBotProfile !== undefined) {
|
||||
emitterUserProfile.emitterEventsCount++
|
||||
}
|
||||
if (targetBotProfile !== undefined) {
|
||||
targetBotProfile.targetEventsCount++
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
+51
-40
@@ -1,19 +1,35 @@
|
||||
exports.newPost = function newPost() {
|
||||
|
||||
/*
|
||||
Posts represent a collection of multimedia content sotored somewhere else
|
||||
and identified by that content hash. Posts might belong to:
|
||||
* a User Profile.
|
||||
* a Bot Profile.
|
||||
|
||||
Posts might be linked to other posts when they are a reply or quote.
|
||||
|
||||
Posts migth have:
|
||||
* replies, when a user or bot replies to a post.
|
||||
* reactions, when a user or bot reacts to a post.
|
||||
*/
|
||||
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
|
||||
}
|
||||
@@ -32,32 +48,23 @@ exports.newPost = function newPost() {
|
||||
REACTION_WOW: 3,
|
||||
REACTION_SAD: 4,
|
||||
REACTION_ANGRY: 5,
|
||||
REACTION_HUG: 6
|
||||
REACTION_CARE: 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_CARE, 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,51 +86,55 @@ exports.newPost = function newPost() {
|
||||
thisObject.targetPostHash = targetPostHash
|
||||
thisObject.postType = postType
|
||||
thisObject.timestamp = timestamp
|
||||
|
||||
thisObject.replies = []
|
||||
/*
|
||||
Let's find the Target Post
|
||||
*/
|
||||
let targetPost
|
||||
|
||||
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.')
|
||||
}
|
||||
|
||||
let targetPost = targetUserProfile.posts.get(thisObject.targetPostHash)
|
||||
|
||||
if (targetPost === undefined) {
|
||||
throw ('Target Post Not Found.')
|
||||
}
|
||||
}
|
||||
/*
|
||||
Let's add this post to the replies of the Target Post
|
||||
*/
|
||||
if (
|
||||
thisObject.postType === POST_TYPES.REPLY_TO_POST
|
||||
) {
|
||||
targetPost.replies.push(thisObject)
|
||||
/*
|
||||
Let's add this post to the replies of the Target Post
|
||||
*/
|
||||
if (
|
||||
thisObject.postType === POST_TYPES.REPLY_TO_POST
|
||||
) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
+98
-92
@@ -1,30 +1,41 @@
|
||||
exports.newUserProfile = function newUserProfile() {
|
||||
|
||||
/*
|
||||
Users can have a Profile that can:
|
||||
* follow other user profiles.
|
||||
* be followed by other user profiles.
|
||||
* have posts linked to the profile.
|
||||
* have bots linked to the profile.
|
||||
*/
|
||||
let thisObject = {
|
||||
userProfieId: undefined,
|
||||
/* Unique Keys */
|
||||
userProfileId: undefined,
|
||||
userProfileHandle: undefined,
|
||||
/* User Unitque Properties */
|
||||
blockchainAccount: undefined,
|
||||
/* SA Reputation + SA Token Balance */
|
||||
ranking: undefined,
|
||||
/* Maps */
|
||||
following: undefined,
|
||||
followers: undefined,
|
||||
followingCount: undefined,
|
||||
followersCount: undefined,
|
||||
posts: undefined,
|
||||
bots: undefined,
|
||||
/* Stats */
|
||||
emitterEventsCount: undefined,
|
||||
targetEventsCount: undefined,
|
||||
postsCount: undefined,
|
||||
botsCount: undefined,
|
||||
bots: undefined,
|
||||
posts: undefined,
|
||||
/* Post Functions */
|
||||
addPost: addPost,
|
||||
removePost: removePost,
|
||||
/* Follow - Unfollow Functions */
|
||||
addFollowing: addFollowing,
|
||||
removeFollowing: removeFollowing,
|
||||
addFollower: addFollower,
|
||||
removeFollower: removeFollower,
|
||||
/* Bot Functions */
|
||||
addBot: addBot,
|
||||
removeBot: removeBot,
|
||||
enableBot: enableBot,
|
||||
disableBot: disableBot,
|
||||
/* Framework Functions */
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
@@ -32,28 +43,34 @@ exports.newUserProfile = function newUserProfile() {
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
|
||||
thisObject.following = undefined
|
||||
thisObject.followers = undefined
|
||||
|
||||
thisObject.posts = undefined
|
||||
thisObject.bots = undefined
|
||||
|
||||
}
|
||||
|
||||
function initialize() {
|
||||
function initialize(
|
||||
userProfileId,
|
||||
userProfileHandle,
|
||||
blockchainAccount,
|
||||
ranking
|
||||
) {
|
||||
|
||||
thisObject.userProfileId = userProfileId
|
||||
thisObject.userProfileHandle = userProfileHandle
|
||||
thisObject.blockchainAccount = blockchainAccount
|
||||
thisObject.ranking = ranking
|
||||
|
||||
thisObject.following = new Map()
|
||||
thisObject.followers = new Map()
|
||||
|
||||
thisObject.followingCount = 0
|
||||
thisObject.followersCount = 0
|
||||
thisObject.posts = new Map()
|
||||
thisObject.bots = new Map()
|
||||
|
||||
thisObject.emitterEventsCount = 0
|
||||
thisObject.targetEventsCount = 0
|
||||
thisObject.postsCount = 0
|
||||
thisObject.botsCount = 0
|
||||
|
||||
thisObject.posts = []
|
||||
thisObject.bots = []
|
||||
}
|
||||
|
||||
function addPost(
|
||||
@@ -64,140 +81,129 @@ exports.newUserProfile = function newUserProfile() {
|
||||
postType,
|
||||
timestamp
|
||||
) {
|
||||
if (NT.memory.maps.POSTS.get(emitterPostHash) !== undefined) {
|
||||
if (thisObject.posts.get(emitterPostHash) !== undefined) {
|
||||
throw ('Post Already Exists.')
|
||||
} else {
|
||||
let post = NT.modules.POST.newPost()
|
||||
post.initialize(
|
||||
emitterUserProfileId,
|
||||
targetUserProfileId,
|
||||
undefined,
|
||||
undefined,
|
||||
emitterPostHash,
|
||||
targetPostHash,
|
||||
postType,
|
||||
timestamp
|
||||
)
|
||||
|
||||
thisObject.posts.set(emitterPostHash, post)
|
||||
}
|
||||
|
||||
let post = NT.modules.POST.newPost()
|
||||
post.initialize(
|
||||
emitterUserProfileId,
|
||||
targetUserProfileId,
|
||||
undefined,
|
||||
undefined,
|
||||
emitterPostHash,
|
||||
targetPostHash,
|
||||
postType,
|
||||
timestamp
|
||||
)
|
||||
|
||||
thisObject.posts.push(post)
|
||||
NT.memory.maps.POSTS.set(emitterPostHash, post)
|
||||
thisObject.postsCount++
|
||||
}
|
||||
|
||||
function removePost(
|
||||
emitterPostHash
|
||||
) {
|
||||
if (NT.memory.maps.POSTS.get(emitterPostHash) === undefined) {
|
||||
if (thisObject.posts.get(emitterPostHash) === undefined) {
|
||||
throw ('Post Does Not Exist.')
|
||||
} else {
|
||||
let post = thisObject.posts.get(emitterPostHash)
|
||||
post.finalize()
|
||||
thisObject.posts.delete(emitterPostHash)
|
||||
}
|
||||
|
||||
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(
|
||||
userProfile
|
||||
targetUserProfileId
|
||||
) {
|
||||
if (thisObject.following.get(userProfile.id) === undefined) {
|
||||
thisObject.following.set(userProfile.id, userProfile)
|
||||
thisObject.followingCount++
|
||||
if (thisObject.following.get(targetUserProfileId) === undefined) {
|
||||
thisObject.following.set(targetUserProfileId, targetUserProfileId)
|
||||
} else {
|
||||
throw ('Already Following.')
|
||||
}
|
||||
}
|
||||
|
||||
function removeFollowing(
|
||||
userProfile
|
||||
targetUserProfileId
|
||||
) {
|
||||
if (thisObject.following.get(userProfile.id) !== undefined) {
|
||||
thisObject.following.delete(userProfile.id)
|
||||
thisObject.followingCount--
|
||||
if (thisObject.following.get(targetUserProfileId) !== undefined) {
|
||||
thisObject.following.delete(targetUserProfileId)
|
||||
} else {
|
||||
throw ('Not Following.')
|
||||
}
|
||||
}
|
||||
|
||||
function addFollower(
|
||||
userProfile
|
||||
emitterUserProfileId
|
||||
) {
|
||||
if (thisObject.followers.get(userProfile.id) === undefined) {
|
||||
thisObject.followers.set(userProfile.id, userProfile)
|
||||
thisObject.followersCount++
|
||||
if (thisObject.followers.get(emitterUserProfileId) === undefined) {
|
||||
thisObject.followers.set(emitterUserProfileId, emitterUserProfileId)
|
||||
}
|
||||
}
|
||||
|
||||
function removeFollower(
|
||||
userProfile
|
||||
emitterUserProfileId
|
||||
) {
|
||||
if (thisObject.followers.get(userProfile.id) !== undefined) {
|
||||
thisObject.followers.delete(userProfile.id)
|
||||
thisObject.followersCount--
|
||||
if (thisObject.followers.get(emitterUserProfileId) !== undefined) {
|
||||
thisObject.followers.delete(emitterUserProfileId)
|
||||
}
|
||||
}
|
||||
|
||||
function addBot(
|
||||
botId,
|
||||
botProfileId,
|
||||
botAsset,
|
||||
botExchange
|
||||
botExchange,
|
||||
botEnabled
|
||||
) {
|
||||
if (thisObject.bots.get(botId) !== undefined) {
|
||||
let bot = thisObject.bots.get(botProfileId)
|
||||
if (bot !== undefined) {
|
||||
throw ('Bot Already Exists.')
|
||||
} else {
|
||||
let bot = NT.modules.BOTS.newBot()
|
||||
bot.initialize(
|
||||
botProfileId,
|
||||
botAsset,
|
||||
botExchange,
|
||||
botEnabled
|
||||
)
|
||||
thisObject.bots.set(botProfileId, bot)
|
||||
}
|
||||
|
||||
let bot = NT.modules.BOTS.newBot()
|
||||
bot.initialize(
|
||||
botId,
|
||||
botAsset,
|
||||
botExchange
|
||||
)
|
||||
thisObject.bots.set(botId, bot)
|
||||
thisObject.botsCount++
|
||||
}
|
||||
|
||||
function removeBot(
|
||||
botId
|
||||
botProfileId
|
||||
) {
|
||||
if (thisObject.bots.get(botId) === undefined) {
|
||||
let bot = thisObject.bots.get(botProfileId)
|
||||
if (bot === undefined) {
|
||||
throw ('Bot Does Not Exist.')
|
||||
} else {
|
||||
thisObject.bots.get(botProfileId).finalize()
|
||||
thisObject.bots.delete(botProfileId)
|
||||
}
|
||||
thisObject.bots.get(botId).finalize()
|
||||
thisObject.bots.delete(botId)
|
||||
thisObject.botsCount--
|
||||
}
|
||||
|
||||
function enableBot(
|
||||
botId
|
||||
botProfileId
|
||||
) {
|
||||
let bot = thisObject.bots.get(botId)
|
||||
let bot = thisObject.bots.get(botProfileId)
|
||||
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(
|
||||
botId
|
||||
botProfileId
|
||||
) {
|
||||
let bot = thisObject.bots.get(botId)
|
||||
let bot = thisObject.bots.get(botProfileId)
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -13154,17 +13154,17 @@
|
||||
"id": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"savedPayload": {
|
||||
"position": {
|
||||
"x": 30356,
|
||||
"y": 23119
|
||||
"x": 3571.4285714285716,
|
||||
"y": 25500
|
||||
},
|
||||
"targetPosition": {
|
||||
"x": 30356,
|
||||
"y": 23119
|
||||
"x": 3571.4285714285716,
|
||||
"y": 25500
|
||||
},
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
"isFrozen": false,
|
||||
"isCollapsed": false,
|
||||
"isCollapsed": true,
|
||||
"angleToParent": 1,
|
||||
"distanceToParent": 3,
|
||||
"arrangementStyle": 0
|
||||
|
||||
@@ -56,7 +56,7 @@ function newGovernanceUserProfileSpace() {
|
||||
const X_STEP = SPACE_WIDTH / (userProfiles.length + 1)
|
||||
const Y_STEP = 3000
|
||||
|
||||
const Y_LEVEL = SPACE_HEIGHT * 0.45
|
||||
const Y_LEVEL = SPACE_HEIGHT * 0.425
|
||||
let xOffset = X_STEP
|
||||
let yOffset = 0
|
||||
|
||||
|
||||
Reference in new issue
Block a user