How to invite users to join a multi player Gaming Session using Parse (swift) - ios

I'm trying to develop a trivia app, much like Quiz Up but with multi players.
Here's what I thought of doing:-
Creating a class called 'Game Session' on Parse, that has information of who created it (PFUser.current), the name of the gaming session(name), and the names of users invited(invited_users). Think of this Gaming Session as a closed group where the users interact with each other only.
So there's a createSessionViewController, and a joinSessionViewController.
If User A creates a gaming session (in createSessionViewController) and sends invites out to User B and User C, they get to accept or decline these invites in joinSessionViewController.
Now from what I have researched is that I would have to query through all the objects in the class Game Session (in viewdidload of the joinSessionViewController) and use query.wherekey for eg, User B's object id is in the column "invited_users". If so, I return that Gaming Session's object. Is that right?
If that is the case, is that an efficient way of doing it? Because it seems like if the app gets popular and there are lots of objects in the class, then it could take up a lot of time to get the one object with User B's id.
I hope I made myself clear and you guys understand my question.
PS: I'm sort of new to parse and swift, so if you could give me detailed answers it would be much appreciated.

Your logic is correct but I would also strongly suggest you take a look at Parse-LiveQuery. This tool allows you to subscribe to a PFQuery you are interested in. Once subscribed, the server will notify clients whenever a PFObject that matches the PFQuery is created or updated, in real-time.
https://github.com/ParsePlatform/parse-server/wiki/Parse-LiveQuery
https://github.com/ParsePlatform/ParseLiveQuery-iOS-OSX

Your assumption is correct and that is indeed one way you could go about doing that although it has drawbacks as you mentioned. If you felt like putting more effort into it, you can write JavaScript parse cloud code that executes after an item is saved (for example after a game session is created) and send out silent push notifications with the new objects id to the users who were invited. You could then use that push notification data to know the exact ids instead of having to query for them. This is much more advanced though. For whatever your app is, the simple route of having a model query the data on load should be fine. If you find yourself in a situation where performance is hindered due to this, well then congratulations.

Related

How to use database subscriptions correctly when using CloudKit sharing

I'm working through how to handle CloudKit sharing and database subscriptions and I need help understanding how Apple envisions us using subscriptions and CloudKit sharing together given the properties and delegate methods we have available.
This thread is very similar but doesn't bring sharing into the equation and is a bit different functionality-wise than what I have set up.
Setting up the subs is the easy part. If there's no subscription, set one up. And if the owner stops sharing there's a delegate method that gets called so you can just delete all subs except your own. My problem comes in when a participant leaves a share. The subscription associated with that person should be deleted, but they now don't have access to the shared database to do it. And I see no way to associate a subscription with a participant ID. The only way I can figure out how to do this is basically what is mentioned in that other thread. Create a new Subscription recordType that indexes participant id to subscriptions id.
Conceptually I had this backwards and had assumed each user would be responsible for their own subs. Using a new recordType flips that so the share owner is responsible for all the subs.
Is this really the way to do it? Anyone who uses sharing runs into this so I had thought there should be some way to handle it without creating another recordType?
I misunderstood something very basic and important. For some reason I had it in my head that subs for shared databases actually lived on the owner database, and when sharing stopped they would lose access to the database and wouldn't be able to delete their own sub. That's not the case (obviously?), as you can only see your own subs, and the owner can't see any subs of participants.
When sharing stops you lose access to the CKShare record, but you still have access to your sub on the shared database. So it's trivial to delete it when needed - if the owner was responsible it would be more involved (as I was thinking above).

How to limit access to a database (or a document within a database) based on invitation

From what i've been able to discern so far, Firebase/Firestore seem like the perfect platform to use for an app I am writing. However I can't quite connect all the dots when trying to design my backend. I am hoping that someone will be able to give answer a couple of basic questions about the use of FB/FS.
With my app, a user will be able to share a small piece of data with a select group of friends. ie if the data is to be a To-Do list, the user would create the list on his device (iphone only) and then invite a small group of friends (probably less than 10) to share that data. The friends would have read-only access by default, however, the user can assign any number of them to be "admins" which would allow them read/write permission. When any changes occur to the data, all "friends" who have access to the data will be notified (by some means - push notifications etc). They can manually sync or setup the app to automatically sync. It seems like FB/FS can be used for this right out of the box. However there are a couple of concepts that I can't get my head around.
The database I setup is accessible by ALL users of my app by default. It's not clear (at least to me) how I would set it up so when a user creates (in this case) a to-do list and invites 5 friends, only those 5 friends can access or even know about that data. This is main stumbling block in my development path.
Regarding invitations. I read in the FB/FS documentation that invitations and notifications are among the many features available. I'm not clear on how this will work if a) the recipient doesn't have my app installed and b) how the inviter would get feedback when the invitation was accepted or declined.
Any guidance that anyone is willing to share to help me get started will be a huge help and will be greatly appreciated. Thanks.
You can create new privates collections inside the main collection, and set different rules for access.
Check at: Firebase Firestore get private fields

