aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Kavlie <akavlie@gmail.com>2011-11-04 22:38:57 -0700
committerAaron Kavlie <akavlie@gmail.com>2011-11-04 22:38:57 -0700
commit8fdc3c197369793dc52a989e8000e7493d5ca038 (patch)
tree6de015f727c234f697b17bcd341bda6d5d66de71
parenta89eb161d6e7531fec86bb992e54e1aefc9e5404 (diff)
downloadreevo-webirc-8fdc3c197369793dc52a989e8000e7493d5ca038.tar.gz
reevo-webirc-8fdc3c197369793dc52a989e8000e7493d5ca038.zip
Add messages when users join or part a channel.
-rw-r--r--app.js40
1 files changed, 34 insertions, 6 deletions
diff --git a/app.js b/app.js
index c6eaad8..5f2dc94 100644
--- a/app.js
+++ b/app.js
@@ -9,11 +9,25 @@ $(function() {
9 // MODELS & COLLECTIONS 9 // MODELS & COLLECTIONS
10 // ==================== 10 // ====================
11 var Message = Backbone.Model.extend({ 11 var Message = Backbone.Model.extend({
12 // expected properties:
13 // - sender
14 // - text
15 defaults: { 12 defaults: {
13 // expected properties:
14 // - sender
15 // - text
16 'type': 'message' 16 'type': 'message'
17 },
18
19 // Set output text for status messages
20 setText: function() {
21 var text = '';
22 switch (this.get('type')) {
23 case 'join':
24 text = this.get('nick') + ' joined the channel';
25 break;
26 case 'part':
27 text = this.get('nick') + ' left the channel';
28 break;
29 }
30 this.set({text: text});
17 } 31 }
18 }); 32 });
19 33
@@ -22,6 +36,9 @@ $(function() {
22 }); 36 });
23 37
24 var Person = Backbone.Model.extend({ 38 var Person = Backbone.Model.extend({
39 defaults: {
40 opStatus: ''
41 }
25 }); 42 });
26 43
27 var Participants = Backbone.Collection.extend({ 44 var Participants = Backbone.Collection.extend({
@@ -82,7 +99,6 @@ $(function() {
82 var MessageView = Backbone.View.extend({ 99 var MessageView = Backbone.View.extend({
83 tmpl: $('#message-tmpl').html(), 100 tmpl: $('#message-tmpl').html(),
84 initialize: function() { 101 initialize: function() {
85 this.el.className = this.model.get('type');
86 this.render(); 102 this.render();
87 }, 103 },
88 104
@@ -92,7 +108,8 @@ $(function() {
92 text: this.model.get('text') 108 text: this.model.get('text')
93 }; 109 };
94 var html = Mustache.to_html(this.tmpl, context); 110 var html = Mustache.to_html(this.tmpl, context);
95 $(this.el).html(html); 111 $(this.el).addClass(this.model.get('type'))
112 .html(html);
96 return this; 113 return this;
97 } 114 }
98 }); 115 });
@@ -103,7 +120,6 @@ $(function() {
103 position: {}, 120 position: {},
104 121
105 initialize: function() { 122 initialize: function() {
106 // frame.bind('add', this.focus, this);
107 _.bindAll(this); 123 _.bindAll(this);
108 }, 124 },
109 125
@@ -366,6 +382,12 @@ $(function() {
366 console.log('Join event received for ' + data.channel + ' - ' + data.nick); 382 console.log('Join event received for ' + data.channel + ' - ' + data.nick);
367 if (data.nick == irc.me.get('nick')) { 383 if (data.nick == irc.me.get('nick')) {
368 frames.add({name: data.channel}); 384 frames.add({name: data.channel});
385 } else {
386 channel = frames.getByName(data.channel);
387 channel.participants.add({nick: data.nick});
388 var joinMessage = new Message({type: 'join', nick: data.nick});
389 joinMessage.setText();
390 channel.stream.add(joinMessage);
369 } 391 }
370 }); 392 });
371 393
@@ -373,6 +395,12 @@ $(function() {
373 console.log('Part event received for ' + data.channel + ' - ' + data.nick); 395 console.log('Part event received for ' + data.channel + ' - ' + data.nick);
374 if (data.nick == irc.me.get('nick')) { 396 if (data.nick == irc.me.get('nick')) {
375 frames.getByName(data.channel).part(); 397 frames.getByName(data.channel).part();
398 } else {
399 channel = frames.getByName(data.channel);
400 channel.participants.add({nick: data.nick});
401 var partMessage = new Message({type: 'part', nick: data.nick});
402 partMessage.setText();
403 channel.stream.add(partMessage);
376 } 404 }
377 }); 405 });
378 406