Add private messaging
This commit is contained in:
parent
573e59680e
commit
b41529d4aa
7 changed files with 208 additions and 7 deletions
|
|
@ -2865,6 +2865,57 @@ Channel.prototype.handleChat = function (user, data) {
|
|||
}
|
||||
};
|
||||
|
||||
Channel.prototype.handlePm = function (user, data) {
|
||||
if (typeof data.meta !== "object") {
|
||||
data.meta = {};
|
||||
}
|
||||
|
||||
if (!user.name) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof data.msg !== "string" || typeof data.to !== "string") {
|
||||
return;
|
||||
}
|
||||
|
||||
var msg = data.msg.substring(0, 240);
|
||||
var to = null;
|
||||
for (var i = 0; i < this.users.length; i++) {
|
||||
if (this.users[i].name.toLowerCase() === data.to) {
|
||||
to = this.users[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!to) {
|
||||
return;
|
||||
}
|
||||
|
||||
var meta = {};
|
||||
if (user.rank >= 2) {
|
||||
if ("modflair" in data.meta && data.meta.modflair === user.rank) {
|
||||
meta.modflair = data.meta.modflair;
|
||||
}
|
||||
}
|
||||
|
||||
if (msg.indexOf(">") === 0) {
|
||||
meta.addClass = "greentext";
|
||||
}
|
||||
|
||||
msg = XSS.sanitizeText(msg);
|
||||
msg = this.filterMessage(msg);
|
||||
var msgobj = {
|
||||
username: user.name,
|
||||
to: data.to,
|
||||
msg: msg,
|
||||
meta: meta,
|
||||
time: Date.now()
|
||||
};
|
||||
|
||||
to.socket.emit("pm", msgobj);
|
||||
user.socket.emit("pm", msgobj);
|
||||
};
|
||||
|
||||
/**
|
||||
* Filters a chat message
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -256,6 +256,14 @@ User.prototype.initChannelCallbacks = function () {
|
|||
|
||||
self.channel.handleChat(self, data);
|
||||
});
|
||||
|
||||
wrapTypecheck("pm", function (data) {
|
||||
if (typeof data.msg !== "string" || typeof data.to !== "string") {
|
||||
return;
|
||||
}
|
||||
|
||||
self.channel.handlePm(self, data);
|
||||
});
|
||||
|
||||
wrapTypecheck("newPoll", function (data) {
|
||||
self.channel.handleOpenPoll(self, data);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue