diff --git a/spec/muc.js b/spec/muc.js index e3e585129..6c42abcba 100644 --- a/spec/muc.js +++ b/spec/muc.js @@ -608,19 +608,39 @@ `))); await u.waitUntil(() => view.model.handleSubjectChange.calls.count() === 2); - const el = sizzle('.chat-info__message', view.el).pop(); + let el = sizzle('.chat-info__message', view.el).pop(); expect(el.textContent.trim()).toBe('Topic set by ralphm'); await u.waitUntil(() => desc.textContent.trim() === 'This is a new topic'); + // Doesn't show multiple subsequent topic change notifications + _converse.connection._dataRecv(test_utils.createRequest(u.toStanza(` + + Yet another topic + `))); + await u.waitUntil(() => view.model.handleSubjectChange.calls.count() === 3); + await u.waitUntil(() => desc.textContent.trim() === 'Yet another topic'); + expect(sizzle('.chat-info__message', view.el).length).toBe(1); + + // Sow multiple subsequent topic change notification from someone else + _converse.connection._dataRecv(test_utils.createRequest(u.toStanza(` + + Some1's topic + `))); + await u.waitUntil(() => view.model.handleSubjectChange.calls.count() === 4); + await u.waitUntil(() => desc.textContent.trim() === "Some1's topic"); + expect(sizzle('.chat-info__message', view.el).length).toBe(2); + el = sizzle('.chat-info__message', view.el).pop(); + expect(el.textContent.trim()).toBe('Topic set by some1'); + // Removes current topic const stanza = u.toStanza( - ` + ` `); _converse.connection._dataRecv(test_utils.createRequest(stanza)); - await u.waitUntil(() => view.model.handleSubjectChange.calls.count() === 3); + await u.waitUntil(() => view.model.handleSubjectChange.calls.count() === 5); await u.waitUntil(() => view.el.querySelector('.chat-head__desc') === null); - expect(view.el.querySelector('.chat-info:last-child').textContent.trim()).toBe("Topic cleared by ralphm"); + expect(view.el.querySelector('.chat-info:last-child').textContent.trim()).toBe("Topic cleared by some1"); done(); })); }); diff --git a/src/headless/converse-muc.js b/src/headless/converse-muc.js index c09050813..203af35e8 100644 --- a/src/headless/converse-muc.js +++ b/src/headless/converse-muc.js @@ -1703,12 +1703,17 @@ converse.plugins.add('converse-muc', { }); if (!attrs.is_delayed) { const message = subject ? __('Topic set by %1$s', author) : __('Topic cleared by %1$s', author); - const data = { - message, - 'nick': attrs.nick, - 'type': 'info' - }; - this.createMessage(data); + const prev_msg = this.messages.last(); + if (prev_msg?.get('nick') !== attrs.nick || + prev_msg?.get('type') !== 'info' || + prev_msg?.get('message') !== message) { + + this.createMessage({ + message, + 'nick': attrs.nick, + 'type': 'info' + }); + } } return true; }