I saw a few tutorials over the net how to make private messaging with parse or an chat between users, but they all kind of complicated and it's hard to fit it in my project plus most of them are chat rooms and not private messaging.
What I'm trying to do is to find the simplest way to make chat between two users .
my code is kind of simple , I have a text field and one button, let's say a userOne
send those numbers: 1234
.
Then userTwo
put the same numbers in the text field and push the button to send it to parse.com
and then I have a query to look for it and to see if there is a match between users.
Once there is match , I want to ask both of them users if they want to chat , if yes so they can chat with each other.
Now , I would like to know from you all pros ( :-D ) what are my options,
I thought about notification system between users ( is it even possible ? ) or maybe (since chat rooms are complicated to create) create a UILabel
with NSTimer
code that going to update every 2 seconds and another text field which users can send text to each other.
Another question I have is, once I found the second user ID how can I save it and use it for later?
Do i need to save it to NSString?
anyway that's my code for query (when you press the button to send to number )
PFObject *addValues= [PFObject objectWithClassName:@"someNumber"];
[addValues setObject:someNumbers forKey:@"numbers"];
[addValues setObject:whoIsTheUser forKey:@"theUser"];
[addValues saveInBackground];
PFQuery* numQuery = [PFQuery queryWithClassName:@"someNumber"];
[numQuery whereKey:@"numbers" equalTo:someNumbers];
[numQuery whereKey:@"theUser" notEqualTo:[PFUser currentUser]];
[numQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if(!error) {
//alert view for thanking the user for sending a message
UIAlertView *messageForSending = [[UIAlertView alloc]initWithTitle:@"thank you"
message:@"the details has been send"
delegate:nil
cancelButtonTitle:@"okay"
otherButtonTitles:nil];
[messageForSending show];
for(PFObject *numObject in objects) {
// the numbers if found are right here
if (objects.count > 1 ) {
NSLog(@"yay we found %lu objects", (unsigned long)objects.count);
// Here I can see what is the ID of the second user I want to create chat with
NSLog(@" the numobject is %@ " , numObject);
} else {
NSLog(@"there is no match ");
// showing later UIAlert that there is no match
}
any help would be appreciated ! thank you all .