Continued from Part 1, our next requirement is:
List requests from others waiting for my approve/reject action
// remember our common code, FriendRequest, currentUser
// and RequestStatus are already defined
var pendingRequestQuery = new Parse.Query(FriendRequest);
pendingRequestQuery.equalTo('toUser', currentUser);
pendingRequestQuery.equalTo('status', RequestStatus.requested);
requests.find().then(function (requests) {
// render them somewhere with Approve/Reject buttons
});
I'll leave it as an exercise for the reader to render the list.
List my friends
var myFriendsQuery1 = new Parse.Query(FriendRequest);
myFriendsQuery1.equalTo('fromUser', currentUser);
myFriendsQuery1.equalTo('status', RequestStatus.approved);
var myFriendsQuery2 = new Parse.Query(FriendRequest);
myFriendsQuery2.equalTo('toUser', currentUser);
myFriendsQuery2.equalTo('status', RequestStatus.approved);
var myFriendsQuery = Parse.Query.or(myFriendsQuery1, myFriendsQuery2);
myFriendsQuery.find().then(function (approvedFriendRequests) {
// render them
});
List my requests that are pending
var pendingRequestQuery = new Parse.Query(FriendRequest);
pendingRequestQuery.equalTo('fromUser', currentUser);
pendingRequestQuery.equalTo('status', RequestStatus.requested);
pendingRequestQuery.find().then(function (pendingRequests) {
// render them
});
List my rejections
var rejectedMeQuery = new Parse.Query(FriendRequest);
rejectedMeQuery.equalTo('fromUser', currentUser);
rejectedMeQuery.equalTo('status', RequestStatus.rejected);
rejectedMeQuery.find().then(function (rejectedMeRequests) {
// render them
});
List requests I have rejected
var rejectedByMeQuery = new Parse.Query(FriendRequest);
rejectedByMeQuery.equalTo('toUser', currentUser);
rejectedByMeQuery.equalTo('status', RequestStatus.rejected);
rejectedByMeQuery.find().then(function (rejectedByMeRequests) {
// render them
});
In the next part I'll talk about Actions.
No comments:
Post a Comment