How to implement chat moderation in AJAX live chat?

I've made a fairly basic AJAX chat with PHP & MySQL. The chat messages are stored in the MySQL database, and I poll (I know, I know) every few seconds to check for new messages.

In order to keep the bandwidth and update times down, I've set it up so that on the first request it returns all of the messages, and then each request after that only returns messages with an id greater than the last message id received by the client, adding these new messages to the bottom of the chat and removing old ones at the top to keep the chat at a set 150 messages at all times.

This works great, but there is one fatal flaw. When a chat message is deleted by a moderator, it won't get removed from the chat screen unless you reload the page. How can I either alter my system to allow for messages to be deleted, or change my approach so that this will work?


You could keep track of the deleted ids somehow. Either just flag them deleted in the database, or if you have to truly delete the record, keep track of the IDs of those deleted messages. Then add a new section to your AJAX response that lists those deleted IDs.

The clients could then go through the message history and delete the corresponding entries. Assuming you've been attaching the message IDs to the messages in the chat history, this should be a relatively trivial operation.

Need Your Help

Config rails server on vps hosting

ruby-on-rails webserver hosting vps

I must configure my RoR vps hosting for my rails app, but on my localmachine i simple use webrick...

Cannot find windows service (just installed)

c# visual-studio-2010 windows-7 .net-4.0 windows-services

I just installed a windows service using VS 2010, using the installutil.exe, the cmd prompt window said the commit phase completed successfully, but I cannot see the windows service in the local se...