diff --git a/lib/channel-new.js b/lib/channel-new.js index 89f74298..496f9e63 100644 --- a/lib/channel-new.js +++ b/lib/channel-new.js @@ -1156,6 +1156,34 @@ Channel.prototype.packUserData = function (user) { }; }; +/** + * Sends a user.meta update, optionally filtering by minimum rank + */ +Channel.prototype.sendUserMeta = function (users, user, minrank) { + var self = this; + var userdata = self.packUserData(user); + self.users.filter(function (u) { + return typeof minrank !== "number" || u.rank > minrank + }).forEach(function (u) { + if (u.rank >= 255) { + u.socket.emit("setUserMeta", { + name: user.name, + meta: userdata.sadmin.meta + }); + } else if (u.rank >= 2) { + u.socket.emit("setUserMeta", { + name: user.name, + meta: userdata.mod.meta + }); + } else { + u.socket.emit("setUserMeta", { + name: user.name, + meta: userdata.base.meta + }); + } + }); +}; + /** * Send a user join notification */ @@ -2537,7 +2565,7 @@ Channel.prototype.handleChat = function (user, data) { time: Date.now() }; this.shadowMutedUsers().forEach(function (u) { - u.socket.emit("chatMsg", msgobject); + u.socket.emit("chatMsg", msgobj); }); return; } diff --git a/lib/chatcommand.js b/lib/chatcommand.js index a1c30c70..d0bbdb17 100644 --- a/lib/chatcommand.js +++ b/lib/chatcommand.js @@ -195,32 +195,13 @@ function handleShadowMute(chan, user, args) { /* Reset a previous regular mute */ if (chan.mutedUsers.contains(person.name.toLowerCase())) { chan.mutedUsers.remove(person.name.toLowerCase()); - chan.sendAll("setUserIcon", { - name: person.name, - icon: false - }); } + + person.meta.smuted = person.meta.muted = true; + chan.sendUserMeta(chan.users, person, 2); chan.mutedUsers.add("[shadow]" + person.name.toLowerCase()); chan.logger.log("*** " + user.name + " shadow muted " + args[0]); - person.meta.icon = "icon-volume-off"; - chan.sendAllExcept(person, "setUserIcon", { - name: person.name, - icon: "icon-volume-off" - }); - var pkt = { - username: "[server]", - msg: user.name + " shadow muted " + args[0], - meta: { - addClass: "server-whisper", - addClassToNameAndTimestamp: true - }, - time: Date.now() - }; - chan.users.forEach(function (u) { - if (u.rank >= 2) { - u.socket.emit("chatMsg", pkt); - } - }); + chan.sendModMessage(user.name + " shadow muted " + args[0], 2); } } } @@ -243,13 +224,11 @@ function handleMute(chan, user, args) { }); return; } - person.meta.icon = "icon-volume-off"; + person.meta.muted = true; + chan.sendUserMeta(chan.users, person); chan.mutedUsers.add(person.name.toLowerCase()); - chan.sendAll("setUserIcon", { - name: person.name, - icon: "icon-volume-off" - }); chan.logger.log("*** " + user.name + " muted " + args[0]); + chan.sendModMessage(user.name + " muted " + args[0], 2); } } } @@ -272,14 +251,14 @@ function handleUnmute(chan, user, args) { }); return; } - person.meta.icon = false; + person.meta.muted = false; + var wasSmuted = person.meta.smuted; + person.meta.smuted = false; + chan.sendUserMeta(chan.users, person, wasSmuted ? 2 : false); chan.mutedUsers.remove(person.name.toLowerCase()); chan.mutedUsers.remove("[shadow]" + person.name.toLowerCase()); - chan.sendAll("setUserIcon", { - name: person.name, - icon: false - }); chan.logger.log("*** " + user.name + " unmuted " + args[0]); + chan.sendModMessage(user.name + " unmuted " + args[0], 2); } } } diff --git a/lib/user.js b/lib/user.js index a3f862b7..97a11749 100644 --- a/lib/user.js +++ b/lib/user.js @@ -128,34 +128,6 @@ User.prototype.kick = function (reason) { this.socket.disconnect(true); }; -/** - * Packs user metadata - */ -User.prototype.packMeta = function (opts) { - var meta = {}; - if (opts.afk) { - meta.afk = this.meta.afk; - } - - if (opts.aliases) { - meta.aliases = this.meta.aliases; - } - - if (opts.ip) { - meta.ip = this.ip; - } - - if (opts.muted) { - meta.muted = this.meta.muted; - } - - if (opts.smuted) { - meta.smuted = this.meta.smuted; - } - - return meta; -}; - /** * Initializes socket message callbacks for a channel user */ diff --git a/www/assets/js/callbacks.js b/www/assets/js/callbacks.js index daf458ee..93aa77a0 100644 --- a/www/assets/js/callbacks.js +++ b/www/assets/js/callbacks.js @@ -529,6 +529,15 @@ Callbacks = { } user.data("meta", data); + if (data.meta.muted || data.meta.smuted) { + user.data("icon", "glyphicon-volume-off"); + } else { + user.data("icon", false); + } + + formatUserlistItem(user, data); + addUserDropdown(user, data); + sortUserlist(); }, setUserProfile: function (data) {