我正在尝试为我的iOS社交应用编写一个Parse查询,该查询将显示关注活跃用户的所有用户。以下是我到目前为止的情况:
PFQuery *followingUser = [PFQuery queryWithClassName:@"Activity"];
[followingUser whereKey:@"Activity" equalTo:@"follow"];
[followingUser whereKey:@"fromUser" equalTo:self.user];
[followingUser includeKey:@"User"];
[followingUser setCachePolicy:kPFCachePolicyCacheThenNetwork];
目前,这正确地为我提供了跟随任何其他用户的活动用户的所有记录,但是这并没有为我提供相应记录的PFUser详细信息(用户配置文件图片,显示名称等)。关于如何在一个查询中轻松绘制PFUser详细信息的任何想法?
提前致谢
答案 0 :(得分:4)
以下是一些查询示例代码,用于获取所有被关注的用户,所有来自用户的帖子以及当前用户的所有帖子。我希望这有帮助!
// List of all users being followed by current user
PFQuery *followingActivitiesQuery = [PFQuery queryWithClassName:kFTActivityClassKey];
[followingActivitiesQuery whereKey:kFTActivityTypeKey equalTo:kFTActivityTypeFollow];
[followingActivitiesQuery whereKey:kFTActivityFromUserKey equalTo:[PFUser currentUser]];
followingActivitiesQuery.cachePolicy = kPFCachePolicyNetworkOnly;
followingActivitiesQuery.limit = 100;
// Posts from users being followed
PFQuery *postsFromFollowedUsersQuery = [PFQuery queryWithClassName:self.parseClassName];
[postsFromFollowedUsersQuery whereKey:kFTPostUserKey matchesKey:kFTActivityToUserKey inQuery:followingActivitiesQuery];
[postsFromFollowedUsersQuery whereKey:kFTPostTypeKey containedIn:@[kFTPostTypeImage,kFTPostTypeVideo,kFTPostTypeGallery]];
// Posts from current user
PFQuery *postsFromCurrentUserQuery = [PFQuery queryWithClassName:self.parseClassName];
[postsFromCurrentUserQuery whereKey:kFTPostUserKey equalTo:[PFUser currentUser]];
[postsFromCurrentUserQuery whereKey:kFTPostTypeKey containedIn:@[kFTPostTypeImage,kFTPostTypeVideo,kFTPostTypeGallery]];
PFQuery *query = [PFQuery orQueryWithSubqueries:[NSArray arrayWithObjects: postsFromFollowedUsersQuery, postsFromCurrentUserQuery, nil]];
[query includeKey:kFTPostUserKey];
[query orderByDescending:@"createdAt"];