【发布时间】:2023-03-21 08:34:01
【问题描述】:
我想要一个表格来显示待处理的好友请求列表。我跟踪好友请求状态的方法是使用 Parse 作为后端并创建一个 FriendRequest 类。在该类中,有一个状态列已接受、待处理、拒绝。这是当前的查询逻辑。
PFQuery *userQuary = [PFUser query];
PFQuery *pendingFriends = [PFQuery queryWithClassName:@"FriendRequest"];
PFQuery *aceeptedFriends = [PFQuery queryWithClassName:@"FriendRequest"];
[aceeptedFriends whereKey:@"toUser" equalTo:self.currentUser.objectId];
[aceeptedFriends whereKey:@"status" equalTo:@"Accepted"];
[pendingFriends whereKey:@"status" doesNotMatchKey:@"status" inQuery:aceeptedFriends];
[pendingFriends whereKey:@"toUser" equalTo:self.currentUser.objectId];
[pendingFriends whereKey:@"status" equalTo:@"Pending"];
[userQuary whereKey:@"objectId" matchesKey:@"fromUser" inQuery:pendingFriends];
[userQuary findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (error){
NSLog(@"ERROR: %@ %@", error, [error userInfo]);
}else{
self.friendList = objects;
NSLog(@"%@", self.friendList);
[self.tableView reloadData];
}
}];
我遇到的问题是已经被接受的朋友不断出现在待定朋友的查询中。
这里是作为接受好友请求的方法。 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
PFRelation *myRelation = [self.currentUser relationForKey:@"friendRelation"];
//PFRelation *friendsRelation = [self.selectedUser relationForKey:@"friendRelation"];
PFObject *friendRequest = [PFObject objectWithClassName:@"FriendRequest" ];
[friendRequest setObject:self.currentUser.objectId forKey:@"fromUser"];
[friendRequest setObject:self.selectedUser.objectId forKey:@"toUser"];
[friendRequest setObject:@"Accepted" forKey:@"status"];
switch (buttonIndex) {
case 0:
[friendRequest saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error){
NSLog(@"ERROR: %@, %@", error, [error userInfo]);
}
}];
[myRelation addObject:self.selectedUser];
[self.currentUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error){
NSLog(@"ERROR: %@ %@", error, [error userInfo]);
}
}];
case 2:
[alertView dismissWithClickedButtonIndex:1 animated:0];
break;
}
/*
[self.currentUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error){
NSLog(@"ERROR: %@ %@", error, [error userInfo]);
}
}];
*/
[self.tableView reloadData];
}
【问题讨论】:
标签: ios parse-platform