解析 Swift:具有“好友请求"的用户关系 [英] Parse Swift: User relations with a "friends request"

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

问题描述

我对编程和解析有点陌生,但我真的很感兴趣.由于 parse.com 上提供的教程,我已经知道如何创建 PFUser 以及如何设置用户之间的关系.问题是他们只有一个用户跟随另一个用户的例子.我更喜欢像朋友请求"一样发送,例如,如果个人资料不对任何人开放,就像在 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列中的数组中,然后传入fromUserobjectId 到字典中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.

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

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