Based on the comments and the structure in the question, the reason the data is becoming stale is due to how the data is stored in Firebase.
One option is that when a message is sent, a node is written with the message and then a reference to the senders info. That keeps everything fresh and up-to-date at all times
So say we have a users node with users stored with the users UID as the key to each node
users
uid_0
user_name: "Peter"
user_age: "32"
gender: "Male"
business_name: "Peter's Plumbing Place"
url: "http:...."
type: "Customer"
uid_1
user_name: "Ralph"
user_age: "47"
gener: "Male"
business_name: "Ralph's Repair Room"
url: "http:...."
type: "Employee"
then we have messages
messages
msg_0
msg_text: "Here's a message!"
from_uid: "uid_0"
to_uid: "uid_1"
timestamp: "20180110"
Then, user uid_1 adds a query observer to the messages node for any messages where to_uid is uid_1 so they are notified of the incoming message. When they receive it, they will also know it was sent by uid_0 and can pull up their name, profile image, age etc.
That way, all data is kept in sync and current and no stale data exists.
This is a typical implementation of a structure for a messaging app.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句