Commit 4425c3dd authored by JC Brand's avatar JC Brand

Always show a new topic, even if the previous one was hidden

parent bc4d0165
......@@ -581,6 +581,45 @@
done();
}));
it("will always be shown when it's new",
mock.initConverse(
['rosterGroupsFetched'], {},
async function (done, _converse) {
await test_utils.openAndEnterChatRoom(_converse, 'jdev@conference.jabber.org', 'jc');
const text = 'Jabber/XMPP Development | RFCs and Extensions: https://xmpp.org/ | Protocol and XSF discussions: xsf@muc.xmpp.org';
let stanza = u.toStanza(`
<message xmlns="jabber:client" to="${_converse.jid}" type="groupchat" from="jdev@conference.jabber.org/ralphm">
<subject>${text}</subject>
</message>`);
_converse.connection._dataRecv(test_utils.createRequest(stanza));
const view = _converse.chatboxviews.get('jdev@conference.jabber.org');
await new Promise(resolve => view.model.once('change:subject', resolve));
const head_desc = await u.waitUntil(() => view.el.querySelector('.chat-head__desc'));
expect(head_desc?.textContent.trim()).toBe(text);
let topic_el = view.el.querySelector('.chat-head__desc');
expect(topic_el.textContent.trim()).toBe(text);
expect(u.isVisible(topic_el)).toBe(true);
const toggle = view.el.querySelector('.hide-topic');
expect(toggle.textContent).toBe('Hide topic');
toggle.click();
await u.waitUntil(() => !u.isVisible(topic_el));
stanza = u.toStanza(`
<message xmlns="jabber:client" to="${_converse.jid}" type="groupchat" from="jdev@conference.jabber.org/ralphm">
<subject>Another topic</subject>
</message>`);
_converse.connection._dataRecv(test_utils.createRequest(stanza));
await u.waitUntil(() => u.isVisible(view.el.querySelector('.chat-head__desc')));
topic_el = view.el.querySelector('.chat-head__desc');
expect(topic_el.textContent.trim()).toBe('Another topic');
done();
}));
it("causes an info message to be shown when received in real-time",
mock.initConverse(
['rosterGroupsFetched'], {},
......
......@@ -1274,8 +1274,7 @@ converse.plugins.add('converse-muc-views', {
* @method _converse.ChatRoomView#generateHeadingTemplate
*/
async generateHeadingTemplate () {
const jids = await api.user.settings.get('mucs_with_hidden_subject', [])
const subject_hidden = jids.includes(this.model.get('jid'));
const subject_hidden = await this.model.isSubjectHidden();
const heading_btns = await this.getHeadingButtons(subject_hidden);
const standalone_btns = heading_btns.filter(b => b.standalone);
const dropdown_btns = heading_btns.filter(b => !b.standalone);
......@@ -1289,14 +1288,8 @@ converse.plugins.add('converse-muc-views', {
}));
},
async toggleTopic () {
const muc_jid = this.model.get('jid');
const jids = await api.user.settings.get('mucs_with_hidden_subject', []);
if (jids.includes(this.model.get('jid'))) {
api.user.settings.set('mucs_with_hidden_subject', jids.filter(jid => jid !== muc_jid));
} else {
api.user.settings.set('mucs_with_hidden_subject', [...jids, muc_jid]);
}
toggleTopic () {
this.model.toggleSubjectHiddenState();
},
showInviteModal (ev) {
......
......@@ -1681,6 +1681,21 @@ converse.plugins.add('converse-muc', {
}
},
async isSubjectHidden () {
const jids = await api.user.settings.get('mucs_with_hidden_subject', [])
return jids.includes(this.get('jid'));
},
async toggleSubjectHiddenState () {
const muc_jid = this.get('jid');
const jids = await api.user.settings.get('mucs_with_hidden_subject', []);
if (jids.includes(this.get('jid'))) {
api.user.settings.set('mucs_with_hidden_subject', jids.filter(jid => jid !== muc_jid));
} else {
api.user.settings.set('mucs_with_hidden_subject', [...jids, muc_jid]);
}
},
/**
* Handle a possible subject change and return `true` if so.
* @private
......@@ -1688,7 +1703,7 @@ converse.plugins.add('converse-muc', {
* @param { object } attrs - Attributes representing a received
* message, as returned by {@link stanza_utils.getMessageAttributesFromStanza}
*/
handleSubjectChange (attrs) {
async handleSubjectChange (attrs) {
if (isString(attrs.subject) && !attrs.thread && !attrs.message) {
// https://xmpp.org/extensions/xep-0045.html#subject-mod
// -----------------------------------------------------
......@@ -1697,22 +1712,17 @@ converse.plugins.add('converse-muc', {
// MUST NOT contain a <body/> element (or a <thread/> element).
const subject = attrs.subject;
const author = attrs.nick;
u.safeSave(this, {
'subject': {author, 'text': attrs.subject || ''},
'subject_hidden': subject ? false : this.get('subject_hidden')
});
u.safeSave(this, {'subject': {author, 'text': attrs.subject || ''}});
if (!attrs.is_delayed) {
const message = subject ? __('Topic set by %1$s', author) : __('Topic cleared by %1$s', author);
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'
});
this.createMessage({message, 'nick': attrs.nick, 'type': 'info'});
}
if (await this.isSubjectHidden()) {
this.toggleSubjectHiddenState();
}
}
return true;
......@@ -2028,7 +2038,7 @@ converse.plugins.add('converse-muc', {
if (await this.handleRetraction(attrs) ||
await this.handleModeration(attrs) ||
this.handleSubjectChange(attrs)) {
await this.handleSubjectChange(attrs)) {
this.removeNotification(attrs.nick, ['composing', 'paused']);
return api.trigger('message', {'stanza': original_stanza});
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment