About an "undo send" feature, the most evident way of doing that is to actually not "do" what you want to "undo".
What I mean is :
- When a user clicks on "send", you should not really send the message
- Instead, you should mark it as "to send in X seconds" -- place it in some queue, for instance
- Which means it'll only be sent after X seconds, and not immediatly.
- During this X number of seconds, if the user clicks "undo send", you just have to remove that mail from the "waiting queue"
Of course, you cannot "undo send" on a mail which has already been sent : it's gone from your server, and there is nothing you can do anymore about it.
To implement that, you'll need :
- Some queue for actions
- To place your data into this queue when the user clicks "send"
- To have some batch that really sends data that's been in the queue for more than X seconds
- To remove the data from the queue when the user clicks "undo send".
The same idea can be applied to "undo delete" :
- When a user clicks on "delete", don't physicilly delete the data
- Instead, use some boolean flag to indicate that it should be considered as deleted
- Then, un-doping that deletion only means de-activating that flag
This can easily be implemented in any language :
- Add a
is_deleted
field on your data
- When displaying the data, filter those for which this flag is enabled
- When deleting, instead of physically deleting, set this flag
- When un-deleting, un-set this flag
The "undo save" can be a bit harder : a solution would be to not keep only one version of the message, but several :
- Each time the user clicks "save", you should store a new version of the message
- Which means you'll end up, after some time, with many versions of the message
- Which will allow you to "come back" to a previous version, restoring it from the history.
This can be done :
- adding a new field called like "
version
" on your data.
- each time the user saves, just increment that field, and store a copy of the data
- i.e. never actually update any exiting data, but always insert a new version of it.
- then, "undo save" only means "get the previous version of the data"