Yeah sure
Parse.Cloud.define("getHomeObjects", async (request) => {
const user = request.user;
const Post = Parse.Object.extend("Post");
const Follow = Parse.Object.extend("Follow");
const getFollow = new Parse.Query(Follow);
getFollow.equalTo("owner",user);
const getPosts = new Parse.Query(Post);
getPosts.matchesKeyInQuery("user","who",getFollow);
getPosts.include("user");
if(request.params.date!==undefined){
getPosts.lessThan("createdAt",request.params.date);
}
getPosts.exclude("words");
getPosts.descending("createdAt");
getPosts.limit(40);
const postList = await getPosts.find({useMasterKey:true});
if(postList.length<1){
return postList;
}
const Like = Parse.Object.extend("Like");
const getLikes = new Parse.Query(Like);
getLikes.equalTo("owner",user);
getLikes.containedIn("post",postList);
const likeList = await getLikes.find({useMasterKey:true});
var likeListIDs = [];
var i;
for(i=0;i<likeList.length;i++){
likeListIDs.push(likeList[i].get("post").id);
}
const SavedPost = Parse.Object.extend("SavedPost");
const getSaves = new Parse.Query(SavedPost);
getSaves.equalTo("owner",user);
getSaves.containedIn("post",postList);
const saveList = await getSaves.find({useMasterKey:true});
var saveListIDs = [];
var i;
for(i=0;i<saveList.length;i++){
saveListIDs.push(saveList[i].get("post").id);
}
const tpL = postList.map(post => ({
...post.toJSON(),
liked2: likeListIDs.indexOf(post.id) >= 0,
saved2: saveListIDs.indexOf(post.id) >= 0,
likenumber2:post.likenumber,
commentnumber2:post.commentnumber,
commentable2:post.commentable
}));
var lastList = [];
for(i=0;i<tpL.length;i++){
var post = tpL[i];
var jsonUser = post.user;
delete jsonUser.email;
delete jsonUser.ACL;
delete jsonUser.token;
jsonUser.__type = "Object";
jsonUser.className = "_User";
post.user=jsonUser;
post.likenumber2 = post.likenumber;
post.commentnumber2 = post.commentnumber;
post.commentable2 = post.commentable;
post.__type = "Object";
post.className = "Post";
lastList.push(post);
}
return lastList;
});