1
votes

I'm working with Parse.com ... My app relies heavily on relations between users and to use this thing PFRelation that creates a relationship between the User and the User corrent selected ...

Whenever the Current User chooses User " A" creates the relationship with PFRelation and User "A" receives a push notification where it is informed that the current user has started to follow him.

Now I have created through a label , even the badge number that should appear not to CurrentUser but the USER "A" that receives the notification . The badge I'm talking about is NOT the classic Icon badge but it is a badge that appears on NavigationBar .

To do all this I should try to save an entry in the special class _USER CurrentUser but not to the USER "A" .. Could you tell me how could I do? I already have an array fetches the names of users and displays them in tablebiew .

For example, to create the relationship with the user selected on the Tableview I implemented a PFUser connected with the array

- (void) tableView : ( UITableView * ) tableView didSelectRowAtIndexPath : ( NSIndexPath * ) indexPath {
[ self.TableView deselectRowAtIndexPath : indexPath animated : NO] ;
    
if (! isFiltered ) {

    UITableViewCell * cell = [ self.TableView cellForRowAtIndexPath : indexPath ] ;
    cell.accessoryType = UITableViewCellAccessoryCheckmark ;

    PFUser * user = [ self.Utenti objectAtIndex : indexPath.row ] ;
    PFRelation * Report = [ [ PFUser currentUser ] relationforKey : @ "Relationship "] ;
    PFInstallation currentInstallation * = [ PFInstallation currentInstallation ] ;
    NSString * RegistraNomeUtente = [ NSString stringWithFormat : @ "% @ " , [user objectForKey : FF_USER_NOMECOGNOME ]] ;
 
.....
1
Can you use join table that has from_user & to_user entities. So that you can query specific user how follow current user or count total users who is following the current one. - babygau
Hello and thanks for the reply ... I've heard of this method but I have not figured out how I should do sincerely ... There 'some tutorials or specific discussion where he explains exactly what to do?? I'm new to parse.com ... What is a Join table .. Excuse my bad english, I'm Italian - kAiN
Pls see my answer, I'm not good at English as well, so don't worry :) - babygau

1 Answers

3
votes

Basically you create a new class on parse named such as Activity. From this class, you will have from_user attribute is a pointer to User class and to_user is also a pointer to User class. Maybe you can have one more attribute name type used to indicate what type of relationship betweens users. Each user can "follow", "post comment", "like" each other.

Now get back to your code. I assume that you will have a particular PFUser object when you click on a specific row of your tableView. In -tableView:didSelectRowAtIndexPath: you save new Activity object by using the following pseudo code:

PFObject *activityObj = [PFObject objectWithClassName:@"Activity"];
[activityObj setObject:[PFUser currentUser] forKey:@"from_user"];
[activityObj setObject:OtherUserObj forKey:@"to_user"];
[activityObj setObject:@"follow" forKey:@"type"];
[activityObj saveInBackGround];

Now you have a relationship between current user and other user. You can get total number of following user to display in your badge item by:

PFQuery *activityQuery = [PFQuery queryWithClassName:@"Activity"];
[activityQuery whereKey:@"from_user" equalTo:[PFUser currentUser]];
[activityQuery whereKey:@"type" equalTo:@"follow"]];
[activityQuery countObjectsInBackground];

Hope it helps you :)