Parse Swift:与“朋友请求”的用户关系 [英] Parse Swift: User relations with a "friends request"

查看:144
本文介绍了Parse Swift:与“朋友请求”的用户关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对编程和解析有点新意,但我真的很感兴趣。
我已经知道如何创建PFUser以及如何设置用户之间的关系,这要归功于parse.com上提供的教程。问题是他们只有一个用户跟随另一个用户的示例。我更喜欢发送像朋友请求,例如在Instagram中,如果个人资料不对任何人开放。
我该如何编码呢?我需要考虑什么?
非常欢迎示例代码:P

I am kind of new to programming and parse, but I am really interested in it. I already know how to create a PFUser and how to set relations between Users, thanks to the tutorial provided on parse.com. The thing is they only have examples for one User following another User. I would prefer sending like a "Friends Request", for example like in instagram if a profile is not open to anybody. How can I code that? What do I need to think of? Example Code is very welcome :P

推荐答案

我肯定会创建一个像@MatthewLuiHK建议的FriendRequest表。但是,我不知道这是否是追踪谁跟踪谁的最佳方式,这只会允许跟踪打开的朋友请求。在我的应用程序中,我使用云代码函数在每个用户的对象中设置 friends 数组,因为您无法在没有主密钥的情况下修改其他用户。下面是我使用的函数:

I would definitely create a FriendRequest table as @MatthewLuiHK suggested. However, I don't know if this is the best way to track who is following who, this would just allow for tracking open friend requests. In my apps I use a cloud code function to set a friends array in each user's object, as you cannot modify other users without the master key. Below is the function I use:

Parse.Cloud.define("handleFriendRequest", function(request, response) {

    Parse.Cloud.useMasterKey();
    var query = new Parse.Query(Parse.User);
    //console.log(request.user);
    query.get(request.params.fromUserId).then(function(fromUser) {

        console.log("Hello World!");
        fromUser.addUnique("friends", request.user);
        return fromUser.save();

    }).then(function(savedFromUser) {

        response.success("Successfully made a new friend! :)");

    }, function(error) {

        response.error("Error occurred: " + error.message);

    });


});

在调用此函数之前,需要添加 fromUser 指向当前用户 friends 列中数组的指针,然后将fromUser objectId 发送到此函数下字典中的fromUserId键。

Before calling this function, you need to add the fromUser pointer to the array in the current users friends column, then send in the fromUser objectId into this function under the "fromUserId" key in the dictionary.

这篇关于Parse Swift:与“朋友请求”的用户关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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