Parse: How to save single column of PFObject - swift

I have an issue where if a user posts something on my app, and a user with bad internet connection tries to view it, the post is deleted. I think this is because in my code, the client saves the array of posts every 5 seconds or so. Since the client with bad internet connection has an old version of the posts, when they try to view the post, the old version is saved and therefore the new post is deleted. In order to fix this, I need to save columns in an object individually and not affect the new posts column. How do I do this?

You can compare the value in updatedAt, if the local value updatedAt is lower than the one on server, you just wont update it... I think you can do that in cloud code with beforeSave trigger

Related

Facebook API Private Message image expired - How to get new image ? URL signature expired

I'm helping maintain an app that integrates with Facebook, and has lots of archived links to old private message images. Sometimes these images expire, and we go to facebook and request a new image. This works 90% of the time.
About 10% of the time we're getting back a response that we can't tell what the new image is.
What's the proper way to request a new url for an expired Facebook Private Message image, preferably using v2.5 or newer of the Graph API?
Currently we're doing a GET request to Facebook's Graph API using the message id of the private message like so:
https://graph.facebook.com/v2.3/m_mid.XXXXXXXXX:YYYYYYYYY
and that gives us a response that has a bunch of attachments in it. For 90% of use cases, there's a new attachment that has an url or name field with a new filename that contains the old filename, e.g. old file name being XXX, we'd see a new filename like ....XXXX.... in the url field.
attachments [url='*%s*']/image_data/url
attachments [name='*%s*']/image_data/url
or sometimes
picture
but that doesnt match what we get now, which is a bunch of attachments with no way to map to the new image.
We haven't been able to find a graph API way of doing this, but have the following solutions we're considering:
When there's only one attachment in the response, we just use that one url. This works some of the time, but fails when there's more than one image of course
Save more metadata about the image, at worst case an MD5 of the file. Then compare that to MD5's of the other files until we get the one we want. Instead of an MD5, we could consider using info about the file from a HEAD request. All of this is untested.
Update our old message metadata with new metadata whenever this happens, thus avoiding the problem entirely as new image requests would come from the new metadata.

Meteor: The Correct way to access user information

