Handle mute/unmute/smute and related icons

This commit is contained in:
calzoneman 2014-01-19 01:58:35 -06:00
parent 6471969f55
commit cd73653451
4 changed files with 50 additions and 62 deletions

View File

@ -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;
}

View File

@ -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);
}
}
}

View File

@ -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
*/

View File

@ -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) {