User Profile re-written
This commit is contained in:
1 parent
b7fdc7feb7
commit
1cd04a056b
10 files changed
+308
-118
No files matched your search
+70
-84
@@ -1,30 +1,33 @@
|
||||
exports.newUserProfile = function newUserProfile() {
|
||||
|
||||
let thisObject = {
|
||||
|
||||
userProfileId: undefined,
|
||||
userProfileHandle: undefined,
|
||||
blockchainAccount: undefined,
|
||||
ranking: undefined,
|
||||
|
||||
following: undefined,
|
||||
followers: undefined,
|
||||
followingCount: undefined,
|
||||
followersCount: undefined,
|
||||
posts: undefined,
|
||||
bots: undefined,
|
||||
|
||||
emitterEventsCount: undefined,
|
||||
targetEventsCount: undefined,
|
||||
postsCount: undefined,
|
||||
botsCount: undefined,
|
||||
bots: undefined,
|
||||
posts: undefined,
|
||||
|
||||
addPost: addPost,
|
||||
removePost: removePost,
|
||||
|
||||
addFollowing: addFollowing,
|
||||
removeFollowing: removeFollowing,
|
||||
addFollower: addFollower,
|
||||
removeFollower: removeFollower,
|
||||
|
||||
addBot: addBot,
|
||||
removeBot: removeBot,
|
||||
enableBot: enableBot,
|
||||
disableBot: disableBot,
|
||||
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
@@ -32,28 +35,24 @@ exports.newUserProfile = function newUserProfile() {
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
|
||||
thisObject.following = undefined
|
||||
thisObject.followers = undefined
|
||||
|
||||
thisObject.posts = undefined
|
||||
thisObject.bots = undefined
|
||||
|
||||
}
|
||||
|
||||
function initialize() {
|
||||
|
||||
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 +63,127 @@ 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
|
||||
) {
|
||||
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
|
||||
)
|
||||
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) {
|
||||
throw ('Bot Already Enabled.')
|
||||
}
|
||||
|
||||
bot.enabled = 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) {
|
||||
throw ('Bot Already Disabled.')
|
||||
}
|
||||
|
||||
bot.enabled = false
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user