Post.js supports Users and Bots

This commit is contained in:
Luis Fernando Molina committed 2021-08-27 20:50:53 +02:00
1 parent f36f1d2e29
commit 78ea072b9f
4 files changed
+64 -57

No files matched your search

-5
View File
@@ -13,8 +13,6 @@ exports.newUserProfile = function newUserProfile() {
emitterEventsCount: undefined,
targetEventsCount: undefined,
postsCount: undefined,
botsCount: undefined,
bots: undefined,
posts: undefined,
addPost: addPost,
removePost: removePost,
@@ -33,7 +31,6 @@ exports.newUserProfile = function newUserProfile() {
thisObject.followers = undefined
thisObject.posts = undefined
thisObject.bots = undefined
}
function initialize() {
@@ -47,10 +44,8 @@ exports.newUserProfile = function newUserProfile() {
thisObject.emitterEventsCount = 0
thisObject.targetEventsCount = 0
thisObject.postsCount = 0
thisObject.botsCount = 0
thisObject.posts = []
thisObject.bots = undefined
}
function addPost(
+41 -35
View File
@@ -4,6 +4,8 @@ exports.newEvent = function newEvent() {
eventId: undefined,
emitterUserProfileId: undefined,
targetUserProfileId: undefined,
emitterBotProfileId: undefined,
targetBotProfileId: undefined,
emitterPostHash: undefined,
targetPostHash: undefined,
timestamp: undefined,
@@ -16,19 +18,19 @@ 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_USER_POST: 10,
REPLY_TO_USER_POST: 11,
REPOST_USER_POST: 12,
QUOTE_REPOST_USER_POST: 13,
FOLLOW_USER_PROFILE: 14,
UNFOLLOW_USER_PROFILE: 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,
NEW_BOT_POST: 20,
REPLY_TO_BOT_POST: 21,
REPOST_BOT_POST: 22,
QUOTE_REPOST_BOT_POST: 23,
FOLLOW_BOT_PROFILE: 24,
UNFOLLOW_BOT_PROFILE: 25,
ADD_BOT: 50,
REMOVE_BOT: 51,
@@ -66,6 +68,8 @@ exports.newEvent = function newEvent() {
thisObject.eventId = eventReceived.eventId
thisObject.emitterUserProfileId = eventReceived.emitterUserProfileId
thisObject.targetUserProfileId = eventReceived.targetUserProfileId
thisObject.emitterBotProfileId = eventReceived.emitterBotProfileId
thisObject.targetBotProfileId = eventReceived.targetBotProfileId
thisObject.emitterPostHash = eventReceived.emitterPostHash
thisObject.targetPostHash = eventReceived.targetPostHash
thisObject.timestamp = eventReceived.timestamp
@@ -87,8 +91,8 @@ exports.newEvent = function newEvent() {
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_MULTI_MEDIA_POST &&
thisObject.eventType !== EVENT_TYPES.NEW_TRADE_POST
thisObject.eventType !== EVENT_TYPES.NEW_USER_POST &&
thisObject.eventType !== EVENT_TYPES.NEW_BOT_POST
) {
throw ('Target User Profile Not Found.')
}
@@ -99,27 +103,29 @@ exports.newEvent = function newEvent() {
Is is a new post?
*/
if (
thisObject.eventType === EVENT_TYPES.NEW_MULTI_MEDIA_POST ||
thisObject.eventType === EVENT_TYPES.REPLY_TO_MULTI_MEDIA_POST ||
thisObject.eventType === EVENT_TYPES.REPOST_MULTI_MEDIA ||
thisObject.eventType === EVENT_TYPES.QUOTE_REPOST_MULTI_MEDIA ||
thisObject.eventType === EVENT_TYPES.NEW_TRADE_POST ||
thisObject.eventType === EVENT_TYPES.REPLY_TO_TRADE_POST ||
thisObject.eventType === EVENT_TYPES.RE_POST_TRADE ||
thisObject.eventType === EVENT_TYPES.QUOTE_REPOST_TRADE
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 (
thisObject.eventType === EVENT_TYPES.NEW_MULTI_MEDIA_POST ||
thisObject.eventType === EVENT_TYPES.REPLY_TO_MULTI_MEDIA_POST ||
thisObject.eventType === EVENT_TYPES.REPOST_MULTI_MEDIA ||
thisObject.eventType === EVENT_TYPES.QUOTE_REPOST_MULTI_MEDIA
thisObject.eventType === EVENT_TYPES.NEW_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,
thisObject.eventType - 10,
thisObject.timestamp
)
}
@@ -130,13 +136,13 @@ exports.newEvent = function newEvent() {
Is is a following?
*/
if (
thisObject.eventType === EVENT_TYPES.FOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS ||
thisObject.eventType === EVENT_TYPES.UNFOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS ||
thisObject.eventType === EVENT_TYPES.FOLLOW_USER_PROFILE_TRADE_POSTS ||
thisObject.eventType === EVENT_TYPES.UNFOLLOW_USER_PROFILE_TRADE_POSTS
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_MULTI_MEDIA_POSTS: {
case EVENT_TYPES.FOLLOW_USER_PROFILE: {
emitterUserProfile.addFollowing(
targetUserProfile
)
@@ -145,7 +151,7 @@ exports.newEvent = function newEvent() {
)
break
}
case EVENT_TYPES.UNFOLLOW_USER_PROFILE_MULTI_MEDIA_POSTS: {
case EVENT_TYPES.UNFOLLOW_USER_PROFILE: {
emitterUserProfile.removeFollowing(
targetUserProfile
)
@@ -154,7 +160,7 @@ exports.newEvent = function newEvent() {
)
break
}
case EVENT_TYPES.FOLLOW_USER_PROFILE_TRADE_POSTS: {
case EVENT_TYPES.FOLLOW_BOT_PROFILE: {
emitterUserProfile.addTradePostsFollowing(
targetUserProfile
)
@@ -163,7 +169,7 @@ exports.newEvent = function newEvent() {
)
break
}
case EVENT_TYPES.UNFOLLOW_USER_PROFILE_TRADE_POSTS: {
case EVENT_TYPES.UNFOLLOW_BOT_PROFILE: {
emitterUserProfile.removeTradePostsFollowing(
targetUserProfile
)
+16 -16
View File
@@ -3,6 +3,8 @@ exports.newPost = function newPost() {
let thisObject = {
emitterUserProfileId: undefined,
targetUserProfileId: undefined,
emitterBotProfileId: undefined,
targetBotProfileId: undefined,
emitterPostHash: undefined,
targetPostHash: undefined,
postType: undefined,
@@ -17,14 +19,10 @@ exports.newPost = function newPost() {
}
const POST_TYPES = {
NEW_MULTI_MEDIA_POST: 10,
REPLY_TO_MULTI_MEDIA_POST: 11,
REPOST_MULTI_MEDIA: 12,
QUOTE_REPOST_MULTI_MEDIA: 13,
NEW_TRADE_POST: 20,
REPLY_TO_TRADE_POST: 21,
RE_POST_TRADE: 22,
QUOTE_REPOST_TRADE: 23
NEW_POST: 0,
REPLY_TO_POST: 1,
REPOST_: 2,
QUOTE_REPOST_: 3
}
const REACTION_TYPES = {
@@ -53,6 +51,8 @@ exports.newPost = function newPost() {
function finalize() {
thisObject.emitterUserProfileId = undefined
thisObject.targetUserProfileId = undefined
thisObject.emitterBotProfileId = undefined
thisObject.targetBotProfileId = undefined
thisObject.emitterPostHash = undefined
thisObject.targetPostHash = undefined
thisObject.postType = undefined
@@ -63,6 +63,8 @@ exports.newPost = function newPost() {
function initialize(
emitterUserProfileId,
targetUserProfileId,
emitterBotProfileId,
targetBotProfileId,
emitterPostHash,
targetPostHash,
postType,
@@ -71,6 +73,8 @@ exports.newPost = function newPost() {
thisObject.emitterUserProfileId = emitterUserProfileId
thisObject.targetUserProfileId = targetUserProfileId
thisObject.emitterBotProfileId = emitterBotProfileId
thisObject.targetBotProfileId = targetBotProfileId
thisObject.emitterPostHash = emitterPostHash
thisObject.targetPostHash = targetPostHash
thisObject.postType = postType
@@ -83,12 +87,9 @@ exports.newPost = function newPost() {
let targetPost
if (
event.eventType === POST_TYPES.REPLY_TO_MULTI_MEDIA_POST ||
event.eventType === POST_TYPES.REPOST_MULTI_MEDIA ||
event.eventType === POST_TYPES.QUOTE_REPOST_MULTI_MEDIA ||
event.eventType === POST_TYPES.REPLY_TO_TRADE_POST ||
event.eventType === POST_TYPES.RE_POST_TRADE ||
event.eventType === POST_TYPES.QUOTE_REPOST_TRADE
thisObject.postType === POST_TYPES.REPLY_TO_POST ||
thisObject.postType === POST_TYPES.REPOST_ ||
thisObject.postType === POST_TYPES.QUOTE_REPOST_
) {
targetPost = NT.memory.maps.POSTS.get(thisObject.targetPostHash)
@@ -100,8 +101,7 @@ exports.newPost = function newPost() {
Let's add this post to the replies of the Target Post
*/
if (
event.eventType === POST_TYPES.REPLY_TO_MULTI_MEDIA_POST ||
event.eventType === POST_TYPES.REPLY_TO_TRADE_POST
thisObject.postType === POST_TYPES.REPLY_TO_POST
) {
targetPost.replies.push(thisObject)
}
+7 -1
View File
@@ -53,10 +53,12 @@ exports.newUserProfile = function newUserProfile() {
thisObject.botsCount = 0
thisObject.posts = []
thisObject.bots = undefined
thisObject.bots = []
}
function addPost(
emitterUserProfileId,
targetUserProfileId,
emitterPostHash,
targetPostHash,
postType,
@@ -69,6 +71,10 @@ exports.newUserProfile = function newUserProfile() {
let post = NT.modules.POST.newPost()
post.initialize(
emitterUserProfileId,
targetUserProfileId,
undefined,
undefined,
emitterPostHash,
targetPostHash,
postType,