I'm new to meteor and I am in the process of building my application, but I am running into some "best practice" questions.
I have three databases. One for the users, one for questions, and one for answers. Think of my site as a quora of sorts.
I am iterating through the questions, and I am having a hard time accessing the user information. At the moment when a question gets recorded, I record the question, and I only record the user's id. Coming from a rails background, this is usually all I need to access all the other information when I need it. I don't record the name and all the other info.
The question I have is what is the right way to access the user information? I am doing an each loop and it seems that Meteor.user is only for logged in users (only for my information basically). I can't seem to do something like Meteor.users.find({_id: this.user_id}) on the questions helper so that I could get each users info. It retrieves nothing like this.
In the examples I have seen, they usually record the information on the questions database. So they would record first,last name, and anything else that would be necessary. But this seems like I am recording information twice.
What is the right way to access this info? Should I record it when a question is posted or should I call it from the users database everytime?
I have tried accessing the info through a server method, but can't seem to get it to work. Been at this for a while so I though I should ask instead.
Thanks in advance!!
My solution would be just save the user_id field in db as you're doing right now,
If you save firstname or lastname with the questions they may change in future (considering the fact that in most sites we have option to change names)
I can't seem to do something like Meteor.users.find({_id:
this.user_id})
this is because user data is not availbale in the client, that is the reason why you can't see the data
solution is while publishing the question to client you should publish the information of the user too
Example
Meteor.publish('question,function(question_id){
var question = Question.findOne(question_id);
//get info of the question user
var user = Meteor.users.find({_id: question.user_id });
//you cannot publish findone result, so do another query
var ques_rec= Question.find({_id: question_id});
return [ques_rec, user];
});
Now, in the client side when you do I can't seem to do something like Meteor.users.find({_id: this.user_id}) you'll get the user data.
I think I found a solution. I haven't turned the autopublish off, so this seems to be working for now.
Template.questionItem.helpers({
user: function(){
user = Meteor.users.find({_id: this.user_id}).fetch();
return user[0]
}
I think basically you can search users, but for some reason if I do
Meteor.users.find({_id: this.user_id})
it returns an object and I can't seem to find the actual data.
But if I add the .fetch() at the end it will return an array for the user. So if declare it as a variable, I can access all the info by saying user[0].
I'm not sure if if this is the best way to do it in meteor, but it does seem to work.
So when I call the object in the handlebars I go something like:
{{user.profile.name}}
I think once I turn autopublish off I will have to do the same thing but from the server side.

PayPal , return page post values, how to access and use

I am wrestling with the PayPal service . I almost have it done . Last step, when the customer payed and has the last page, which stays open for 10 seconds and then redirects them to the page of your choosing.
What parameters, posts, etc are sent with that page opening? And how do I get access to them, so I can link the returning user with their created account (from ipn and my personalized database entry on the initial buyitnow)
I tried echo($_post). But it just shows .... Array() But no key value pairs.
I'd think there would be a lot more
I have rm=2. Set already.
Plus, I see some Get() cars in the URL but, nothing I can use .
Also, I am passing a custom variable , which is going through, and being used by the IPN to update the user account just fine. I just don't see how to connect the return page and the customer, preferably with the $custom var
Help?
Try using var_dump($_POST); instead of echo($_post);
Apparently, there are no POST variables coming from PayPal, they're all GET variables. A VAR_DUMP(GET) will show like 6 things, including your CUSTOM variable (id cm). I thought there would be more and it would be in POST format.
I also thought there would be a way to show everything, POST, GET, SESSION, etc. I even tried using Firefox NETWORK setting, but there were like 50 separate items. None of which seemed to contain my data. I'm sure it was there, but, hidden.

Saving changes to DB made in a webpage

I rewrote the title and content 3 times before posting it, I don't find the right way to ask this :P
I have a page that manage a list of notes, I have a CRUD on that page but the items are created and saved in javascript (using knockoutjs).
I create a new note, I add it to the model in javascript and it show up in the page.
The way Im saving the notes to the database is when I add it to the model, I send it via Ajax (async) to the server. So I have my note on screen and in the database really fast.
I send a note without Id to the server and EF will take care of the Id.
So far so good.
Imagine that I add a note but I dont refresh the webpage, so the note is in the database, is in the javascript model too but in the model it doesn't have the id yet.
I make some changes to the note and yeah, I want to update the note in the database... but... how?
I send my note to the server with the changes, but remember, the item still have no Id so I can't say:
Hey EF, give me the note with the ID == xx and we are going to update that note.
The others properties can be changed on the webpage so I have nothing that identifies the note apart from the Id, who doesn't work here.
I tried this:
Send the new note to the server, insert it on the database, retrieve it again (to pick the Id), send it back to javascript and update the object with the Id. So when I edit, I have the Id. Yeah, but the "save" call need to be sync and that destroy the experience.
Any ideas?
EDIT: The sync options is not that slow at the end but there have to be a async way and meh, the thing of "Insert on database", "Retrieve the last item I inserted" and "return back to the client" is a little hackish.
You could return the id of the new record in your asynch call. If you are using jQuery you can subscribe to the "success" callback and as long as your controller returns a JSON with the id of the new record you could update your model on the client side.
Even with this approach, you will need to have a way to identify the item updated on the client side (which is really the root of your question.) For that you can probably generate a random GUID on the client side, send it to the server when saving, and return it to jQuery when returning the ID so that you can identify the correct element to update on the page.

Need help with Zend Framework dynamic Namespaces

I want to make my system redirect unknown requests such as
www.address.com/a_company
to the adress
www.address.com/companies/company/ and display the company a_company if it exists in the database, otherwise throw the user to a 404 not found page.
So in detail, I want to make namespace that is as the first example dynamically, if the company exist in the database, I have no problem connecting to the database and retrieving information or finding a way to parse a company name, I just need help how to make my system check and run a function every time the address doesn't exist and show the second page (/companies/company/)..
I am using an Acl as well, but I think it should be fine if the page is /companies/company and then possibly add /?c=a_company or similar.
Thank you.
/Marcus
simply create a front controller plugin which checks the request params agains the database before the request is dispatched.