Closed domcini closed 5 years ago
You'd have to do a lot of querying, but your queries themselves won't be downloading large amounts of data until you start loading messages. Here's what I'd recommend:
uid
as the unique identifier for their user node in RTDB. This way you can fetch the user node directly without querying a collection of users.groups
array and fetch all of those groups from the groups
root.To answer your questions directly:
Would I have to create an array of groupIDs for each user, then loop through those IDs to get groups data (and so on)?
Yes. FUIIndexArray is a sample implementation of what you're describing, though it's in objc.
Would i have to query the current userID inside the groups node and add all relevant groups data to a 'Groups' array (and so on - or would this too long with large sets of data?)?
Yes, though if you're concerned with data size you can always just load the first N and then allow the user to load more later.
Or is there a more efficient way to do this?
There's some optimizations you can make around how frequently groups/channels will be created and destroyed as well as how many groups a user will likely belong to at one time, but otherwise there isn't really a more efficient way to do this.
I’m also finding it hard to understand how the data would be structured inside my code once I have retrieved it from the database (unless i were to use number 2), so i can display it in the relevant views. I could not imagine a standard Dictionary would be suitable for this?
A standard dictionary is not suitable since you have to load each corresponding key's value asynchronously.
How would I know which channels belonged to which groups, and which messages to which channels?
The easiest way would be to add a groupID
field to your channel object and a channelID
field to your message objects, since each message can only belong to one channel and each channel can only belong to one group.
I'm a relatively new developer to the Firebase/Swift communities and am facing a challenge slightly out of my current capacity. I’m looking to create a chat app similar to slack and my database looks as follows...
The current issue I’m facing is how to query the relevant data and how to link the data together.
I would like to display a collection view, populated with group images. Once a group is selected, display the relevant channels for this group in a table view below, then the relevant messages for the channel selected inside a new VC.
Would I have to create an array of groupIDs for each user, then loop through those IDs to get groups data (and so on)?
Would i have to query the current userID inside the groups node and add all relevant groups data to a 'Groups' array (and so on - or would this too long with large sets of data?)?
Or is there a more efficient way to do this?
I’m also finding it hard to understand how the data would be structured inside my code once I have retrieved it from the database (unless i were to use number 2), so i can display it in the relevant views. I could not imagine a standard Dictionary would be suitable for this?
E.g. How would I know which channels belonged to which groups, and which messages to which channels? This may be a simple solution, but right now i cant seem to find an answer.
With the following question in mind https://stackoverflow.com/questions/38537028/firebase-ios-swift-retrieve-child-data-corresponding-to-a-chat-conversation-id?rq=1
I'd like to say thanks in advance and hope you guys can help!