From 58417c9a90df6766bd476c595a21c8ca1adae5bb Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Mon, 14 Sep 2015 22:03:39 +0100 Subject: [PATCH] Implemented delete for admins --- lib/chat/controller.js | 2 +- lib/react/message.jsx | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/chat/controller.js b/lib/chat/controller.js index 62e4892..c1817a7 100644 --- a/lib/chat/controller.js +++ b/lib/chat/controller.js @@ -20,7 +20,7 @@ var Message = mongoose.model("Message"); module.exports = namespace => { var broadcastUpdate = message => { - namespace.emit("message:new", message.toJson()); + namespace.emit("message:new", message); }; var refreshMessages = socket => { diff --git a/lib/react/message.jsx b/lib/react/message.jsx index 91003b4..af5f31f 100644 --- a/lib/react/message.jsx +++ b/lib/react/message.jsx @@ -27,6 +27,12 @@ var Chatroom = React.createClass({ self.scrollToBottom(); }); + socket.on("users:update", data => { + self.setProps({ + currentUser: data.currentUser + }); + }); + socket.emit("message:refresh", {}); }, @@ -41,7 +47,9 @@ var Chatroom = React.createClass({ render() { let messages = this.props.history.map(message => - + ); return (
@@ -74,6 +82,11 @@ var ChatMessage = React.createClass({ }, render() { + let deleteButton; + let currentUser = this.props.currentUser; + if (this.props.currentUser && this.props.currentUser.admin) { + deleteButton = ; + } return (
  • @@ -88,6 +101,7 @@ var ChatMessage = React.createClass({
    {this.props.message.author.username} + {deleteButton} {$.timeago(this.props.message.createdAt)}
    @@ -98,6 +112,23 @@ var ChatMessage = React.createClass({ } }); +var DeleteMessageButton = React.createClass({ + handleClick (e) { + e.preventDefault(); + socket.emit("message:delete", { + id: this.props.messageId + }); + }, + + render() { + return ( + + + + ); + } +}) + var MessageBar = React.createClass({ sendMessage(content) { socket.emit("message:new", {