diff --git a/GetHip/FriendDataSource.swift b/GetHip/FriendDataSource.swift index 57ec2d5..ab3b968 100644 --- a/GetHip/FriendDataSource.swift +++ b/GetHip/FriendDataSource.swift @@ -68,7 +68,9 @@ class FriendDataSource{ var newFriend: FriendData = FriendData(display: userName, status: requestStatus) //print(userName) self.dataSource.append(newFriend) + } + NSNotificationCenter.defaultCenter().postNotificationName("refreshTableView", object: nil) } }) @@ -77,7 +79,7 @@ class FriendDataSource{ } - NSNotificationCenter.defaultCenter().postNotificationName("refreshTableView", object: nil) + } diff --git a/GetHip/FriendRequestViewController.swift b/GetHip/FriendRequestViewController.swift index e706c75..12e7b1e 100644 --- a/GetHip/FriendRequestViewController.swift +++ b/GetHip/FriendRequestViewController.swift @@ -20,7 +20,6 @@ class FriendRequestViewController: UIViewController{ @IBAction func sendButtonClicked(sender: AnyObject){ var query = PFQuery(className: "_User") query.whereKey("username", equalTo: foundName.text!) - println(foundName.text!) dispatch_async(dispatch_get_main_queue(),{ query.getFirstObjectInBackgroundWithBlock({ (object:PFObject?, error: NSError?) -> Void in diff --git a/GetHip/Main.storyboard b/GetHip/Main.storyboard index a432e3d..816158e 100644 --- a/GetHip/Main.storyboard +++ b/GetHip/Main.storyboard @@ -108,12 +108,18 @@ + + + diff --git a/GetHip/PendingRequestViewController.swift b/GetHip/PendingRequestViewController.swift index 8e0d1b4..25ecd8a 100644 --- a/GetHip/PendingRequestViewController.swift +++ b/GetHip/PendingRequestViewController.swift @@ -13,6 +13,66 @@ class PendingRequestViewController: UITableViewController { var requests = [] + + @IBAction func didAcceptFriend(sender: AnyObject?){ + var path:NSIndexPath = self.table.indexPathForCell(sender?.superview!!.superview as! PendingFriendCell)! + var cell: PendingFriendCell! = self.table.cellForRowAtIndexPath(path) as! PendingFriendCell + + var query: PFQuery! = PFQuery(className: "FriendRequest") + query.whereKey("username", equalTo: PFUser.currentUser()!.username!) + query.whereKey("RequestStatus", equalTo: "pending") + query.whereKey("inRealtionTo", equalTo: cell.friendName.text!) + query.includeKey("OtherUser") + + dispatch_async(dispatch_get_main_queue(), { + query.getFirstObjectInBackgroundWithBlock({ + (object:PFObject?, error: NSError?) -> Void in + + if(error == nil){ + object!.setObject("accepted", forKey: "RequestStatus") + object!.save() + PFUser.currentUser()?.relationForKey("FriendRequest").addObject(object!) + + dispatch_async(dispatch_get_main_queue(), {() -> Void in + PFUser.currentUser()!.saveInBackgroundWithBlock({ + (succeeded, error) -> Void in + + if(succeeded){ + + } + + }) + + }) + + //change requestStatus of other user who initiated request + var otherQuery: PFQuery! = PFQuery(className: "FriendRequest") + println(object!.objectForKey("OtherUser")!.objectForKey("username")!) + otherQuery.whereKey("username", equalTo: object!.objectForKey("OtherUser")!.objectForKey("username")!) + otherQuery.whereKey("inRealtionTo", equalTo: PFUser.currentUser()?.username as String!) + otherQuery.whereKey("RequestStatus", equalTo: "Awaiting Response") + + dispatch_async(dispatch_get_main_queue(), { + otherQuery.getFirstObjectInBackgroundWithBlock({ + (object, error) -> Void in + + if(error == nil){ + object!.setObject("accepted", forKey: "RequestStatus") + object!.save() + } + }) + }) + + } + }) + }) + + + } + + @IBAction func didRejectFriend(sender: AnyObject?){ + + } override func viewDidLoad() { super.viewDidLoad() self.title = "Friend Requests"