0

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 .

XcodeNOOB
  • 2,135
  • 4
  • 23
  • 29
  • You've also left out half of the code. Please could you fill it in. And try to keep it nicely formatted :D – Fogmeister Mar 13 '14 at 00:41
  • hey there, i didn't left out half of the code, that's the whole code I have for query . what i don't know is how to save the user ID and use it for later plus i'm still confused how to create a chat room between them two users . thank you for replying tho . – XcodeNOOB Mar 13 '14 at 00:48

1 Answers1

1

for the DB model, you could have:

User table

The parse User table

Room table

A simple table with maybe the room name field and the pointer field to the user creator

Member table

Associative table between User and Room, since an User can partecipate to many Rooms and a single Room can contains many Users

Messages table

A simple table with the message field, and the pointer field to the Member, that means the user member of a specific Room.


In addition (as you probably already know), each table in Parse has default fields that are "objectId","createdAt","updatedAt" and "ACL". Those fields (except ACL) are automatically filled.

Hope this helps

Luca Iaco
  • 3,387
  • 1
  • 19
  • 20
  • thank you for replying , i wish there were a tutorial to point me out for this . i'm going to try it myself and see what's happen. – XcodeNOOB Mar 13 '14 at 13:11