Merge pull request #1566 from Luis-Fernando-Molina/develop
Contribution: Superalgos Network: First Queries Implemented
This commit is contained in:
15 files changed
+603
-196
No files matched your search
@@ -0,0 +1,24 @@
|
||||
|
||||
|
||||
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.
|
||||
},
|
||||
modules: {
|
||||
USER_PROFILE: require('./UserProfile.js'),
|
||||
EVENT: require('./Event.js'),
|
||||
POST: require('./Post.js'),
|
||||
BOT: require('./Bot.js'),
|
||||
QUERY: require('./Query.js'),
|
||||
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')
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
exports.newProfilePosts = function newProfilePosts() {
|
||||
|
||||
let thisObject = {
|
||||
profile: undefined,
|
||||
initialPostIndex: 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() {
|
||||
|
||||
}
|
||||
|
||||
function initialize(queryReceived) {
|
||||
/*
|
||||
Validate User Profile
|
||||
*/
|
||||
if (queryReceived.targetUserProfileId !== undefined) {
|
||||
thisObject.profile = NT.memory.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId)
|
||||
} else {
|
||||
thisObject.profile = NT.memory.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle)
|
||||
}
|
||||
|
||||
if (thisObject.profile === undefined) {
|
||||
throw ('Target User Profile Not Found.')
|
||||
}
|
||||
/*
|
||||
Validate Initial Post Index
|
||||
*/
|
||||
if (queryReceived.initialPostIndex === undefined) {
|
||||
throw ('Initial Post Index Undefined.')
|
||||
}
|
||||
|
||||
if (queryReceived.initialPostIndex === INITIAL_POST_INDEX_LAST) {
|
||||
queryReceived.initialPostIndex = thisObject.posts.length - 1
|
||||
}
|
||||
|
||||
if (queryReceived.initialPostIndex === INITIAL_POST_INDEX_FIRST) {
|
||||
queryReceived.initialPostIndex = 0
|
||||
}
|
||||
|
||||
if (isNaN(queryReceived.initialPostIndex) === true) {
|
||||
throw ('Initial Post Is Not a Number.')
|
||||
}
|
||||
|
||||
thisObject.initialPostIndex = queryReceived.initialPostIndex
|
||||
/*
|
||||
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 Amount Requested
|
||||
*/
|
||||
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.initialPostIndex; i < thisObject.initialPostIndex + 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
return response
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
exports.newProfileStats = function newProfileStats() {
|
||||
|
||||
let thisObject = {
|
||||
profile: undefined,
|
||||
execute: execute,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
|
||||
}
|
||||
|
||||
function initialize(queryReceived) {
|
||||
/*
|
||||
Validate User Profile
|
||||
*/
|
||||
if (queryReceived.targetUserProfileId !== undefined) {
|
||||
thisObject.profile = NT.memory.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId)
|
||||
} else {
|
||||
thisObject.profile = NT.memory.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle)
|
||||
}
|
||||
|
||||
if (thisObject.profile === undefined) {
|
||||
throw ('Target User Profile Not Found.')
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function execute() {
|
||||
|
||||
return {
|
||||
"userProfieId": thisObject.profile.userProfieId,
|
||||
"userProfileHandle": thisObject.profile.userProfileHandle,
|
||||
"blockchainAccount": thisObject.profile.blockchainAccount,
|
||||
"ranking": thisObject.profile.ranking,
|
||||
"multiMediaPostFollowingCount": thisObject.profile.multiMediaPostFollowingCount,
|
||||
"multiMediaPostFollowersCount": thisObject.profile.multiMediaPostFollowersCount,
|
||||
"tradePostsFollowingCount": thisObject.profile.tradePostsFollowingCount,
|
||||
"tradePostsFollowersCount": thisObject.profile.tradePostsFollowersCount,
|
||||
"emitterEventsCount": thisObject.profile.emitterEventsCount,
|
||||
"targetEventsCount": thisObject.profile.targetEventsCount,
|
||||
"postsCount": thisObject.profile.postsCount,
|
||||
"botsCount": thisObject.profile.botsCount
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
exports.newQuery = function newQuery() {
|
||||
|
||||
let thisObject = {
|
||||
query: undefined,
|
||||
queryType: undefined,
|
||||
execute: execute,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
const QUERY_TYPES = {
|
||||
|
||||
PROFILE_STATS: 0,
|
||||
PROFILE_POSTS: 1,
|
||||
POST_REPLIES: 2,
|
||||
TIMELINE_CHUNK: 3
|
||||
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
thisObject.query = undefined
|
||||
thisObject.queryType = undefined
|
||||
}
|
||||
|
||||
function initialize(queryReceived) {
|
||||
|
||||
thisObject.queryType = queryReceived.queryType
|
||||
|
||||
switch (thisObject.queryType) {
|
||||
|
||||
case QUERY_TYPES.PROFILE_STATS: {
|
||||
thisObject.query = NT.modules.QUERY_PROFILE_STATS.newProfileStats()
|
||||
query.initialize(queryReceived)
|
||||
break
|
||||
}
|
||||
|
||||
case QUERY_TYPES.PROFILE_POSTS: {
|
||||
thisObject.query = NT.modules.QUERY_PROFILE_POSTS.newProfilePosts()
|
||||
query.initialize(queryReceived)
|
||||
break
|
||||
}
|
||||
|
||||
case QUERY_TYPES.POST_REPLIES: {
|
||||
thisObject.query = NT.modules.QUERY_POST_REPLIES.newPostReplies()
|
||||
query.initialize(queryReceived)
|
||||
break
|
||||
}
|
||||
|
||||
case QUERY_TYPES.TIMELINE_CHUNK: {
|
||||
thisObject.query = NT.modules.QUERY_TIMELINE_CHUNK.newTimelineChunk()
|
||||
query.initialize(queryReceived)
|
||||
break
|
||||
}
|
||||
default: throw('Query Type Not Supported.')
|
||||
}
|
||||
}
|
||||
|
||||
function execute() {
|
||||
return thisObject.query.execute()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
exports.newBot = function newBot() {
|
||||
|
||||
let thisObject = {
|
||||
botId: undefined,
|
||||
botAsset: undefined,
|
||||
botExchange: undefined,
|
||||
enabled: undefined,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
|
||||
}
|
||||
|
||||
function initialize(
|
||||
botId,
|
||||
botAsset,
|
||||
botExchange
|
||||
) {
|
||||
thisObject.botId = botId
|
||||
thisObject.botAsset = botAsset
|
||||
thisObject.botExchange = botExchange
|
||||
thisObject.enabled = true
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
exports.newClientInterface = function newClientInterface() {
|
||||
|
||||
let thisObject = {
|
||||
eventReceived: eventReceived,
|
||||
queryReceived: queryReceived,
|
||||
initialize: initialize,
|
||||
finalize: finalize,
|
||||
run: run
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
return thisObject
|
||||
@@ -16,7 +17,57 @@ exports.newClientInterface = function newClientInterface() {
|
||||
|
||||
}
|
||||
|
||||
function run() {
|
||||
|
||||
}
|
||||
function eventReceived(eventMessage) {
|
||||
/*
|
||||
We expect here a JSON string with the following properties:
|
||||
|
||||
{
|
||||
"eventId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"eventType": 10,
|
||||
"emitterUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"targetUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"emitterPostHash": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"targetPostHash": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"timestamp": 124234234234,
|
||||
"botId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"botAsset": "BTC",
|
||||
"botExchange": "Binance"
|
||||
}
|
||||
*/
|
||||
|
||||
let eventReceived = JSON.parse(eventMessage)
|
||||
if (NT.memory.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)
|
||||
}
|
||||
|
||||
function queryReceived(queryMessage) {
|
||||
/*
|
||||
We expect here a JSON string with the following properties:
|
||||
|
||||
{
|
||||
"equeryId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"queryType": 10,
|
||||
"emitterUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"targetUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"emitterUserProfileHandle": "Luis-Fernando-Molina",
|
||||
"targetUserProfileHandle": "Luis-Fernando-Molina",
|
||||
"emitterPostHash": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"targetPostHash": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"timestamp": 124234234234,
|
||||
"botId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"botAsset": "BTC",
|
||||
"botExchange": "Binance"
|
||||
}
|
||||
*/
|
||||
|
||||
let queryReceived = JSON.parse(queryMessage)
|
||||
let query = NT.modules.QUERY.newQuery()
|
||||
query.initialize(queryReceived)
|
||||
return query.execute()
|
||||
}
|
||||
}
|
||||
+109
-69
@@ -12,18 +12,26 @@ exports.newEvent = function newEvent() {
|
||||
}
|
||||
|
||||
const EVENT_TYPES = {
|
||||
|
||||
NEW_MULTI_MEDIA_POST: 10,
|
||||
REPLY_TO_MULTI_MEDIA_POST: 11,
|
||||
REPOST_MULTI_MEDIA: 12,
|
||||
QUOTE_REPOST_MULTI_MEDIA: 13,
|
||||
FOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS: 14,
|
||||
UNFOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS: 15,
|
||||
|
||||
NEW_TRADE_POST: 20,
|
||||
REPLY_TO_TRADE_POST: 21,
|
||||
RE_POST_TRADE: 22,
|
||||
QUOTE_REPOST_TRADE: 23,
|
||||
FOLLOW_USER_PROFILE_TRADE_POSTS: 24,
|
||||
UNFOLLOW_USER_PROFILE_TRADE_POSTS: 25,
|
||||
|
||||
ADD_BOT: 50,
|
||||
REMOVE_BOT: 51,
|
||||
ENABLE_BOT: 52,
|
||||
DISABLE_BOT: 53,
|
||||
|
||||
ADD_REACTION_LIKE: 100,
|
||||
ADD_REACTION_LOVE: 101,
|
||||
ADD_REACTION_HAHA: 102,
|
||||
@@ -31,6 +39,7 @@ exports.newEvent = function newEvent() {
|
||||
ADD_REACTION_SAD: 104,
|
||||
ADD_REACTION_ANGRY: 105,
|
||||
ADD_REACTION_HUG: 106,
|
||||
|
||||
REMOVE_REACTION_LIKE: 200,
|
||||
REMOVE_REACTION_LOVE: 201,
|
||||
REMOVE_REACTION_HAHA: 202,
|
||||
@@ -47,79 +56,71 @@ exports.newEvent = function newEvent() {
|
||||
thisObject.targetUserProfile = undefined
|
||||
}
|
||||
|
||||
function initialize(eventMessage) {
|
||||
/*
|
||||
We expect here a JSON string with the following properties:
|
||||
function initialize(eventReceived) {
|
||||
|
||||
{
|
||||
"eventId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"eventType": 10,
|
||||
"emitterUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"targetUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"emitterPostHash": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"targetPostHash": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"asset": "BTC",
|
||||
"timestamp": 124234234234
|
||||
}
|
||||
*/
|
||||
|
||||
let event = JSON.parse(eventMessage)
|
||||
|
||||
thisObject.emitterUserProfile = NT.memory.USER_PROFILES.get(event.emitterUserProfileId)
|
||||
thisObject.emitterUserProfile = NT.memory.USER_PROFILES_BY_ID.get(eventReceived.emitterUserProfileId)
|
||||
if (thisObject.emitterUserProfile === undefined) {
|
||||
/* The message is ignored */
|
||||
return
|
||||
throw ('Emitter User Profile Not Found.')
|
||||
}
|
||||
thisObject.emitterUserProfile.emitterEventsCount++
|
||||
|
||||
thisObject.targetUserProfile = NT.memory.USER_PROFILES.get(event.targetUserProfileId)
|
||||
thisObject.targetUserProfile = NT.memory.USER_PROFILES_BY_ID.get(eventReceived.targetUserProfileId)
|
||||
if (thisObject.targetUserProfile === undefined) {
|
||||
/* We thow an exception when it does not have a target user profile and is required*/
|
||||
if (
|
||||
event.eventType !== EVENT_TYPES.NEW_MULTI_MEDIA_POST &&
|
||||
event.eventType !== EVENT_TYPES.NEW_TRADE_POST
|
||||
)
|
||||
eventReceived.eventType !== EVENT_TYPES.NEW_MULTI_MEDIA_POST &&
|
||||
eventReceived.eventType !== EVENT_TYPES.NEW_TRADE_POST
|
||||
) {
|
||||
throw ('Target User Profile Not Found.')
|
||||
}
|
||||
} else {
|
||||
thisObject.targetUserProfile.targetEventsCount++
|
||||
}
|
||||
|
||||
thisObject.eventId = event.eventId
|
||||
thisObject.eventType = event.eventType
|
||||
thisObject.asset = event.asset
|
||||
thisObject.timestamp = event.timestamp
|
||||
|
||||
thisObject.eventId = eventReceived.eventId
|
||||
thisObject.eventType = eventReceived.eventType
|
||||
thisObject.asset = eventReceived.asset
|
||||
thisObject.timestamp = eventReceived.timestamp
|
||||
/*
|
||||
Is is a new post?
|
||||
*/
|
||||
if (
|
||||
event.eventType === EVENT_TYPES.NEW_MULTI_MEDIA_POST ||
|
||||
event.eventType === EVENT_TYPES.REPLY_TO_MULTI_MEDIA_POST ||
|
||||
event.eventType === EVENT_TYPES.REPOST_MULTI_MEDIA ||
|
||||
event.eventType === EVENT_TYPES.QUOTE_REPOST_MULTI_MEDIA ||
|
||||
event.eventType === EVENT_TYPES.NEW_TRADE_POST ||
|
||||
event.eventType === EVENT_TYPES.REPLY_TO_TRADE_POST ||
|
||||
event.eventType === EVENT_TYPES.RE_POST_TRADE ||
|
||||
event.eventType === EVENT_TYPES.QUOTE_REPOST_TRADE
|
||||
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
|
||||
) {
|
||||
let post = NT.modules.POST.newPost()
|
||||
post.initialize(
|
||||
event.emitterPostHash,
|
||||
event.targetPostHash,
|
||||
thisObject.eventType,
|
||||
thisObject.emitterUserProfile,
|
||||
thisObject.asset,
|
||||
thisObject.timestamp
|
||||
)
|
||||
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.emitterUserProfile.addPost(
|
||||
eventReceived.emitterPostHash,
|
||||
eventReceived.targetPostHash,
|
||||
thisObject.eventType,
|
||||
thisObject.emitterUserProfile,
|
||||
thisObject.timestamp
|
||||
)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
/*
|
||||
Is is a following?
|
||||
*/
|
||||
if (
|
||||
event.eventType === EVENT_TYPES.FOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS ||
|
||||
event.eventType === EVENT_TYPES.UNFOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS ||
|
||||
event.eventType === EVENT_TYPES.FOLLOW_USER_PROFILE_TRADE_POSTS ||
|
||||
event.eventType === EVENT_TYPES.UNFOLLOW_USER_PROFILE_TRADE_POSTS
|
||||
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
|
||||
) {
|
||||
switch (event.eventType) {
|
||||
switch (eventReceived.eventType) {
|
||||
case EVENT_TYPES.FOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS: {
|
||||
thisObject.emitterUserProfile.addMultiMediaPostsFollowing(
|
||||
thisObject.targetUserProfile
|
||||
@@ -163,39 +164,78 @@ exports.newEvent = function newEvent() {
|
||||
Is is a Reaction?
|
||||
*/
|
||||
if (
|
||||
event.eventType === EVENT_TYPES.ADD_REACTION_LIKE ||
|
||||
event.eventType === EVENT_TYPES.ADD_REACTION_LOVE ||
|
||||
event.eventType === EVENT_TYPES.ADD_REACTION_HAHA ||
|
||||
event.eventType === EVENT_TYPES.ADD_REACTION_WOW ||
|
||||
event.eventType === EVENT_TYPES.ADD_REACTION_SAD ||
|
||||
event.eventType === EVENT_TYPES.ADD_REACTION_ANGRY ||
|
||||
event.eventType === EVENT_TYPES.ADD_REACTION_HUG
|
||||
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
|
||||
) {
|
||||
let targetPost = NT.memory.POSTS.get(event.targetPostHash)
|
||||
let targetPost = NT.memory.POSTS.get(eventReceived.targetPostHash)
|
||||
|
||||
if (targetPost === undefined) {
|
||||
throw ('Target Post Not Found')
|
||||
}
|
||||
|
||||
targetPost.addReaction(event.eventType - 100)
|
||||
targetPost.addReaction(eventReceived.eventType - 100)
|
||||
return
|
||||
}
|
||||
if (
|
||||
event.eventType === EVENT_TYPES.REMOVE_REACTION_LIKE ||
|
||||
event.eventType === EVENT_TYPES.REMOVE_REACTION_LOVE ||
|
||||
event.eventType === EVENT_TYPES.REMOVE_REACTION_HAHA ||
|
||||
event.eventType === EVENT_TYPES.REMOVE_REACTION_WOW ||
|
||||
event.eventType === EVENT_TYPES.REMOVE_REACTION_SAD ||
|
||||
event.eventType === EVENT_TYPES.REMOVE_REACTION_ANGRY ||
|
||||
event.eventType === EVENT_TYPES.REMOVE_REACTION_HUG
|
||||
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
|
||||
) {
|
||||
let targetPost = NT.memory.POSTS.get(event.targetPostHash)
|
||||
let targetPost = NT.memory.POSTS.get(eventReceived.targetPostHash)
|
||||
|
||||
if (targetPost === undefined) {
|
||||
throw ('Target Post Not Found')
|
||||
}
|
||||
|
||||
targetPost.removeReaction(event.eventType - 200)
|
||||
targetPost.removeReaction(eventReceived.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
|
||||
) {
|
||||
switch (eventReceived.eventType) {
|
||||
case EVENT_TYPES.ADD_BOT: {
|
||||
thisObject.emitterUserProfile.addBot(
|
||||
thisObject.botId,
|
||||
thisObject.botAsset,
|
||||
thisObject.botExchange
|
||||
)
|
||||
break
|
||||
}
|
||||
case EVENT_TYPES.REMOVE_BOT: {
|
||||
thisObject.emitterUserProfile.removeBot(
|
||||
thisObject.botId
|
||||
)
|
||||
break
|
||||
}
|
||||
case EVENT_TYPES.ENABLE_BOT: {
|
||||
thisObject.emitterUserProfile.enableBot(
|
||||
thisObject.botId
|
||||
)
|
||||
break
|
||||
}
|
||||
case EVENT_TYPES.DISABLE_BOT: {
|
||||
thisObject.emitterUserProfile.disableBot(
|
||||
thisObject.botId
|
||||
)
|
||||
break
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"eventId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"eventType": 10,
|
||||
"emitterUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"targetUserProfileId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"asset": "BTC",
|
||||
"timestamp": 124234234234,
|
||||
"postHash": "dasdhqJKGdadjlasgjaGSHAJGSDjhagsg",
|
||||
"postId": "a8de78f0-c3e4-4a2a-b7e8-f659073969db"
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
{
|
||||
"userProfiles": [
|
||||
{
|
||||
"username": "Luis-Fernando-Molina",
|
||||
"id": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"posts": [
|
||||
{
|
||||
"id": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"replyTo": "a8de78f0-c3e4-4a2a-b7e8-f659073969db"
|
||||
}
|
||||
],
|
||||
"replies": [
|
||||
{
|
||||
"id": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"replyTo": "a8de78f0-c3e4-4a2a-b7e8-f659073969db"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
|
||||
|
||||
global.NT = {
|
||||
memory: {
|
||||
USER_PROFILES: new Map(), // Here we will store the user profiles and their statistics.
|
||||
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.
|
||||
},
|
||||
modules: {
|
||||
EVENT: require('./event.js'),
|
||||
POST: require('./post.js')
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
We will add this event to the timeline
|
||||
*/
|
||||
NT.memory.TIMELINE.push()
|
||||
+9
-6
@@ -1,14 +1,15 @@
|
||||
exports.newPost = function newPost() {
|
||||
|
||||
let thisObject = {
|
||||
postHash: undefined,
|
||||
emitterPostHash: undefined,
|
||||
targetPostHash: undefined,
|
||||
postType: undefined,
|
||||
userProfile: undefined,
|
||||
asset: undefined,
|
||||
timestamp: undefined,
|
||||
replies: undefined,
|
||||
targetPost: undefined,
|
||||
reactionsCount: undefined,
|
||||
reactionTypesCount: undefined,
|
||||
addReaction: addReaction,
|
||||
removeReactions: removeReaction,
|
||||
initialize: initialize,
|
||||
@@ -36,6 +37,8 @@ exports.newPost = function newPost() {
|
||||
REACTION_HUG: 6
|
||||
}
|
||||
|
||||
thisObject.reactionTypesCount = 7
|
||||
|
||||
thisObject.reactionsCount = new Map()
|
||||
thisObject.reactionsCount.set(REACTION_TYPES.REACTION_LIKE, 0)
|
||||
thisObject.reactionsCount.set(REACTION_TYPES.REACTION_LOVE, 0)
|
||||
@@ -48,10 +51,10 @@ exports.newPost = function newPost() {
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
thisObject.postHash = undefined
|
||||
thisObject.emitterPostHash = undefined
|
||||
thisObject.targetPostHash = undefined
|
||||
thisObject.postType = undefined
|
||||
thisObject.userProfile = undefined
|
||||
thisObject.asset = undefined
|
||||
thisObject.timestamp = undefined
|
||||
thisObject.replies = undefined
|
||||
thisObject.targetPost = undefined
|
||||
@@ -62,7 +65,6 @@ exports.newPost = function newPost() {
|
||||
targetPostHash,
|
||||
postType,
|
||||
userProfile,
|
||||
asset,
|
||||
timestamp
|
||||
) {
|
||||
|
||||
@@ -70,8 +72,9 @@ exports.newPost = function newPost() {
|
||||
thisObject.targetPostHash = targetPostHash
|
||||
thisObject.postType = postType
|
||||
thisObject.userProfile = userProfile
|
||||
thisObject.asset = asset
|
||||
thisObject.timestamp = timestamp
|
||||
|
||||
thisObject.replies = []
|
||||
/*
|
||||
Let's find the Target Post
|
||||
*/
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
[
|
||||
{
|
||||
"userProfile": "Luis-Fernando-Molina",
|
||||
"id": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"followers": 0,
|
||||
"following": 0,
|
||||
"ranking": 0,
|
||||
"joined": 123423423423,
|
||||
"account": "asd23123aff23q2bcaa21447567"
|
||||
},
|
||||
{
|
||||
"userProfile": "Luis-Fernando-Molina",
|
||||
"id": "a8de78f0-c3e4-4a2a-b7e8-f659073969db",
|
||||
"followers": 0,
|
||||
"following": 0,
|
||||
"ranking": 0,
|
||||
"joined": 123423423423,
|
||||
"account": "asd23123aff23q2bcaa21447567"
|
||||
}
|
||||
]
|
||||
|
||||
// a map by userProfile would be needed.
|
||||
@@ -1,27 +0,0 @@
|
||||
[
|
||||
{
|
||||
"type": "post",
|
||||
"timestamp": 12343242342,
|
||||
"userProfile": "Luis-Fernando-Molina",
|
||||
"hash": "dhaHSkjasdmwhdajSHSJhewshed"
|
||||
},
|
||||
{
|
||||
"type": "post",
|
||||
"timestamp": 12343242342,
|
||||
"userProfile": "Luis-Fernando-Molina",
|
||||
"hash": "dhaHSkjasdmwhdajSHSJhewshed",
|
||||
"relatedEvent": "daawerewdhkasdSdGHGjdsasd"
|
||||
},
|
||||
{
|
||||
"type": "trade",
|
||||
"timestamp": 12343242342,
|
||||
"userProfile": "Luis-Fernando-Molina",
|
||||
"hash": "dhaHSkjasdmwhdajSHSJhewshed"
|
||||
},
|
||||
{
|
||||
"type": "post",
|
||||
"timestamp": 12343242342,
|
||||
"userProfile": "Luis-Fernando-Molina",
|
||||
"hash": "dhaHSkjasdmwhdajSHSJhewshed"
|
||||
}
|
||||
]
|
||||
+133
-10
@@ -2,28 +2,37 @@ exports.newUserProfile = function newUserProfile() {
|
||||
|
||||
let thisObject = {
|
||||
userProfieId: undefined,
|
||||
githubUsername: undefined,
|
||||
userProfileHandle: undefined,
|
||||
blockchainAccount: undefined,
|
||||
multiMediaPostsFollowing: undefined,
|
||||
multiMediaPostsFollowers: undefined,
|
||||
tradePostsFollowing: undefined,
|
||||
tradePostsFollowers: undefined,
|
||||
ranking: undefined,
|
||||
events: undefined,
|
||||
multiMediaPostFollowingCount: undefined,
|
||||
multiMediaPostFollowersCount: undefined,
|
||||
tradePostsFollowingCount: undefined,
|
||||
tradePostsFollowersCount: undefined,
|
||||
eventsCount: undefined,
|
||||
emitterEventsCount: undefined,
|
||||
targetEventsCount: undefined,
|
||||
postsCount: undefined,
|
||||
addMultiMediaPostsFollowing: addMultiMediaPostsFollowing,
|
||||
removeMultiMediaPostsFollowing: removeMultiMediaPostsFollowing,
|
||||
addTradePostsFollowing: addTradePostsFollowing,
|
||||
botsCount: undefined,
|
||||
bots: undefined,
|
||||
posts: undefined,
|
||||
addPost: addPost,
|
||||
removePost: removePost,
|
||||
addMultiMediaPostsFollowing: addMultiMediaPostsFollowing,
|
||||
removeMultiMediaPostsFollowing: removeMultiMediaPostsFollowing,
|
||||
addTradePostsFollowing: addTradePostsFollowing,
|
||||
removeTradePostsFollowing: removeTradePostsFollowing,
|
||||
addMultiMediaPostsFollower: addMultiMediaPostsFollower,
|
||||
removeMultiMediaPostsFollower: removeMultiMediaPostsFollower,
|
||||
addTradePostsFollower: addTradePostsFollower,
|
||||
removeTradePostsFollower: removeTradePostsFollower,
|
||||
addBot: addBot,
|
||||
removeBot: removeBot,
|
||||
enableBot: enableBot,
|
||||
disableBot: disableBot,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
@@ -31,7 +40,14 @@ exports.newUserProfile = function newUserProfile() {
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
thisObject.multiMediaPostsFollowing = undefined
|
||||
thisObject.multiMediaPostsFollowers = undefined
|
||||
|
||||
thisObject.tradePostsFollowing = undefined
|
||||
thisObject.tradePostsFollowers = undefined
|
||||
|
||||
thisObject.posts = undefined
|
||||
thisObject.bots = undefined
|
||||
}
|
||||
|
||||
function initialize() {
|
||||
@@ -42,17 +58,64 @@ exports.newUserProfile = function newUserProfile() {
|
||||
thisObject.tradePostsFollowing = new Map()
|
||||
thisObject.tradePostsFollowers = new Map()
|
||||
|
||||
thisObject.events = [] // Dont know what this is
|
||||
|
||||
thisObject.multiMediaPostFollowingCount = 0
|
||||
thisObject.multiMediaPostFollowersCount = 0
|
||||
thisObject.tradePostsFollowingCount = 0
|
||||
thisObject.tradePostsFollowersCount = 0
|
||||
thisObject.eventsCount = 0
|
||||
thisObject.emitterEventsCount = 0
|
||||
thisObject.targetEventsCount = 0
|
||||
thisObject.postsCount = 0
|
||||
thisObject.botsCount = 0
|
||||
|
||||
thisObject.posts = []
|
||||
thisObject.bots = undefined
|
||||
}
|
||||
|
||||
|
||||
function addPost(
|
||||
emitterPostHash,
|
||||
targetPostHash,
|
||||
postType,
|
||||
userProfile,
|
||||
timestamp
|
||||
) {
|
||||
if (NT.memory.POSTS.get(emitterPostHash) !== undefined) {
|
||||
throw ('Post Already Exists.')
|
||||
}
|
||||
|
||||
let post = NT.modules.POST.newPost()
|
||||
post.initialize(
|
||||
emitterPostHash,
|
||||
targetPostHash,
|
||||
postType,
|
||||
userProfile,
|
||||
timestamp
|
||||
)
|
||||
|
||||
thisObject.posts.push(post)
|
||||
NT.memory.POSTS.set(emitterPostHash, post)
|
||||
thisObject.postsCount++
|
||||
}
|
||||
|
||||
function removePost(
|
||||
emitterPostHash
|
||||
) {
|
||||
if (NT.memory.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-- {
|
||||
if (thisObject.posts[i].emitterPostHash === emitterPostHash) {
|
||||
thisObject.posts.splice(i, 1)
|
||||
break
|
||||
}
|
||||
}
|
||||
NT.memory.POSTS.delete(emitterPostHash)
|
||||
thisObject.postsCount--
|
||||
}
|
||||
|
||||
function addMultiMediaPostsFollowing(
|
||||
userProfile
|
||||
) {
|
||||
@@ -124,4 +187,64 @@ exports.newUserProfile = function newUserProfile() {
|
||||
thisObject.tradePostsFollowersCount--
|
||||
}
|
||||
}
|
||||
|
||||
function addBot(
|
||||
botId,
|
||||
botAsset,
|
||||
botExchange
|
||||
) {
|
||||
if (thisObject.bots.get(botId) !== undefined) {
|
||||
throw ('Bot Already Exists.')
|
||||
}
|
||||
|
||||
let bot = NT.modules.BOTS.newBot()
|
||||
bot.initialize(
|
||||
botId,
|
||||
botAsset,
|
||||
botExchange
|
||||
)
|
||||
thisObject.bots.set(botId, bot)
|
||||
thisObject.botsCount++
|
||||
}
|
||||
|
||||
function removeBot(
|
||||
botId
|
||||
) {
|
||||
if (thisObject.bots.get(botId) === undefined) {
|
||||
throw ('Bot Does Not Exist.')
|
||||
}
|
||||
thisObject.bots.get(botId).finalize()
|
||||
thisObject.bots.delete(botId)
|
||||
thisObject.botsCount--
|
||||
}
|
||||
|
||||
function enableBot(
|
||||
botId
|
||||
) {
|
||||
let bot = thisObject.bots.get(botId)
|
||||
if (bot === undefined) {
|
||||
throw ('Bot Does Not Exist.')
|
||||
}
|
||||
|
||||
if (bot.enabled === true) {
|
||||
throw ('Bot Already Enabled.')
|
||||
}
|
||||
|
||||
bot.enabled = true
|
||||
}
|
||||
|
||||
function disableBot(
|
||||
botId
|
||||
) {
|
||||
let bot = thisObject.bots.get(botId)
|
||||
if (bot === undefined) {
|
||||
throw ('Bot Does Not Exist.')
|
||||
}
|
||||
|
||||
if (bot.enabled === false) {
|
||||
throw ('Bot Already Disabled.')
|
||||
}
|
||||
|
||||
bot.enabled = false
|
||||
}
|
||||
}
|
||||
@@ -539,7 +539,7 @@
|
||||
"votesAndClaimsPrograms": {
|
||||
"type": "Votes And Claims Programs",
|
||||
"name": "New Votes And Claims Programs",
|
||||
"config": "{\n \"percentage\": 50\n}",
|
||||
"config": "{\n \"percentage\": 10\n}",
|
||||
"project": "Governance",
|
||||
"votingProgram": {
|
||||
"type": "Voting Program",
|
||||
@@ -12078,7 +12078,7 @@
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
"isFrozen": false,
|
||||
"isCollapsed": false,
|
||||
"isCollapsed": true,
|
||||
"angleToParent": 2,
|
||||
"distanceToParent": 3,
|
||||
"arrangementStyle": 0
|
||||
@@ -12435,7 +12435,7 @@
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
"isFrozen": false,
|
||||
"isCollapsed": true,
|
||||
"isCollapsed": false,
|
||||
"angleToParent": 2,
|
||||
"distanceToParent": 3,
|
||||
"arrangementStyle": 0
|
||||
@@ -12471,7 +12471,7 @@
|
||||
"financialPrograms": {
|
||||
"type": "Financial Programs",
|
||||
"name": "New Financial Programs",
|
||||
"config": "{\n \"percentage\": 30\n}",
|
||||
"config": "{\n \"percentage\": 70\n}",
|
||||
"project": "Governance",
|
||||
"stakingProgram": {
|
||||
"type": "Staking Program",
|
||||
@@ -12543,7 +12543,7 @@
|
||||
{
|
||||
"type": "Delegate Power Switch",
|
||||
"name": "Phill",
|
||||
"config": "{\n \"percentage\": 30\n}",
|
||||
"config": "{\n \"percentage\": 35\n}",
|
||||
"project": "Governance",
|
||||
"delegatePowerSwitch": [],
|
||||
"userDelegates": [
|
||||
@@ -12759,7 +12759,7 @@
|
||||
{
|
||||
"type": "Delegate Power Switch",
|
||||
"name": "Carl",
|
||||
"config": "{\n \"percentage\": 5\n}",
|
||||
"config": "{\n \"percentage\": 0\n}",
|
||||
"project": "Governance",
|
||||
"delegatePowerSwitch": [],
|
||||
"userDelegates": [
|
||||
@@ -12797,7 +12797,9 @@
|
||||
"referenceParentCombinedNodePath": [
|
||||
[
|
||||
"cozed-gh",
|
||||
"User Profile"
|
||||
"User Profile",
|
||||
"Governance",
|
||||
"07f0b13a-a50f-4488-8a2c-a3f8f08e889d"
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -13162,7 +13164,7 @@
|
||||
"floatingObject": {
|
||||
"isPinned": false,
|
||||
"isFrozen": false,
|
||||
"isCollapsed": true,
|
||||
"isCollapsed": false,
|
||||
"angleToParent": 1,
|
||||
"distanceToParent": 3,
|
||||
"arrangementStyle": 0
|
||||
|
||||
Reference in new issue
Block a user