From 3aa7b8ccce252edc6c708962f11b7375369c29e7 Mon Sep 17 00:00:00 2001 From: Darren Date: Sat, 12 Jul 2014 19:23:05 +0100 Subject: [PATCH] Moving channel set_topic_by text to topic bar title --- client/src/models/network.js | 4 ++-- client/src/views/channel.js | 14 +++++++++++--- client/src/views/topicbar.js | 18 ++++++++++++++++-- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/client/src/models/network.js b/client/src/models/network.js index 62f70c9..b2fbb3c 100644 --- a/client/src/models/network.js +++ b/client/src/models/network.js @@ -550,8 +550,8 @@ 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}); } diff --git a/client/src/views/channel.js b/client/src/views/channel.js index b73ad2a..bf1fcc2 100644 --- a/client/src/views/channel.js +++ b/client/src/views/channel.js @@ -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'); - }, + } }); diff --git a/client/src/views/topicbar.js b/client/src/views/topicbar.js index c12507f..85c4690 100644 --- a/client/src/views/topicbar.js +++ b/client/src/views/topicbar.js @@ -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 -- 2.25.1