我想避免与Parse.com和Cloud Code或iOS Code重复。这是我的数据库课程:
我想当“ from ” userId 已经发送到“ to ” userId 时,不会发送第二个friendRequest。
这是我的 iOS 代码:
PFUser *selectedUser = [self.allUsers objectAtIndex:indexPath.row];
//request them
PFObject *friendRequest = [PFObject objectWithClassName:@"FriendRequest"];
friendRequest[@"from"] = self.currentUser;
friendRequest[@"fromUsername"] = [[PFUser currentUser] objectForKey:@"username"];
//selected user is the user at the cell that was selected
friendRequest[@"to"] = selectedUser;
// set the initial status to pending
friendRequest[@"status"] = @"pending";
[friendRequest saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (succeeded) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sent !" message:@"Friend request sent" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
} else {
// error occurred
}
}];