Firebase中的引用属性 [英] Reference attribute in Firebase

查看:93
本文介绍了Firebase中的引用属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

firebase是否提供了引用属性的概念?

如果我想把我的在线状态(online | offline | away)状态通知我的所有朋友列表一个容易实现的就是定义引用属性say user @ status,并且如果它的值被改变了,它可以在任何定义的时候触发改变状态。这可以在Firebase中实现吗?

我正在尝试实现聊天用户状态更新。用户名/用户名(好友),姓名,在线状态],[用户名(好友) ,名称,在线状态],...

用户/ user-id-2 / [user-id(friend),name,online-status],[用户ID(朋友),名称,在线状态],...



如果一个特定的用户上线,那么我们现在需要更新他的状态给他们所有的用户手动在一个循环,以便他们得到状态更新...

是否有一个更好的方法来实现这样的后端触发器,如果​​一个字段更改更新其他字段...我们可以定义这样的规则还是定义某种引用指针?

解决方案

  users 
uid_1234
电子邮件:thing@yipee.com
在线:true
uid_5678
电子邮件:stuff@yahoo.com
在线:false
< code


$ b每个用户观察用户节点的变化。

当用户登录,将在线状态设置为true。所有其他用户将被通知这个用户状态改变,并可以相应地更新他们的用户界面。



注意:在登录时添加onDisonnect观察者到用户在线状态节点在断开连接时将其设置为假。


Does firebase provide reference attribute concept?

If I want to notify my online status (online | offline | away) status to all my friends list where I am part of, one easy to implement is to define reference attribute say user@status and if its value is changed it could trigger change status where ever it is defined. Can this be achieved in Firebase?

I am trying to implement chat user status updates. We have user list maintained

Users/user-id-1/[user-id(friend),name,online-status],[user-id(friend),name,online-status], ...

Users/user-id-2/[user-id(friend),name,online-status],[user-id(friend),name,online-status], ...

If a particular user comes online then currently we need to update his status to all their users manually in a loop so that they get status updates...

Is there a better way to implement such backend triggers where if one field is changed update other fields... Can we define such rules or define some kind of reference pointers?

解决方案

users
   uid_1234
     email: thing@yipee.com
     online: true
  uid_5678
     email: stuff@yahoo.com
     online: false

Each user observes the users node for changes.

When a user logs on, set the online status to true. All other users will be notified that this users status changed and can update their UI accordingly.

Side note: add a onDisonnect observer to a users online status node when they log on to set it to false upon disconnect.

这篇关于Firebase中的引用属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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