From 27378068c06cfbf1c6950d254fa39c30972372e2 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Fri, 7 Sep 2018 10:06:36 +0200 Subject: [PATCH] Fixes #1064 /topic without argument sets topic to "undefined" --- dist/converse.js | 45 +++++++++++++++++----------- spec/chatroom.js | 51 ++------------------------------ src/converse-muc-views.js | 30 +++++++++++-------- src/converse-muc.js | 9 +++--- src/templates/chatroom_head.html | 2 +- 5 files changed, 53 insertions(+), 84 deletions(-) diff --git a/dist/converse.js b/dist/converse.js index 0dc401939..bc977d8f2 100644 --- a/dist/converse.js +++ b/dist/converse.js @@ -68757,7 +68757,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_ type: "groupchat" }).c("subject", { xmlns: "jabber:client" - }).t(match[2]).tree()); + }).t(match[2] || "").tree()); break; @@ -69428,19 +69428,25 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_ // For translators: the %1$s and %2$s parts will get // replaced by the user and topic text respectively // Example: Topic set by JC Brand to: Hello World! - const subject = this.model.get('subject'); + const subject = this.model.get('subject'), + message = subject.text ? __('Topic set by %1$s', subject.author) : __('Topic cleared by %1$s', subject.author), + date = moment().format(); this.content.insertAdjacentHTML('beforeend', tpl_info({ 'data': '', - 'isodate': moment().format(), + 'isodate': date, 'extra_classes': 'chat-event', - 'message': __('Topic set by %1$s', subject.author) - })); - this.content.insertAdjacentHTML('beforeend', tpl_info({ - 'data': '', - 'isodate': moment().format(), - 'extra_classes': 'chat-topic', - 'message': subject.text + 'message': message })); + + if (subject.text) { + this.content.insertAdjacentHTML('beforeend', tpl_info({ + 'data': '', + 'isodate': date, + 'extra_classes': 'chat-topic', + 'message': subject.text + })); + } + this.scrollDown(); } @@ -70893,9 +70899,14 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } sender = resource && Strophe.unescapeNode(resource) || ''; if (!this.handleMessageCorrection(stanza)) { - const subject = _.propertyOf(stanza.querySelector('subject'))('textContent'); + if (sender === '') { + return; + } - if (subject) { + const subject_el = stanza.querySelector('subject'); + + if (subject_el) { + const subject = _.propertyOf(subject_el)('textContent') || ''; u.safeSave(this, { 'subject': { 'author': sender, @@ -70904,10 +70915,6 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } }); } - if (sender === '') { - return; - } - this.createMessage(stanza, original_stanza).then(msg => this.incrementUnreadMsgCounter(msg)).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL)); } @@ -78386,8 +78393,10 @@ __e( o.Strophe.getNodeFromJid(o.jid) ) + __e( o.Strophe.getDomainFromJid(o.jid) ) + '\n '; } ; -__p += '\n \n

' + -__e( o.description ) + +__p += '\n \n

' + +__e(o.description) + '

\n\n

