Real fix for showing your own posts ()

* Real fix for not showing your own posts ()

Instead of adding yourself as your follower at the moment of the creation of the user, it's better to change the getFeed.ts script to getAllPosts from users that you are following + posts from you.

* add same users posts in Feed function (refactor old hack way)

Co-authored-by: Gustavo Contreiras <guto.contreiras@gmail.com>
This commit is contained in:
Matthew Danics
2020-01-04 16:01:25 -05:00
committed by GitHub
parent 4252c71c7e
commit f1f3bd9582
6 changed files with 25 additions and 19 deletions

@ -14,19 +14,21 @@ exports.getFeedModule = function (req, res) {
function compileFeedPost() {
return __awaiter(this, void 0, void 0, function* () {
const following = yield getFollowing(uid, res);
let listOfPosts = yield getAllPosts(following, res);
let listOfPosts = yield getAllPosts(following, uid, res);
listOfPosts = [].concat.apply([], listOfPosts); // flattens list
res.send(listOfPosts);
});
}
compileFeedPost().then().catch();
};
function getAllPosts(following, res) {
function getAllPosts(following, uid, res) {
return __awaiter(this, void 0, void 0, function* () {
let listOfPosts = [];
for (let user in following) {
const listOfPosts = [];
for (const user in following) {
listOfPosts.push(yield getUserPosts(following[user], res));
}
// add the current user's posts to the feed so that your own posts appear in your feed
listOfPosts.push(yield getUserPosts(uid, res));
return listOfPosts;
});
}
@ -34,7 +36,7 @@ function getUserPosts(userId, res) {
const posts = admin.firestore().collection("insta_posts").where("ownerId", "==", userId).orderBy("timestamp");
return posts.get()
.then(function (querySnapshot) {
let listOfPosts = [];
const listOfPosts = [];
querySnapshot.forEach(function (doc) {
listOfPosts.push(doc.data());
});
@ -45,7 +47,7 @@ function getFollowing(uid, res) {
const doc = admin.firestore().doc(`insta_users/${uid}`);
return doc.get().then(snapshot => {
const followings = snapshot.data().following;
let following_list = [];
const following_list = [];
for (const following in followings) {
if (followings[following] === true) {
following_list.push(following);