如何在 AJAX 实时聊天中实现聊天审核?
我用 PHP 和 PHP 做了一个相当基本的 AJAX 聊天。 MySQL。聊天消息存储在 MySQL 数据库中,我每隔几秒钟轮询(我知道,我知道)以检查新消息。
为了减少带宽和更新时间,我将其设置为在第一个请求时返回所有消息,然后之后的每个请求仅返回 id 大于接收到的最后一条消息 id 的消息。客户端将这些新消息添加到聊天底部,并删除顶部的旧消息,以使聊天始终保持在 150 条消息以内。
这很有效,但有一个致命的缺陷。当管理员删除聊天消息时,除非您重新加载页面,否则它不会从聊天屏幕中删除。我怎样才能改变我的系统以允许删除邮件,或者改变我的方法以使这有效?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以以某种方式跟踪已删除的 ID。要么只是在数据库中将它们标记为已删除,要么如果您必须真正删除记录,请跟踪这些已删除消息的 ID。然后向 AJAX 响应添加一个新部分,其中列出了那些已删除的 ID。
然后,客户端可以浏览消息历史记录并删除相应的条目。假设您已将消息 ID 附加到聊天历史记录中的消息中,这应该是一个相对简单的操作。
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.