Query Post Replies Implemented
This commit is contained in:
1 parent
830a92c486
commit
658bfd2b0d
3 files changed
+161
-21
No files matched your search
@@ -44,7 +44,7 @@ exports.newProfilePosts = function newProfilePosts() {
|
||||
}
|
||||
|
||||
if (queryReceived.initialPostIndex === INITIAL_POST_INDEX_LAST) {
|
||||
queryReceived.initialPostIndex = thisObject.posts.length - 1
|
||||
queryReceived.initialPostIndex = thisObject.profile.posts.length - 1
|
||||
}
|
||||
|
||||
if (queryReceived.initialPostIndex === INITIAL_POST_INDEX_FIRST) {
|
||||
@@ -75,7 +75,7 @@ exports.newProfilePosts = function newProfilePosts() {
|
||||
throw ('Amount Requested Above Max.')
|
||||
}
|
||||
/*
|
||||
Validate Amount Requested
|
||||
Validate Direction
|
||||
*/
|
||||
if (queryReceived.direction === undefined) {
|
||||
throw ('Direction Undefined.')
|
||||
@@ -90,33 +90,42 @@ exports.newProfilePosts = function newProfilePosts() {
|
||||
}
|
||||
|
||||
function execute() {
|
||||
|
||||
let response = []
|
||||
switch (thisObject.direction) {
|
||||
case DIRECTION_FUTURE: {
|
||||
for (let i = thisObject.initialPostIndex; i < thisObject.initialPostIndex + thisObject.amountRequested; i++) {
|
||||
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)
|
||||
addPostToResponse(post)
|
||||
}
|
||||
}
|
||||
case DIRECTION_PAST: {
|
||||
for (let i = thisObject.initialPostIndex; i > thisObject.initialPostIndex - thisObject.amountRequested; i--) {
|
||||
let post = thisObject.profile.posts[i]
|
||||
if (post === undefined) { break }
|
||||
addPostToResponse(post)
|
||||
}
|
||||
}
|
||||
}
|
||||
return response
|
||||
|
||||
function addPostToResponse(post) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user