1
votes

I'm using Parse for backend and I'm designing the Activity class. Activity class has 4 columns. fromUser(that would be PFUser currentUser), activityType(String: lets say it's "like"), argument("Post" pointer associated witht that like) and toUser(that would be the owner of the post.) What I'm troubling is that when I try to save the fromUser column i have the error

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'User cannot be saved unless they have been authenticated via logIn or signUp'

How can I save a activity object properly? I can log my own activities(since both the fromUser and toUser is already me). But Parse doesnt lets me to log activities that relates to other Users(in the case that i'm trying to like someone elses post.)

sample code here:

        //user objectId: the object id of the User who posted the Post.
        PFUser *postOwner = [PFUser objectWithoutDataWithObjectId:self.userObjectId];
        [postOwner setObjectId:self.userObjectId];        
        activity[@"fromUser"]=[PFUser currentUser];   
        activity[@"toUser"]= postOwner;
        activity[@"post"]=postPointer;

I'm having the error in the "toUser" line.

1
I'm not quite sure I understand the question, but you cannot save a user that is not the current user.Jacob
Yup, sounds right. But i need to keep the post owner to send him a notification. How can i satisfy that, other than this design. I thought about fetching the related users from the post pointer but i don't believe it is the best practice.Ugur
You don't need to modify or save that user to send him a push.Jacob
I'm fetching the activity by looking at the "toUser" column therefore, I need to log the related user.Ugur
I'm a little confused now, could you show more code?Jacob

1 Answers

-1
votes

This is a perfect example of when to use a Cloud Function.

You should start by reading the docs here:

https://parse.com/docs/cloud_code_guide#functions

To bypass the normal security in your Cloud Function you'll need the following line:

Parse.Cloud.useMasterKey();

NOTE: use with caution, you should do your own security checks where appropriate to ensure you're not opening a security hole in your app.