Moving channel set_topic_by text to topic bar title
authorDarren <darren@darrenwhitlen.com>
Sat, 12 Jul 2014 18:23:05 +0000 (19:23 +0100)
committerDarren <darren@darrenwhitlen.com>
Sat, 12 Jul 2014 18:23:05 +0000 (19:23 +0100)
client/src/models/network.js
client/src/views/channel.js
client/src/views/topicbar.js

index 62f70c92c7ee785146eef226f75164b677b090bf..b2fbb3cf1260d5d3487d38d780cc945c0a155d48 100644 (file)
         c = this.panels.getByName(event.channel);
         if (!c) return;
 
-        when = formatDate(new Date(event.when * 1000));
-        c.addMsg('', styleText('channel_topic_setby', {text: translateText('client_models_network_topic', [event.nick, when]), channel: event.channel}), 'topic');
+        when = new Date(event.when * 1000);
+        c.set('topic_set_by', {nick: event.nick, when: when});
     }
 
 
index b73ad2a349d11635588b58b245e7d2b2059a7cd9..bf1fcc2b55a98a4ddd1412830006b6eb3269b841 100644 (file)
@@ -22,6 +22,7 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({
         this.$el.append(this.$messages);
 
         this.model.bind('change:topic', this.topic, this);
+        this.model.bind('change:topic_set_by', this.topicSetBy, this);
 
         if (this.model.get('members')) {
             this.model.get('members').bind('add', function (member) {
@@ -322,8 +323,15 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({
         this.model.addMsg('', styleText('channel_topic', {text: topic, channel: this.model.get('name')}), 'topic');
 
         // If this is the active channel then update the topic bar
-        if (_kiwi.app.panels().active === this) {
-            _kiwi.app.topicbar.setCurrentTopic(this.model.get("topic"));
+        if (_kiwi.app.panels().active === this.model) {
+            _kiwi.app.topicbar.setCurrentTopicFromChannel(this.model);
+        }
+    },
+
+    topicSetBy: function (topic) {
+        // If this is the active channel then update the topic bar
+        if (_kiwi.app.panels().active === this.model) {
+            _kiwi.app.topicbar.setCurrentTopicFromChannel(this.model);
         }
     },
 
@@ -425,5 +433,5 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({
         if (!nick_class) return;
 
         $('.'+nick_class).removeClass('global_nick_highlight');
-    },
+    }
 });
index c12507fe369b580384543408cdad8d578b7dec18..85c4690c841d5b0a4b34f4b6a2f7f0c6dc5e6e69 100644 (file)
@@ -7,7 +7,7 @@ _kiwi.view.TopicBar = Backbone.View.extend({
         _kiwi.app.panels.bind('active', function (active_panel) {
             // If it's a channel topic, update and make editable
             if (active_panel.isChannel()) {
-                this.setCurrentTopic(active_panel.get('topic') || '');
+                this.setCurrentTopicFromChannel(active_panel);
                 this.$el.find('div').attr('contentEditable', true);
 
             } else {
@@ -21,7 +21,7 @@ _kiwi.view.TopicBar = Backbone.View.extend({
     process: function (ev) {
         var inp = $(ev.currentTarget),
             inp_val = inp.text();
-        
+
         // Only allow topic editing if this is a channel panel
         if (!_kiwi.app.panels().active.isChannel()) {
             return false;
@@ -39,5 +39,19 @@ _kiwi.view.TopicBar = Backbone.View.extend({
 
         // We only want a plain text version
         $('div', this.$el).html(formatIRCMsg(_.escape(new_topic)));
+    },
+
+    setCurrentTopicFromChannel: function(channel) {
+        var set_by = channel.get('topic_set_by'),
+            set_by_text = '';
+
+        this.setCurrentTopic(channel.get("topic"));
+
+        if (set_by) {
+            set_by_text += translateText('client_models_network_topic', [set_by.nick, formatDate(set_by.when)]);
+            this.$el.attr('title', set_by_text);
+        } else {
+            this.$el.attr('title', '');
+        }
     }
 });
\ No newline at end of file