mirror of
https://github.com/ENSL/ensl_gathers.git
synced 2024-11-27 14:42:13 +00:00
Implemented delete for admins
This commit is contained in:
parent
add58ff761
commit
58417c9a90
2 changed files with 33 additions and 2 deletions
|
@ -20,7 +20,7 @@ var Message = mongoose.model("Message");
|
||||||
module.exports = namespace => {
|
module.exports = namespace => {
|
||||||
|
|
||||||
var broadcastUpdate = message => {
|
var broadcastUpdate = message => {
|
||||||
namespace.emit("message:new", message.toJson());
|
namespace.emit("message:new", message);
|
||||||
};
|
};
|
||||||
|
|
||||||
var refreshMessages = socket => {
|
var refreshMessages = socket => {
|
||||||
|
|
|
@ -27,6 +27,12 @@ var Chatroom = React.createClass({
|
||||||
self.scrollToBottom();
|
self.scrollToBottom();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on("users:update", data => {
|
||||||
|
self.setProps({
|
||||||
|
currentUser: data.currentUser
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
socket.emit("message:refresh", {});
|
socket.emit("message:refresh", {});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -41,7 +47,9 @@ var Chatroom = React.createClass({
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let messages = this.props.history.map(message =>
|
let messages = this.props.history.map(message =>
|
||||||
<ChatMessage message={message} key={message.id} />
|
<ChatMessage message={message}
|
||||||
|
key={message.id}
|
||||||
|
currentUser={this.props.currentUser} />
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<div className="panel panel-default chatbox">
|
<div className="panel panel-default chatbox">
|
||||||
|
@ -74,6 +82,11 @@ var ChatMessage = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
let deleteButton;
|
||||||
|
let currentUser = this.props.currentUser;
|
||||||
|
if (this.props.currentUser && this.props.currentUser.admin) {
|
||||||
|
deleteButton = <DeleteMessageButton messageId={this.props.message._id} />;
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<li className="left clearfix">
|
<li className="left clearfix">
|
||||||
<span className="chat-img pull-left">
|
<span className="chat-img pull-left">
|
||||||
|
@ -88,6 +101,7 @@ var ChatMessage = React.createClass({
|
||||||
<div className="header">
|
<div className="header">
|
||||||
<strong className="primary-font">{this.props.message.author.username}</strong>
|
<strong className="primary-font">{this.props.message.author.username}</strong>
|
||||||
<small className="pull-right text-muted">
|
<small className="pull-right text-muted">
|
||||||
|
{deleteButton}
|
||||||
<i className="fa fa-clock-o fa-fw"></i> {$.timeago(this.props.message.createdAt)}
|
<i className="fa fa-clock-o fa-fw"></i> {$.timeago(this.props.message.createdAt)}
|
||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
|
@ -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 (
|
||||||
|
<a href="#" onClick={this.handleClick}>
|
||||||
|
<i className="fa fa-trash-o"></i>
|
||||||
|
</a>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
var MessageBar = React.createClass({
|
var MessageBar = React.createClass({
|
||||||
sendMessage(content) {
|
sendMessage(content) {
|
||||||
socket.emit("message:new", {
|
socket.emit("message:new", {
|
||||||
|
|
Loading…
Reference in a new issue