From f42a6487d6608e231b3059bbfb54aa66a323ef17 Mon Sep 17 00:00:00 2001 From: Mattias Erming Date: Fri, 10 Oct 2014 22:05:25 +0200 Subject: [PATCH] Emit topic over socket --- Gruntfile.js | 4 ++-- client/js/shout.js | 4 ++++ client/js/shout.templates.js | 7 ++++--- client/views/chat.tpl | 2 +- src/models/chan.js | 1 + src/plugins/irc-events/topic.js | 8 +++++++- 6 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 625bfd2d..f4c637e7 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -19,7 +19,7 @@ module.exports = function(grunt) { grunt.loadNpmTasks("grunt-contrib-uglify"); grunt.loadNpmTasks("grunt-contrib-watch"); grunt.registerTask( - "handlebars", + "build", function() { grunt.util.spawn({ cmd: "node", @@ -36,6 +36,6 @@ module.exports = function(grunt) { ); grunt.registerTask( "default", - ["uglify", "handlebars"] + ["uglify", "build"] ); }; diff --git a/client/js/shout.js b/client/js/shout.js index 5a50433c..f229ea51 100644 --- a/client/js/shout.js +++ b/client/js/shout.js @@ -309,6 +309,10 @@ $(function() { break; } }); + + socket.on("topic", function(data) { + $("#chan-" + data.chan).find(".header .topic").html(data.topic); + }); socket.on("users", function(data) { var users = chat.find("#chan-" + data.chan).find(".users").html(render("user", data)); diff --git a/client/js/shout.templates.js b/client/js/shout.templates.js index a9d7ebfd..d68bff93 100644 --- a/client/js/shout.templates.js +++ b/client/js/shout.templates.js @@ -40,9 +40,10 @@ templates['chat'] = template({"1":function(depth0,helpers,partials,data) { if (stack1 != null) { buffer += stack1; } buffer += " \n \n " + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper))) - + "\n " - + escapeExpression(((helper = (helper = helpers.type || (depth0 != null ? depth0.type : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"type","hash":{},"data":data}) : helper))) - + " \n \n
\n
\n "; + stack1 = ((helpers.parse || (depth0 && depth0.parse) || helperMissing).call(depth0, (depth0 != null ? depth0.topic : depth0), {"name":"parse","hash":{},"data":data})); + if (stack1 != null) { buffer += stack1; } + buffer += "\n
\n
\n
\n
{{name}} - {{type}} + {{{parse topic}}}
diff --git a/src/models/chan.js b/src/models/chan.js index 3664c125..0121cc19 100644 --- a/src/models/chan.js +++ b/src/models/chan.js @@ -15,6 +15,7 @@ function Chan(attr) { id: id++, messages: [], name: "", + topic: "", type: Chan.Type.CHANNEL, unread: 0, users: [] diff --git a/src/plugins/irc-events/topic.js b/src/plugins/irc-events/topic.js index c12033f1..9814b1a6 100644 --- a/src/plugins/irc-events/topic.js +++ b/src/plugins/irc-events/topic.js @@ -13,11 +13,12 @@ module.exports = function(irc, network) { if (from.toLowerCase() == irc.me.toLowerCase()) { self = true; } + var topic = data.topic; var msg = new Msg({ type: Msg.Type.TOPIC, mode: chan.getMode(from), from: from, - text: data.topic, + text: topic, self: self }); chan.messages.push(msg); @@ -25,5 +26,10 @@ module.exports = function(irc, network) { chan: chan.id, msg: msg }); + chan.topic = topic + client.emit("topic", { + chan: chan.id, + topic: topic + }); }); };