关注用户的 Firebase 最新供稿 [英] Firebase newest feed for following users

查看:22
本文介绍了关注用户的 Firebase 最新供稿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Angularjs 和 Firebase.现在我是 firebase 的新手,我正在努力为我的问题寻找解决方案.

I'm working with Angularjs and Firebase. Right now I'm new at firebase for this I'm struggling to find solutions for my issues.

想象一下我是这样对用户进行排序的

Imagine I'm sorting users like this

users:{
    facebook:123456789:{
        blog: [{
            // List of blogs
        }],
        following: [{
            // List of users auth.ids
        }]
    },
    facebook:123456780:{
        blog: [{
            // List of blogs
        }],
        following: [{
            // List of users auth.ids
        }]
    }
}

并登录用户博客对象并像这样迭代并将其推送到数组

And getting logged in user blog object and iterating and pushing it to the array like this

var blogRef = new Firebase(FirebaseUrl + "/users/" + authData.uid + "/blog");
var userBlog = $firebaseArray(blogRef);
var userBlogDatas = []
blogRef.limitToLast(10).on("child_added", function(snapshot) {
    var snap = snapshot.val();                
    userBlogDatas.push(snap);
});

到目前为止一切正常.

但是我如何从关注用户的提要中获取最新的博文.现在我有一些想法代表获取用户博客数据并将它们推送到数组中.我不确定它是否正确...

But how can i get latest blogposts from feeds from following users. Right now I have some idea which represents getting user blog datas and pushing them into array. I'm not sure is it right way or not...

我还阅读了 https://github.com/firebase/firefeed/blob/master/www/js/firefeed.js 代码,但我无法为自己获取任何信息.

I also read https://github.com/firebase/firefeed/blob/master/www/js/firefeed.js code but I could not get any information for myself.

任何想法都会很有帮助.

Any ideas will be really helpfull.

谢谢

推荐答案

如果我正确理解了问题,有几种方法可以做到这一点.

There's a couple of ways to do this if I am understanding the question correctly.

一种方法是不存储 user_id,而是将用户 id 存储为键,将博客 id 存储为值,如

One way is that instead of storing the user_id, store the user id as a key and the blog id as the value like

users
    facebook:123456789
        blog
            // List of blogs
        following
            user_id_0: blog_id_x
            user_id_1: blog_id_y

然后你可以在下面的节点中为每个博客添加一个观察者.您可以从键/值对中获取路径.在这种情况下,Facebook:123456789 如下:

Then you can add an observer to each blog in the following node. You can get the path from the key/value pair. In this case Facebook:123456789 is following:

/users/user_id_0/blog/blog_id_x
/users/user_id_1/blog/blog_id_y

另一种选择是在以下节点中创建一个包含两个值的子节点:user_id 和 blog_id.

Another option would be to create a child node within the following node that contains two values: the user_id and blog_id.

users
    facebook:123456789
        blog
            // List of blogs
        following
            follow_id_0
              userid: user_id_0
              blog: blog_id_0
            follow_id_1
              userid: user_id_0
              blog: blog_id_1

在这种情况下,facebook:123456789 正在关注 user_id_0 的博客 0 和博客 1

In this case, facebook:123456789 is following user_id_0's blog 0 and blog 1

注意:user_id_0 和 user_id_1 实际上是 Facebook:abcdefg 的用户 ID

Note: user_id_0 and user_id_1 are actually Facebook:abcdefg users id's

这篇关于关注用户的 Firebase 最新供稿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