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 @@
'nick': ' some1'
});
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);
expect(view.el.querySelector('.chatbox-title__text .fa-bookmark')).toBe(null);
await u.waitUntil(() => view.el.querySelector('.chatbox-title__text .fa-bookmark') === null);
done();
}));
......@@ -253,12 +253,12 @@
expect(_converse.bookmarks.length).toBe(1);
await u.waitUntil(() => _converse.chatboxes.length >= 1);
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();
const bookmark_icon = view.el.querySelector('.toggle-bookmark');
bookmark_icon.click();
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);
// Check that an IQ stanza is sent out, containing no
......
......@@ -611,6 +611,8 @@
await u.waitUntil(() => sent_stanzas.filter(iq => sizzle('presence history', iq).length).pop());
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
* know about them because we receive their presences before we
* receive our own.
......@@ -646,8 +648,8 @@
}).up()
.c('status', {code: '110'});
_converse.connection._dataRecv(test_utils.createRequest(presence));
expect(sizzle('div.chat-info:first', view.content).pop().textContent.trim())
.toBe("some1 has entered the groupchat");
const text = await u.waitUntil(() => sizzle('div.chat-info:first', view.content).pop()?.textContent);
expect(text.trim()).toBe("some1 has entered the groupchat");
await room_creation_promise;
await u.waitUntil(() => (view.model.session.get('connection_status') === converse.ROOMSTATUS.ENTERED));
......@@ -664,7 +666,7 @@
'role': 'participant'
});
_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())
.toBe("newguy has entered the groupchat");
......@@ -2166,7 +2168,8 @@
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(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(
`<message xmlns="jabber:client" to="jc@opkode.com/_converse.js-60429116" type="groupchat" from="jdev@conference.jabber.org/ralphm">
......@@ -2188,7 +2191,7 @@
</message>`);
_converse.connection._dataRecv(test_utils.createRequest(stanza));
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");
done();
}));
......
......@@ -36,9 +36,9 @@ converse.plugins.add('converse-bookmark-views', {
// plugin architecture they will replace existing methods on the
// relevant objects or classes.
ChatRoomView: {
getHeadingButtons () {
async getHeadingButtons () {
const { _converse } = this.__super__;
const buttons = this.__super__.getHeadingButtons.call(this);
const buttons = await this.__super__.getHeadingButtons.call(this);
if (_converse.allow_bookmarks) {
const supported = _converse.checkBookmarksSupport();
const bookmarked = this.model.get('bookmarked');
......
......@@ -139,9 +139,9 @@ converse.plugins.add('converse-minimize', {
return result;
},
getHeadingButtons () {
async getHeadingButtons () {
const { _converse } = this.__super__;
const buttons = this.__super__.getHeadingButtons.call(this);
const buttons = await this.__super__.getHeadingButtons.call(this);
const data = {
'a_class': 'toggle-chatbox-button',
'handler': ev => this.minimize(ev),
......
......@@ -725,7 +725,7 @@ converse.plugins.add('converse-muc-views', {
this.onMouseMove = this.onMouseMove.bind(this);
this.onMouseUp = this.onMouseUp.bind(this);
this.render();
await this.render();
this.createSidebarView();
await this.updateAfterMessagesFetched();
this.onConnectionStatusChanged();
......@@ -739,13 +739,13 @@ converse.plugins.add('converse-muc-views', {
api.trigger('chatRoomViewInitialized', this);
},
render () {
async render () {
this.el.setAttribute('id', this.model.get('box_id'));
render(tpl_chatroom({
'muc_show_logs_before_join': _converse.muc_show_logs_before_join,
'show_send_button': _converse.show_send_button
}), this.el);
this.renderHeading();
await this.renderHeading();
this.renderBottomPanel();
this.content = this.el.querySelector('.chat-content');
this.msgs_container = this.el.querySelector('.chat-content__messages');
......@@ -802,8 +802,9 @@ converse.plugins.add('converse-muc-views', {
* @method _converse.ChatRoomView#renderHeading
* @param { _converse.ChatRoom } [item]
*/
renderHeading () {
render(this.generateHeadingTemplate(), this.el.querySelector('.chat-head-chatroom'));
async renderHeading () {
const tpl = await this.generateHeadingTemplate();
render(tpl, this.el.querySelector('.chat-head-chatroom'));
},
......@@ -1156,7 +1157,7 @@ converse.plugins.add('converse-muc-views', {
}
},
getHeadingButtons () {
async getHeadingButtons () {
const buttons = [{
'i18n_text': __('Details'),
'i18n_title': __('Show more information about this groupchat'),
......@@ -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');
if (subject && subject.text) {
buttons.push({
'i18n_text': this.model.get('subject_hidden') ? __('Show topic') : __('Hide topic'),
'i18n_title': this.model.get('subject_hidden') ?
'i18n_text': subject_hidden ? __('Show topic') : __('Hide topic'),
'i18n_title': subject_hidden ?
__('Show the topic message in the heading') :
__('Hide the topic in the heading'),
'handler': ev => this.toggleTopic(ev),
......@@ -1249,8 +1253,8 @@ converse.plugins.add('converse-muc-views', {
* @private
* @method _converse.ChatRoomView#generateHeadingTemplate
*/
generateHeadingTemplate () {
const heading_btns = this.getHeadingButtons();
async generateHeadingTemplate () {
const heading_btns = await this.getHeadingButtons();
const standalone_btns = heading_btns.filter(b => b.standalone);
const dropdown_btns = heading_btns.filter(b => !b.standalone);
return tpl_chatroom_head(
......@@ -1262,11 +1266,16 @@ converse.plugins.add('converse-muc-views', {
}));
},
toggleTopic () {
this.model.save('subject_hidden', !this.model.get('subject_hidden'));
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]);
}
},
showInviteModal (ev) {
ev.preventDefault();
if (this.muc_invite_modal === undefined) {
......@@ -1950,15 +1959,16 @@ converse.plugins.add('converse-muc-views', {
}
},
showJoinNotification (occupant) {
async showJoinNotification (occupant) {
if (!_converse.muc_show_join_leave ||
this.model.session.get('connection_status') !== converse.ROOMSTATUS.ENTERED) {
return;
}
const nick = occupant.get('nick'),
stat = _converse.muc_show_join_leave_status ? occupant.get('status') : null,
prev_info_el = this.getPreviousJoinOrLeaveNotification(this.msgs_container.lastElementChild, nick),
data = prev_info_el?.dataset || {};
await api.waitUntil('chatRoomViewInitialized');
const nick = occupant.get('nick');
const stat = _converse.muc_show_join_leave_status ? occupant.get('status') : null;
const prev_info_el = this.getPreviousJoinOrLeaveNotification(this.msgs_container.lastElementChild, nick);
const data = prev_info_el?.dataset || {};
if (data.leave === nick) {
let message;
......@@ -2004,12 +2014,13 @@ converse.plugins.add('converse-muc-views', {
this.scrollDown();
},
showLeaveNotification (occupant) {
if (!_converse.muc_show_join_leave ||
async showLeaveNotification (occupant) {
if (!api.settings.get('muc_show_join_leave') ||
occupant.get('states').includes('303') ||
occupant.get('states').includes('307')) {
return;
}
await api.waitUntil('chatRoomViewInitialized');
const nick = occupant.get('nick'),
stat = _converse.muc_show_join_leave_status ? occupant.get('status') : null,
prev_info_el = this.getPreviousJoinOrLeaveNotification(this.msgs_container.lastElementChild, nick),
......
......@@ -532,12 +532,14 @@ const api = _converse.api = {
/**
* Get the value of a particular user setting.
* @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.
* @example _converse.api.user.settings.get("foo");
*/
async get (key) {
async get (key, fallback) {
await initUserSettings();
return user_settings.get(key);
return user_settings.get(key) === undefined ? fallback : user_settings.get(key);
},
/**
......
......@@ -251,9 +251,10 @@
[localStorage, sessionStorage].forEach(
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) {
clearStores();
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