From e380319400454e288b2a38c240d157cd8612699f Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Tue, 8 Mar 2016 11:26:43 +0200 Subject: [PATCH] Handle parts, quits, topics and topic set by --- client/css/style.css | 3 ++- client/js/lounge.js | 1 + client/views/actions/topic.tpl | 6 ++--- client/views/actions/topic_set_by.tpl | 1 + src/models/msg.js | 1 + src/plugins/irc-events/message.js | 2 +- src/plugins/irc-events/part.js | 6 ++--- src/plugins/irc-events/quit.js | 4 ++-- src/plugins/irc-events/topic.js | 34 ++++++++++++++++++++------- 9 files changed, 40 insertions(+), 18 deletions(-) create mode 100644 client/views/actions/topic_set_by.tpl diff --git a/client/css/style.css b/client/css/style.css index c88a072c..41373540 100644 --- a/client/css/style.css +++ b/client/css/style.css @@ -789,7 +789,8 @@ button, #chat .nick .text, #chat .part .text, #chat .quit .text, -#chat .topic .text { +#chat .topic .text, +#chat .topic_set_by .text { color: #999; } diff --git a/client/js/lounge.js b/client/js/lounge.js index 7dfa56d8..c134eba3 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -221,6 +221,7 @@ $(function() { "part", "quit", "topic", + "topic_set_by", "action", "whois", ].indexOf(type) !== -1) { diff --git a/client/views/actions/topic.tpl b/client/views/actions/topic.tpl index 56962794..92fe29ae 100644 --- a/client/views/actions/topic.tpl +++ b/client/views/actions/topic.tpl @@ -1,8 +1,8 @@ -{{#if isSetByChan}} - The topic is: -{{else}} +{{#if from}} {{mode}}{{from}} has changed the topic to: +{{else}} + The topic is: {{/if}} {{{parse text}}} diff --git a/client/views/actions/topic_set_by.tpl b/client/views/actions/topic_set_by.tpl new file mode 100644 index 00000000..87d8ee83 --- /dev/null +++ b/client/views/actions/topic_set_by.tpl @@ -0,0 +1 @@ +Topic set by {{nick}} on {{when}} diff --git a/src/models/msg.js b/src/models/msg.js index d501c4d7..d176c8f5 100644 --- a/src/models/msg.js +++ b/src/models/msg.js @@ -15,6 +15,7 @@ Msg.Type = { QUIT: "quit", TOGGLE: "toggle", TOPIC: "topic", + TOPIC_SET_BY: "topic_set_by", WHOIS: "whois" }; diff --git a/src/plugins/irc-events/message.js b/src/plugins/irc-events/message.js index 3ac43c86..e5a0e38d 100644 --- a/src/plugins/irc-events/message.js +++ b/src/plugins/irc-events/message.js @@ -46,7 +46,7 @@ module.exports = function(irc, network) { // Self messages are never highlighted // Non-self messages are highlighted as soon as the nick is detected var highlight = !self && data.msg.split(" ").some(function(w) { - return (w.replace(/^@/, "").toLowerCase().indexOf(irc.me.toLowerCase()) === 0); + return (w.replace(/^@/, "").toLowerCase().indexOf(irc.user.nick.toLowerCase()) === 0); }); if (chan.id !== client.activeChannel) { diff --git a/src/plugins/irc-events/part.js b/src/plugins/irc-events/part.js index 2c0600d4..7006ac0a 100644 --- a/src/plugins/irc-events/part.js +++ b/src/plugins/irc-events/part.js @@ -4,7 +4,7 @@ var Msg = require("../../models/msg"); module.exports = function(irc, network) { var client = this; irc.on("part", function(data) { - var chan = _.find(network.channels, {name: data.channels[0]}); + var chan = _.find(network.channels, {name: data.channel}); if (typeof chan === "undefined") { return; } @@ -23,9 +23,9 @@ module.exports = function(irc, network) { }); var msg = new Msg({ type: Msg.Type.PART, - mode: chan.getMode(from), + mode: user.mode || "", text: data.message || "", - hostmask:data.hostmask.username + "@" + data.hostmask.hostname, + hostmask: data.ident + "@" + data.hostname, from: from }); chan.messages.push(msg); diff --git a/src/plugins/irc-events/quit.js b/src/plugins/irc-events/quit.js index 59ff5f3b..87dd2eab 100644 --- a/src/plugins/irc-events/quit.js +++ b/src/plugins/irc-events/quit.js @@ -16,9 +16,9 @@ module.exports = function(irc, network) { }); var msg = new Msg({ type: Msg.Type.QUIT, - mode: chan.getMode(from), + mode: user.mode || "", text: data.message || "", - hostmask: data.hostmask.username + "@" + data.hostmask.hostname, + hostmask: data.ident + "@" + data.hostname, from: from }); chan.messages.push(msg); diff --git a/src/plugins/irc-events/topic.js b/src/plugins/irc-events/topic.js index 9c746e5b..abf66fbb 100644 --- a/src/plugins/irc-events/topic.js +++ b/src/plugins/irc-events/topic.js @@ -8,26 +8,44 @@ module.exports = function(irc, network) { if (typeof chan === "undefined") { return; } - var from = data.nick || chan.name; - var topic = data.topic; var msg = new Msg({ type: Msg.Type.TOPIC, - mode: chan.getMode(from), - from: from, - text: topic, - isSetByChan: from === chan.name, - self: from === irc.user.nick + mode: (data.nick && chan.getMode(data.nick)) || "", + from: data.nick, + text: data.topic, + self: data.nick === irc.user.nick }); chan.messages.push(msg); client.emit("msg", { chan: chan.id, msg: msg }); - chan.topic = topic; + + chan.topic = data.topic; client.emit("topic", { chan: chan.id, topic: chan.topic }); }); + + irc.on("topicsetby", function(data) { + var chan = _.find(network.channels, {name: data.channel}); + if (typeof chan === "undefined") { + return; + } + + var msg = new Msg({ + type: Msg.Type.TOPIC_SET_BY, + mode: chan.getMode(data.nick), + nick: data.nick, + when: data.when, + self: data.nick === irc.user.nick + }); + chan.messages.push(msg); + client.emit("msg", { + chan: chan.id, + msg: msg + }); + }); };