views:

24

answers:

3

Just want to know the logic behind , allowing user comments to be editable for a few minutes in the site ,after which should be made readable.I had seen this in linkedin site. My solution to use create session during the comments submission and refresh for every 3 minutes and check whether the session has timed out after 14 minutes through ajax.let me know your solutions.

i need to know the best solution to implement.

A: 

Or you could use long polling (see Comet), and just track time on the server.

Exploiting the session like the above solution is less than ideal.

Zack
i am not clear on the Comet part. Between the soultion would be to use a token in the response html and it creation time will be added to server. next time when user clicks on the edit link , the token should match the one in session and the get the time left from the current time - time stored in session. if the resulting minutes is more then disable the edit link. is this the best way.
Suresh S
A: 

any solutions please.

Suresh S
+1  A: 

Why not simply refuse changes after a certain time? When a comment is made, store a 'changesExpire' date (say, 10m in the future). When you get a change for a comment that's past the 'changesExpire' date, you simply refuse them.

On the UI, you can have a simple countdown timer. Put up an 'edit' button, fire off the timer. When the timer goes off, hide the button.

If you leave the page, no big deal, it all goes away. If you come back, create a new timer that is set to the remaining time in the 'changesExpire' value.

No reason to keep connections open or anything here.

Will Hartung
thanks for the reply. but if i can hack the javascript , like going to firebug and changing timer value , it will allow to edit.let me know if i am wrong?
Suresh S
Just validate at the server side. You already have stored the comment timestamp in the DB do you? JS isn't there to do some business logic but just to enhance the UX.
BalusC
Always apply the general rule -- "You can't trust anything by the client". Always have to validate stuff on the server side.
Will Hartung