Commit c20dbbbb authored by JC Brand's avatar JC Brand

Store in user settings whether a MUC topic is hidden or not

parent e4986573
...@@ -224,9 +224,9 @@ ...@@ -224,9 +224,9 @@
'nick': ' some1' 'nick': ' some1'
}); });
view.model.set('bookmarked', true); view.model.set('bookmarked', true);
expect(view.el.querySelector('.chatbox-title__text .fa-bookmark')).not.toBe(null); await u.waitUntil(() => view.el.querySelector('.chatbox-title__text .fa-bookmark') !== null);
view.model.set('bookmarked', false); view.model.set('bookmarked', false);
expect(view.el.querySelector('.chatbox-title__text .fa-bookmark')).toBe(null); await u.waitUntil(() => view.el.querySelector('.chatbox-title__text .fa-bookmark') === null);
done(); done();
})); }));
...@@ -253,12 +253,12 @@ ...@@ -253,12 +253,12 @@
expect(_converse.bookmarks.length).toBe(1); expect(_converse.bookmarks.length).toBe(1);
await u.waitUntil(() => _converse.chatboxes.length >= 1); await u.waitUntil(() => _converse.chatboxes.length >= 1);
expect(view.model.get('bookmarked')).toBeTruthy(); expect(view.model.get('bookmarked')).toBeTruthy();
expect(view.el.querySelector('.chatbox-title__text .fa-bookmark')).not.toBe(null); await u.waitUntil(() => view.el.querySelector('.chatbox-title__text .fa-bookmark') !== null);
spyOn(_converse.connection, 'getUniqueId').and.callThrough(); spyOn(_converse.connection, 'getUniqueId').and.callThrough();
const bookmark_icon = view.el.querySelector('.toggle-bookmark'); const bookmark_icon = view.el.querySelector('.toggle-bookmark');
bookmark_icon.click(); bookmark_icon.click();
expect(view.toggleBookmark).toHaveBeenCalled(); expect(view.toggleBookmark).toHaveBeenCalled();
expect(view.el.querySelector('.chatbox-title__text .fa-bookmark')).toBe(null); await u.waitUntil(() => view.el.querySelector('.chatbox-title__text .fa-bookmark') === null);
expect(_converse.bookmarks.length).toBe(0); expect(_converse.bookmarks.length).toBe(0);
// Check that an IQ stanza is sent out, containing no // Check that an IQ stanza is sent out, containing no
......
...@@ -611,6 +611,8 @@ ...@@ -611,6 +611,8 @@
await u.waitUntil(() => sent_stanzas.filter(iq => sizzle('presence history', iq).length).pop()); await u.waitUntil(() => sent_stanzas.filter(iq => sizzle('presence history', iq).length).pop());
const view = _converse.chatboxviews.get('coven@chat.shakespeare.lit'); const view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
await _converse.api.waitUntil('chatRoomViewInitialized');
/* We don't show join/leave messages for existing occupants. We /* We don't show join/leave messages for existing occupants. We
* know about them because we receive their presences before we * know about them because we receive their presences before we
* receive our own. * receive our own.
...@@ -646,8 +648,8 @@ ...@@ -646,8 +648,8 @@
}).up() }).up()
.c('status', {code: '110'}); .c('status', {code: '110'});
_converse.connection._dataRecv(test_utils.createRequest(presence)); _converse.connection._dataRecv(test_utils.createRequest(presence));
expect(sizzle('div.chat-info:first', view.content).pop().textContent.trim()) const text = await u.waitUntil(() => sizzle('div.chat-info:first', view.content).pop()?.textContent);
.toBe("some1 has entered the groupchat"); expect(text.trim()).toBe("some1 has entered the groupchat");
await room_creation_promise; await room_creation_promise;
await u.waitUntil(() => (view.model.session.get('connection_status') === converse.ROOMSTATUS.ENTERED)); await u.waitUntil(() => (view.model.session.get('connection_status') === converse.ROOMSTATUS.ENTERED));
...@@ -664,7 +666,7 @@ ...@@ -664,7 +666,7 @@
'role': 'participant' 'role': 'participant'
}); });
_converse.connection._dataRecv(test_utils.createRequest(presence)); _converse.connection._dataRecv(test_utils.createRequest(presence));
expect(view.content.querySelectorAll('div.chat-info').length).toBe(2); await u.waitUntil(() => view.content.querySelectorAll('div.chat-info').length === 2);
expect(sizzle('div.chat-info:last', view.content).pop().textContent.trim()) expect(sizzle('div.chat-info:last', view.content).pop().textContent.trim())
.toBe("newguy has entered the groupchat"); .toBe("newguy has entered the groupchat");
...@@ -2166,7 +2168,8 @@ ...@@ -2166,7 +2168,8 @@
await new Promise(resolve => view.model.once('change:subject', resolve)); await new Promise(resolve => view.model.once('change:subject', resolve));
expect(sizzle('.chat-event:last', view.el).pop().textContent.trim()).toBe('Topic set by ralphm'); expect(sizzle('.chat-event:last', view.el).pop().textContent.trim()).toBe('Topic set by ralphm');
expect(view.el.querySelector('.chat-head__desc').textContent.trim()).toBe(text); const head_desc = await u.waitUntil(() => view.el.querySelector('.chat-head__desc'));
expect(head_desc?.textContent.trim()).toBe(text);
stanza = u.toStanza( stanza = u.toStanza(
`<message xmlns="jabber:client" to="jc@opkode.com/_converse.js-60429116" type="groupchat" from="jdev@conference.jabber.org/ralphm"> `<message xmlns="jabber:client" to="jc@opkode.com/_converse.js-60429116" type="groupchat" from="jdev@conference.jabber.org/ralphm">
...@@ -2188,7 +2191,7 @@ ...@@ -2188,7 +2191,7 @@
</message>`); </message>`);
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
await new Promise(resolve => view.model.once('change:subject', resolve)); await new Promise(resolve => view.model.once('change:subject', resolve));
expect(view.el.querySelector('.chat-head__desc')).toBe(null); 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 ralphm");
done(); done();
})); }));
......
...@@ -36,9 +36,9 @@ converse.plugins.add('converse-bookmark-views', { ...@@ -36,9 +36,9 @@ converse.plugins.add('converse-bookmark-views', {
// plugin architecture they will replace existing methods on the // plugin architecture they will replace existing methods on the
// relevant objects or classes. // relevant objects or classes.
ChatRoomView: { ChatRoomView: {
getHeadingButtons () { async getHeadingButtons () {
const { _converse } = this.__super__; const { _converse } = this.__super__;
const buttons = this.__super__.getHeadingButtons.call(this); const buttons = await this.__super__.getHeadingButtons.call(this);
if (_converse.allow_bookmarks) { if (_converse.allow_bookmarks) {
const supported = _converse.checkBookmarksSupport(); const supported = _converse.checkBookmarksSupport();
const bookmarked = this.model.get('bookmarked'); const bookmarked = this.model.get('bookmarked');
......
...@@ -139,9 +139,9 @@ converse.plugins.add('converse-minimize', { ...@@ -139,9 +139,9 @@ converse.plugins.add('converse-minimize', {
return result; return result;
}, },
getHeadingButtons () { async getHeadingButtons () {
const { _converse } = this.__super__; const { _converse } = this.__super__;
const buttons = this.__super__.getHeadingButtons.call(this); const buttons = await this.__super__.getHeadingButtons.call(this);
const data = { const data = {
'a_class': 'toggle-chatbox-button', 'a_class': 'toggle-chatbox-button',
'handler': ev => this.minimize(ev), 'handler': ev => this.minimize(ev),
......
...@@ -725,7 +725,7 @@ converse.plugins.add('converse-muc-views', { ...@@ -725,7 +725,7 @@ converse.plugins.add('converse-muc-views', {
this.onMouseMove = this.onMouseMove.bind(this); this.onMouseMove = this.onMouseMove.bind(this);
this.onMouseUp = this.onMouseUp.bind(this); this.onMouseUp = this.onMouseUp.bind(this);
this.render(); await this.render();
this.createSidebarView(); this.createSidebarView();
await this.updateAfterMessagesFetched(); await this.updateAfterMessagesFetched();
this.onConnectionStatusChanged(); this.onConnectionStatusChanged();
...@@ -739,13 +739,13 @@ converse.plugins.add('converse-muc-views', { ...@@ -739,13 +739,13 @@ converse.plugins.add('converse-muc-views', {
api.trigger('chatRoomViewInitialized', this); api.trigger('chatRoomViewInitialized', this);
}, },
render () { async render () {
this.el.setAttribute('id', this.model.get('box_id')); this.el.setAttribute('id', this.model.get('box_id'));
render(tpl_chatroom({ render(tpl_chatroom({
'muc_show_logs_before_join': _converse.muc_show_logs_before_join, 'muc_show_logs_before_join': _converse.muc_show_logs_before_join,
'show_send_button': _converse.show_send_button 'show_send_button': _converse.show_send_button
}), this.el); }), this.el);
this.renderHeading(); await this.renderHeading();
this.renderBottomPanel(); this.renderBottomPanel();
this.content = this.el.querySelector('.chat-content'); this.content = this.el.querySelector('.chat-content');
this.msgs_container = this.el.querySelector('.chat-content__messages'); this.msgs_container = this.el.querySelector('.chat-content__messages');
...@@ -802,8 +802,9 @@ converse.plugins.add('converse-muc-views', { ...@@ -802,8 +802,9 @@ converse.plugins.add('converse-muc-views', {
* @method _converse.ChatRoomView#renderHeading * @method _converse.ChatRoomView#renderHeading
* @param { _converse.ChatRoom } [item] * @param { _converse.ChatRoom } [item]
*/ */
renderHeading () { async renderHeading () {
render(this.generateHeadingTemplate(), this.el.querySelector('.chat-head-chatroom')); const tpl = await this.generateHeadingTemplate();
render(tpl, this.el.querySelector('.chat-head-chatroom'));
}, },
...@@ -1156,7 +1157,7 @@ converse.plugins.add('converse-muc-views', { ...@@ -1156,7 +1157,7 @@ converse.plugins.add('converse-muc-views', {
} }
}, },
getHeadingButtons () { async getHeadingButtons () {
const buttons = [{ const buttons = [{
'i18n_text': __('Details'), 'i18n_text': __('Details'),
'i18n_title': __('Show more information about this groupchat'), 'i18n_title': __('Show more information about this groupchat'),
...@@ -1212,11 +1213,14 @@ converse.plugins.add('converse-muc-views', { ...@@ -1212,11 +1213,14 @@ converse.plugins.add('converse-muc-views', {
}); });
} }
const muc_jid = this.model.get('jid');
const jids = await api.user.settings.get('mucs_with_hidden_subject', [])
const subject_hidden = jids.includes(muc_jid);
const subject = this.model.get('subject'); const subject = this.model.get('subject');
if (subject && subject.text) { if (subject && subject.text) {
buttons.push({ buttons.push({
'i18n_text': this.model.get('subject_hidden') ? __('Show topic') : __('Hide topic'), 'i18n_text': subject_hidden ? __('Show topic') : __('Hide topic'),
'i18n_title': this.model.get('subject_hidden') ? 'i18n_title': subject_hidden ?
__('Show the topic message in the heading') : __('Show the topic message in the heading') :
__('Hide the topic in the heading'), __('Hide the topic in the heading'),
'handler': ev => this.toggleTopic(ev), 'handler': ev => this.toggleTopic(ev),
...@@ -1249,8 +1253,8 @@ converse.plugins.add('converse-muc-views', { ...@@ -1249,8 +1253,8 @@ converse.plugins.add('converse-muc-views', {
* @private * @private
* @method _converse.ChatRoomView#generateHeadingTemplate * @method _converse.ChatRoomView#generateHeadingTemplate
*/ */
generateHeadingTemplate () { async generateHeadingTemplate () {
const heading_btns = this.getHeadingButtons(); const heading_btns = await this.getHeadingButtons();
const standalone_btns = heading_btns.filter(b => b.standalone); const standalone_btns = heading_btns.filter(b => b.standalone);
const dropdown_btns = heading_btns.filter(b => !b.standalone); const dropdown_btns = heading_btns.filter(b => !b.standalone);
return tpl_chatroom_head( return tpl_chatroom_head(
...@@ -1262,11 +1266,16 @@ converse.plugins.add('converse-muc-views', { ...@@ -1262,11 +1266,16 @@ converse.plugins.add('converse-muc-views', {
})); }));
}, },
toggleTopic () { async toggleTopic () {
this.model.save('subject_hidden', !this.model.get('subject_hidden')); 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]);
}
}, },
showInviteModal (ev) { showInviteModal (ev) {
ev.preventDefault(); ev.preventDefault();
if (this.muc_invite_modal === undefined) { if (this.muc_invite_modal === undefined) {
...@@ -1950,15 +1959,16 @@ converse.plugins.add('converse-muc-views', { ...@@ -1950,15 +1959,16 @@ converse.plugins.add('converse-muc-views', {
} }
}, },
showJoinNotification (occupant) { async showJoinNotification (occupant) {
if (!_converse.muc_show_join_leave || if (!_converse.muc_show_join_leave ||
this.model.session.get('connection_status') !== converse.ROOMSTATUS.ENTERED) { this.model.session.get('connection_status') !== converse.ROOMSTATUS.ENTERED) {
return; return;
} }
const nick = occupant.get('nick'), await api.waitUntil('chatRoomViewInitialized');
stat = _converse.muc_show_join_leave_status ? occupant.get('status') : null, const nick = occupant.get('nick');
prev_info_el = this.getPreviousJoinOrLeaveNotification(this.msgs_container.lastElementChild, nick), const stat = _converse.muc_show_join_leave_status ? occupant.get('status') : null;
data = prev_info_el?.dataset || {}; const prev_info_el = this.getPreviousJoinOrLeaveNotification(this.msgs_container.lastElementChild, nick);
const data = prev_info_el?.dataset || {};
if (data.leave === nick) { if (data.leave === nick) {
let message; let message;
...@@ -2004,12 +2014,13 @@ converse.plugins.add('converse-muc-views', { ...@@ -2004,12 +2014,13 @@ converse.plugins.add('converse-muc-views', {
this.scrollDown(); this.scrollDown();
}, },
showLeaveNotification (occupant) { async showLeaveNotification (occupant) {
if (!_converse.muc_show_join_leave || if (!api.settings.get('muc_show_join_leave') ||
occupant.get('states').includes('303') || occupant.get('states').includes('303') ||
occupant.get('states').includes('307')) { occupant.get('states').includes('307')) {
return; return;
} }
await api.waitUntil('chatRoomViewInitialized');
const nick = occupant.get('nick'), const nick = occupant.get('nick'),
stat = _converse.muc_show_join_leave_status ? occupant.get('status') : null, stat = _converse.muc_show_join_leave_status ? occupant.get('status') : null,
prev_info_el = this.getPreviousJoinOrLeaveNotification(this.msgs_container.lastElementChild, nick), prev_info_el = this.getPreviousJoinOrLeaveNotification(this.msgs_container.lastElementChild, nick),
......
...@@ -532,12 +532,14 @@ const api = _converse.api = { ...@@ -532,12 +532,14 @@ const api = _converse.api = {
/** /**
* Get the value of a particular user setting. * Get the value of a particular user setting.
* @method _converse.api.user.settings.get * @method _converse.api.user.settings.get
* @param {String} key - hello world
* @param {*} fallback - An optional fallback value if the user setting is undefined
* @returns {Promise} Promise which resolves with the value of the particular configuration setting. * @returns {Promise} Promise which resolves with the value of the particular configuration setting.
* @example _converse.api.user.settings.get("foo"); * @example _converse.api.user.settings.get("foo");
*/ */
async get (key) { async get (key, fallback) {
await initUserSettings(); await initUserSettings();
return user_settings.get(key); return user_settings.get(key) === undefined ? fallback : user_settings.get(key);
}, },
/** /**
......
...@@ -251,9 +251,10 @@ ...@@ -251,9 +251,10 @@
[localStorage, sessionStorage].forEach( [localStorage, sessionStorage].forEach(
s => Object.keys(s).forEach(k => k.match(/^converse-test-/) && s.removeItem(k)) s => Object.keys(s).forEach(k => k.match(/^converse-test-/) && s.removeItem(k))
); );
const cache_key = `converse.room-bookmarksromeo@montague.lit`;
window.sessionStorage.removeItem(cache_key+'fetched');
} }
async function initConverse (settings) { async function initConverse (settings) {
clearStores(); clearStores();
await clearIndexedDB(); await clearIndexedDB();
......
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