Firebase data structure for chat app

I'm looking to basically remake Kik within my app. For most guides I've seen on a firebase chat application, there is one major Messages node, and then underneath that there's a fan-out with messages for each user that reference messages in the main list.
With the way my Firebase is laid out at the moment, it would be easier to implement something like this:
users
chatPartners
02834092890428
chatMessages
2093840923840923
timestamp/userUID/etc.
and just have the actual chat inside of my user's node. This seems to also cut down majorly on having to sift through every single message in a messages node?
So when the users send messages to eachother, I'd update the "chat messages" node under the sender and the user.
Is there any reason NOT to do it like this? I see everyone doing it the first way I described, yet I don't see a reason why storing each chat under user--->chat partner --> the chat log would be an issue.
The only issue you may run in to is how the data is called. Note that when you call the 'Chat Log', because it is a child of 'Users' and 'chatPartners', you will be calling the data of everything in that branch, essentially loading every piece of data in the database under 'Users', which is time and performance sensitive.

Parse: Basic App to App Communication

I am trying to figure out what the basic steps are for getting data passed between users. For example, say I, a user of the app, want to send another user of my app a message or a geopoint or some other form of data. I know the first step would be posting the data to Parse, which I don't have a problem with. But then, how would the other user know there is data to retrieve and also how would they go about retrieving it. Are push notifications the proper and only way of letting the recipient's app know its being sent something? When the recipient app knows there is data posted intended for it to retrieve, how does it go about locating it with a PFQuery? Does the posting app need to supply the receiving app with a UID of some form that the receiving app can then use in its query to locate the data? This is kind of the last puzzle piece for my app and unfortunately it's the only thing Parse didn't make clear to me. It is more than likely user error on my part not finding the correct documentation but, app to app communication is key in most apps and so I need to figure out the defacto way that Parse accomplishes this. Thanks in advance for any help!
You can have a relational table lets say "Messages" table in Parse,
with properties, sender (Pointer to a User), recipient (Pointer to a User) and message (String). and maybe a 'read' Boolean.
You could then query the messages table, With something like:
PSEUDO:
get all messages where recipient is equal to logged in user.
and display these messages on the UI.
Its pretty straightforward, I have done simple messaging service with Parse before
Thanks guys! In the end, I think it is best for a device to not have to be querying for changes but rather to be notified when it has new data to retrieve. Thus, for my uses, I think a combination of your answers, especially with the "onSave" hook function mentioned by Bruno, is the best solution.

What's the most efficient way to create an alert queue for a model with hundreds of millions of entries?

I am currently working on an application in Rails (though language/framework shouldn't matter for this question since it is more of a theoretical one). I'm working on wrapping my head around this problem:
Say I am tracking millions of blogs online and am plugged into their RSS feeds. My app pings these feeds every few few minutes to see if there has been any new activity across any of these millions of blogs. If there is any new activity, I want to alert users of my application who have signed up to receive alerts for specific blogs that there has been an alert.
Does it make sense to have a user_blog_alerts table (where a user can specify custom keywords to be alerted about) and continuously check this table against every new entry that comes in from my feed? And when there is a match, to add them to a queue (using Redis)?
What is the best, most efficient way to build and model this alerting system? Am I even thinking about this in the right way? Are there any good examples or tutorials on this when working with such large amounts of data?
I'm not sure what the right way to do this is, but the thought of continuously scanning a table over and over sounds exhausting (ie. unscalable).
Off the top of my head, what if you created a LIST for every blog in Redis. The values would be the user IDs of those who wanted an alert. The key name would contain the blog id (ex: "user_blog_alerts:12345").
Then when you got a new post for blog 12345 it's a simple lookup to see if that key exists. If it does, then fire off alerts for each user in the list.

Resources