\n \n '; diff --git a/spec/chatroom.js b/spec/chatroom.js index a6c801bb2..2458cd81a 100644 --- a/spec/chatroom.js +++ b/spec/chatroom.js @@ -770,54 +770,6 @@ }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL)) })); - it("shows its description in the chat heading", - mock.initConverseWithPromises( - null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, - function (done, _converse) { - - let sent_IQ, IQ_id, view; - const sendIQ = _converse.connection.sendIQ; - spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) { - sent_IQ = iq; - IQ_id = sendIQ.bind(this)(iq, callback, errback); - }); - _converse.api.rooms.open('coven@chat.shakespeare.lit', {'nick': 'some1'}) - .then(() => { - view = _converse.chatboxviews.get('coven@chat.shakespeare.lit'); - const features_stanza = $iq({ - from: 'coven@chat.shakespeare.lit', - 'id': IQ_id, - 'to': 'dummy@localhost/desktop', - 'type': 'result' - }) - .c('query', { 'xmlns': 'http://jabber.org/protocol/disco#info'}) - .c('identity', { - 'category': 'conference', - 'name': 'A Dark Cave', - 'type': 'text' - }).up() - .c('feature', {'var': 'http://jabber.org/protocol/muc'}).up() - .c('feature', {'var': 'muc_passwordprotected'}).up() - .c('feature', {'var': 'muc_hidden'}).up() - .c('feature', {'var': 'muc_temporary'}).up() - .c('feature', {'var': 'muc_open'}).up() - .c('feature', {'var': 'muc_unmoderated'}).up() - .c('feature', {'var': 'muc_nonanonymous'}).up() - .c('feature', {'var': 'urn:xmpp:mam:0'}).up() - .c('x', { 'xmlns':'jabber:x:data', 'type':'result'}) - .c('field', {'var':'FORM_TYPE', 'type':'hidden'}) - .c('value').t('http://jabber.org/protocol/muc#roominfo').up().up() - .c('field', {'type':'text-single', 'var':'muc#roominfo_description', 'label':'Description'}) - .c('value').t('This is the description').up().up() - .c('field', {'type':'text-single', 'var':'muc#roominfo_occupants', 'label':'Number of participants'}) - .c('value').t(0); - _converse.connection._dataRecv(test_utils.createRequest(features_stanza)); - return test_utils.waitUntil(() => _.get(view.el.querySelector('.chatroom-description'), 'textContent')) - }).then(function () { - expect(view.el.querySelector('.chatroom-description').textContent).toBe('This is the description'); - done(); - }); - })); it("supports the /me command", mock.initConverseWithPromises( @@ -1600,7 +1552,7 @@ }); })); - it("shows received groupchat subject messages", + it("shows the room topic in the header", mock.initConverseWithPromises( null, ['rosterGroupsFetched'], {}, function (done, _converse) { @@ -1618,6 +1570,7 @@ var chat_content = view.el.querySelector('.chat-content'); expect($(chat_content).find('.chat-event:last').text()).toBe('Topic set by ralphm'); expect($(chat_content).find('.chat-topic:last').text()).toBe(text); + expect(view.el.querySelector('.chatroom-description').textContent).toBe(text); done(); }); })); diff --git a/src/converse-muc-views.js b/src/converse-muc-views.js index a86aca9a5..bc75165fb 100644 --- a/src/converse-muc-views.js +++ b/src/converse-muc-views.js @@ -991,7 +991,7 @@ to: this.model.get('jid'), from: _converse.connection.jid, type: "groupchat" - }).c("subject", {xmlns: "jabber:client"}).t(match[2]).tree() + }).c("subject", {xmlns: "jabber:client"}).t(match[2] || "").tree() ); break; case 'voice': @@ -1632,23 +1632,29 @@ // For translators: the %1$s and %2$s parts will get // replaced by the user and topic text respectively // Example: Topic set by JC Brand to: Hello World! - const subject = this.model.get('subject'); + const subject = this.model.get('subject'), + message = subject.text ? __('Topic set by %1$s', subject.author) : + __('Topic cleared by %1$s', subject.author), + date = moment().format(); this.content.insertAdjacentHTML( 'beforeend', tpl_info({ 'data': '', - 'isodate': moment().format(), + 'isodate': date, 'extra_classes': 'chat-event', - 'message': __('Topic set by %1$s', subject.author) - })); - this.content.insertAdjacentHTML( - 'beforeend', - tpl_info({ - 'data': '', - 'isodate': moment().format(), - 'extra_classes': 'chat-topic', - 'message': subject.text + 'message': message })); + + if (subject.text) { + this.content.insertAdjacentHTML( + 'beforeend', + tpl_info({ + 'data': '', + 'isodate': date, + 'extra_classes': 'chat-topic', + 'message': subject.text + })); + } this.scrollDown(); } }); diff --git a/src/converse-muc.js b/src/converse-muc.js index 9409323a6..86ccf9277 100644 --- a/src/converse-muc.js +++ b/src/converse-muc.js @@ -921,13 +921,14 @@ sender = resource && Strophe.unescapeNode(resource) || ''; if (!this.handleMessageCorrection(stanza)) { - const subject = _.propertyOf(stanza.querySelector('subject'))('textContent'); - if (subject) { - u.safeSave(this, {'subject': {'author': sender, 'text': subject}}); - } if (sender === '') { return; } + const subject_el = stanza.querySelector('subject'); + if (subject_el) { + const subject = _.propertyOf(subject_el)('textContent') || ''; + u.safeSave(this, {'subject': {'author': sender, 'text': subject}}); + } this.createMessage(stanza, original_stanza) .then(msg => this.incrementUnreadMsgCounter(msg)) .catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL)); diff --git a/src/templates/chatroom_head.html b/src/templates/chatroom_head.html index 4bec82795..6bc18225a 100644 --- a/src/templates/chatroom_head.html +++ b/src/templates/chatroom_head.html @@ -7,7 +7,7 @@ {{{ o.Strophe.getNodeFromJid(o.jid) }}}@{{{ o.Strophe.getDomainFromJid(o.jid) }}} {[ } ]}
-

{{{ o.description }}}

+

{{{o.description}}}