I have a number of action a user can preform in a social network website, like adding friends following people and such.
Now these actions are done by Ajax, and the user could easily undo them(when say following someone, the follow link is turned into unfollow and clicking it again -of course- results in unfollowing the user, and it -the link- turning back into follow).
When these actions occur, the user (being followed) is notified by via email. and the code that sends the email is run in the same ajax call. That results in two problems, one is that the email is sent even if the user decides to unfollow the other person at once. And two, multiple emails are sent if the user hits the follow/unfollow link multiple times.
I thought of using a session variable to store users'actions and then at "some point" check on that variable and preform accordingly. My struggle is in finding that "some point", thought of when the user logs out, but I can't guarantee that the user will actually log out.
any suggestions?