解析云权限查询以检索好友列表而不是(例如Instagram) [英] Parse Cloud Right Query to retrieve Friendslist and not (like Instagram)

查看:126
本文介绍了解析云权限查询以检索好友列表而不是(例如Instagram)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Parse Dashboad的默认类"Users".我也有"Friends"类,在其中存储用户之间的友谊,如下所示: 有两列,"toUser"和"fromUser",显示了两个用户中谁发送了好友请求.这两列是指向用户类的Pointers(Pointer< _User>).

I have the class "Users" the default of Parse Dashboad. I have also the class "Friends", where I store the friendships between users like this: There are two columns, "toUser" and "fromUser", which are showing who of the two users sent the friend request. These two columns are Pointers(Pointer<_User>) to the Users Class.

我的概念是检索两个列表: 1.登录用户的好友列表 2.用户的用户列表(与登录用户不是朋友)

My concept is to retrieve two lists: 1. Friendlist for the logged in user 2. Userlist of users (who are not friends with the logged in user)

对此合适的查询是什么?

What would be the appropriate queries for that?

从逻辑上讲,第一个不应扫描所有类Users,因为这可能会减慢使用Ionic 3和Angular 4的应用的性能

The first one logically should not scan all the class Users because it may slow down the perfomance of the app which is using Ionic 3 and Angular 4

谢谢

推荐答案

如果我正确地理解了您的问题,那么您希望找到朋友请求您sent或您请求received的朋友.因为我看不到您在用户和他的朋友之间建立了联系. 如果要使用云代码执行此操作,请使用以下代码:

if I understood your question right you want to find the friend requests you sent, or the ones you received. because I don't see where you made a relation between the user and his friends. this is the code if you want to do this using cloud code:

首先,我验证了要保存的friendRequest的参数:

First I validated the parameters of the friendRequest being saved :

Parse.Cloud.beforeSave("Friends", function(request, response){
  var friendRequest = request.object;
  if (!friendRequest.has("toUser") || !friendRequest.has("fromUser")) {
    response.error("Invalid parameters");
    return;
  }
  response.success();
});

然后我创建了两个云函数,一个用于检索sentRequests:

then I created two cloud functions, one for retrieving the sentRequests:

Parse.Cloud.define("getSentRequests", function(request, response){
  var query = new Parse.Query("Friends");
  query.equalTo("fromUser", request.user);
  if (!request.master) {
    query.find({ sessionToken: request.user.getSessionToken() }).then(function(friends){
      response.success(friends);
    });
  }else{
    query.find({useMasterKey:true}).then(function(friends){
      response.success(friends);
    });
  }
});

,您可以从已登录的用户调用此命令,也可以根据需要使用masterKey进行调用,而另一个查询用于recievedRequests:

and you can call this either from a logged in user or using the masterKey if you want, and the other query is for the recievedRequests:

Parse.Cloud.define("getRecievedRequests", function(request, response){
  var query = new Parse.Query("Friends");
  query.equalTo("toUser", request.user);
  if (!request.master) {
    query.find({ sessionToken: request.user.getSessionToken() }).then(function(users){
      response.success(users);
    });
  }else{
    query.find({useMasterKey:true}).then(function(users){
      response.success(users);
    });
  }
});

这篇关于解析云权限查询以检索好友列表而不是(例如Instagram)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