Emit topic over socket

This commit is contained in:
Mattias Erming 2014-10-10 22:05:25 +02:00
parent b3712842bf
commit f42a6487d6
6 changed files with 19 additions and 7 deletions

View File

@ -19,7 +19,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks("grunt-contrib-uglify"); grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks("grunt-contrib-watch"); grunt.loadNpmTasks("grunt-contrib-watch");
grunt.registerTask( grunt.registerTask(
"handlebars", "build",
function() { function() {
grunt.util.spawn({ grunt.util.spawn({
cmd: "node", cmd: "node",
@ -36,6 +36,6 @@ module.exports = function(grunt) {
); );
grunt.registerTask( grunt.registerTask(
"default", "default",
["uglify", "handlebars"] ["uglify", "build"]
); );
}; };

View File

@ -309,6 +309,10 @@ $(function() {
break; break;
} }
}); });
socket.on("topic", function(data) {
$("#chan-" + data.chan).find(".header .topic").html(data.topic);
});
socket.on("users", function(data) { socket.on("users", function(data) {
var users = chat.find("#chan-" + data.chan).find(".users").html(render("user", data)); var users = chat.find("#chan-" + data.chan).find(".users").html(render("user", data));

View File

@ -40,9 +40,10 @@ templates['chat'] = template({"1":function(depth0,helpers,partials,data) {
if (stack1 != null) { buffer += stack1; } if (stack1 != null) { buffer += stack1; }
buffer += " </button>\n </div>\n <span class=\"title\">" buffer += " </button>\n </div>\n <span class=\"title\">"
+ 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))) + 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)))
+ "</span>\n <span class=\"topic\">" + "</span>\n <span class=\"topic\">";
+ 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))) stack1 = ((helpers.parse || (depth0 && depth0.parse) || helperMissing).call(depth0, (depth0 != null ? depth0.topic : depth0), {"name":"parse","hash":{},"data":data}));
+ " </span>\n </div>\n <div class=\"chat\">\n <div class=\"show-more "; if (stack1 != null) { buffer += stack1; }
buffer += "</span>\n </div>\n <div class=\"chat\">\n <div class=\"show-more ";
stack1 = ((helpers.equal || (depth0 && depth0.equal) || helperMissing).call(depth0, ((stack1 = (depth0 != null ? depth0.messages : depth0)) != null ? stack1.length : stack1), 100, {"name":"equal","hash":{},"fn":this.program(6, data),"inverse":this.noop,"data":data})); stack1 = ((helpers.equal || (depth0 && depth0.equal) || helperMissing).call(depth0, ((stack1 = (depth0 != null ? depth0.messages : depth0)) != null ? stack1.length : stack1), 100, {"name":"equal","hash":{},"fn":this.program(6, data),"inverse":this.noop,"data":data}));
if (stack1 != null) { buffer += stack1; } if (stack1 != null) { buffer += stack1; }
return buffer + "\">\n <button class=\"show-more-button\" data-id=\"" return buffer + "\">\n <button class=\"show-more-button\" data-id=\""

View File

@ -13,7 +13,7 @@
</button> </button>
</div> </div>
<span class="title">{{name}}</span> <span class="title">{{name}}</span>
<span class="topic">{{type}} </span> <span class="topic">{{{parse topic}}}</span>
</div> </div>
<div class="chat"> <div class="chat">
<div class="show-more {{#equal messages.length 100}}show{{/equal}}"> <div class="show-more {{#equal messages.length 100}}show{{/equal}}">

View File

@ -15,6 +15,7 @@ function Chan(attr) {
id: id++, id: id++,
messages: [], messages: [],
name: "", name: "",
topic: "",
type: Chan.Type.CHANNEL, type: Chan.Type.CHANNEL,
unread: 0, unread: 0,
users: [] users: []

View File

@ -13,11 +13,12 @@ module.exports = function(irc, network) {
if (from.toLowerCase() == irc.me.toLowerCase()) { if (from.toLowerCase() == irc.me.toLowerCase()) {
self = true; self = true;
} }
var topic = data.topic;
var msg = new Msg({ var msg = new Msg({
type: Msg.Type.TOPIC, type: Msg.Type.TOPIC,
mode: chan.getMode(from), mode: chan.getMode(from),
from: from, from: from,
text: data.topic, text: topic,
self: self self: self
}); });
chan.messages.push(msg); chan.messages.push(msg);
@ -25,5 +26,10 @@ module.exports = function(irc, network) {
chan: chan.id, chan: chan.id,
msg: msg msg: msg
}); });
chan.topic = topic
client.emit("topic", {
chan: chan.id,
topic: topic
});
}); });
}; };