mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 10:18:48 +00:00
All done with only showing posts user is interested in
This commit is contained in:
parent
953d58ea12
commit
54ba36abeb
@ -65,36 +65,46 @@ exports.getallPosts = (req, res) => {
|
||||
};
|
||||
|
||||
exports.getFollowedPosts = (req, res) => {
|
||||
let posts = [];
|
||||
var followers_list = admin.firestore().collection("users").doc(req.user.handle).collection("followedUsers");
|
||||
var post_query = admin.firestore().collection("posts");
|
||||
|
||||
followers_list.get()
|
||||
.then(function(allFollowers) {
|
||||
var followers_likedTopics = new Map();
|
||||
|
||||
allFollowers.forEach(function(followers) {
|
||||
var post_query = admin.firestore().collection("posts").where("userHandle", "==", followers.data().handle);
|
||||
post_query.get()
|
||||
.then(function(allPosts) {
|
||||
allPosts.forEach(function(doc) {
|
||||
var follow = false;
|
||||
doc.data().microBlogTopics.forEach(function(topics) {
|
||||
follow |= followers.data().followedTopics.includes(topics);
|
||||
})
|
||||
if(follow) {
|
||||
posts.push(doc.data());
|
||||
}
|
||||
});
|
||||
return res.status(200).json(posts);
|
||||
})
|
||||
.catch(function(err) {
|
||||
res.status(500).send("Failed to retrieve posts from database.", err);
|
||||
});
|
||||
followers_likedTopics.set(followers.data().handle, followers.data().followedTopics);
|
||||
});
|
||||
|
||||
post_query.get()
|
||||
.then(function(allPosts) {
|
||||
let posts = [];
|
||||
allPosts.forEach(function(doc) {
|
||||
if(doc.data().userHandle === req.user.handle) {
|
||||
posts.push(doc.data());
|
||||
}
|
||||
|
||||
if(followers_likedTopics.has(doc.data().userHandle)) {
|
||||
//posts.push(doc.data());
|
||||
|
||||
doc.data().microBlogTopics.forEach(function(topic) {
|
||||
if(followers_likedTopics.get(doc.data().userHandle).includes(topic)) {
|
||||
posts.push(doc.data());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return res.status(200).json(posts);
|
||||
})
|
||||
.catch(function(err) {
|
||||
res.status(500).send("Failed to retrieve any posts.", err);
|
||||
});
|
||||
//return res.status(200).json(posts);
|
||||
})
|
||||
.then(function() {
|
||||
//res.status(200).send("Successfully retrieved all interesting posts from followed users.");
|
||||
return;
|
||||
})
|
||||
.catch(function(err) {
|
||||
res.status(500).send("Failed to retrieve any post.", err);
|
||||
res.status(500).send("Failed to retrieve any posts.", err);
|
||||
});
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user