Commit 531ebf33 authored by JC Brand's avatar JC Brand

Properly test and fix show/hide of MUC topic

parent 10da630d
......@@ -18,6 +18,7 @@ Soon we'll deprecate the latter, so prepare now.
- #1826: A user can now add himself as a contact
- #1839: Headline messages are shown in controlbox
- #1896: Don't send receipts for messages fetched from the archive
- #1937: Editing a message removes the mentions highlight
- Allow ignoring of bootstrap modules at build using environment variable. For xample: `export BOOTSTRAP_IGNORE_MODULES="Modal,Dropdown" && make dist`
- Bugfix. Handle stanza that clears the MUC subject
- New config option [modtools_disable_assign](https://conversejs.org/docs/html/configuration.html#modtools-disable-assign)
......@@ -26,7 +27,6 @@ Soon we'll deprecate the latter, so prepare now.
- Start using [lit-html](https://lit-html.polymer-project.org/) instead of lodash for templating.
- [muc_fetch_members](https://conversejs.org/docs/html/configuration.html#muc-fetch-members) now also accepts an array of affiliations to fetch.
- Remove the configuration setting `muc_show_join_leave_status`. The optional status message is no longer shown at all.
- #1937: Editing a message removes the mentions highlight
## 6.0.0 (2020-01-09)
......
......@@ -57,10 +57,10 @@
font-size: var(--font-size-small);
margin: 0;
overflow: hidden;
padding: 0.5rem 1rem 1rem 1rem;
padding: 0.5rem 1rem 0.5rem 1rem;
text-overflow: ellipsis;
white-space: nowrap;
width: 100%;
max-height: 5em;
}
.chatbox-title {
......
......@@ -37,7 +37,7 @@
spyOn(view, 'renderBookmarkForm').and.callThrough();
spyOn(view, 'closeForm').and.callThrough();
await u.waitUntil(() => view.el.querySelector('.toggle-bookmark') !== null);
let toggle = view.el.querySelector('.toggle-bookmark');
const toggle = view.el.querySelector('.toggle-bookmark');
expect(toggle.title).toBe('Bookmark this groupchat');
toggle.click();
expect(view.renderBookmarkForm).toHaveBeenCalled();
......@@ -130,10 +130,9 @@
});
_converse.connection._dataRecv(test_utils.createRequest(stanza));
await u.waitUntil(() => view.model.get('bookmarked'));
toggle = await u.waitUntil(() => view.el.querySelector('.toggle-bookmark'));
expect(view.model.get('bookmarked')).toBeTruthy();
expect(toggle.title).toBe('Unbookmark this groupchat');
expect(u.hasClass('on-button', toggle), true);
await u.waitUntil(() => view.el.querySelector('.toggle-bookmark')?.title === 'Unbookmark this groupchat');
expect(u.hasClass('on-button', view.el.querySelector('.toggle-bookmark')), true);
// We ignore this IQ stanza... (unless it's an error stanza), so
// nothing to test for here.
done();
......
This diff is collapsed.
......@@ -236,8 +236,7 @@
'author': 'ralphm'
}});
expect(sizzle('.chat-event:last').pop().textContent.trim()).toBe('Topic set by ralphm');
const desc = await u.waitUntil(() => view.el.querySelector('.chat-head__desc'));
expect(desc.textContent.trim()).toBe(subject);
await u.waitUntil(() => view.el.querySelector('.chat-head__desc')?.textContent.trim() === subject);
done();
}));
});
......
......@@ -8,7 +8,6 @@ import converse from "@converse/headless/converse-core";
const u = converse.env.utils;
export class Dropdown extends CustomElement {
static get properties () {
......
......@@ -36,9 +36,9 @@ converse.plugins.add('converse-bookmark-views', {
// plugin architecture they will replace existing methods on the
// relevant objects or classes.
ChatRoomView: {
async getHeadingButtons () {
getHeadingButtons () {
const { _converse } = this.__super__;
const buttons = await this.__super__.getHeadingButtons.call(this);
const buttons = this.__super__.getHeadingButtons.apply(this, arguments);
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;
},
async getHeadingButtons () {
getHeadingButtons () {
const { _converse } = this.__super__;
const buttons = await this.__super__.getHeadingButtons.call(this);
const buttons = this.__super__.getHeadingButtons.apply(this, arguments);
const data = {
'a_class': 'toggle-chatbox-button',
'handler': ev => this.minimize(ev),
......
......@@ -8,7 +8,7 @@ import "converse-modal";
import "@converse/headless/utils/muc";
import { Model } from 'skeletor.js/src/model.js';
import { View } from 'skeletor.js/src/view.js';
import { head, isString, isUndefined } from "lodash";
import { debounce, head, isString, isUndefined } from "lodash";
import { BootstrapModal } from "./converse-modal.js";
import { render } from "lit-html";
import { __ } from '@converse/headless/i18n';
......@@ -703,7 +703,10 @@ converse.plugins.add('converse-muc-views', {
this.listenTo(this.model.notifications, 'change', this.renderNotifications);
this.listenTo(this.model.session, 'change:connection_status', this.onConnectionStatusChanged);
this.listenTo(this.model, 'change', this.renderHeading);
const user_settings = _converse.api.user.settings.getModel();
this.listenTo(user_settings, 'change:mucs_with_hidden_subject', this.renderHeading);
this.listenTo(this.model, 'change', debounce(() => this.renderHeading(), 250));
this.listenTo(this.model, 'change:hidden_occupants', this.updateOccupantsToggle);
this.listenTo(this.model, 'change:subject', this.setChatRoomSubject);
this.listenTo(this.model, 'configurationNeeded', this.getAndRenderConfigurationForm);
......@@ -1171,7 +1174,7 @@ converse.plugins.add('converse-muc-views', {
}
},
async getHeadingButtons () {
getHeadingButtons (subject_hidden) {
const buttons = [{
'i18n_text': __('Details'),
'i18n_title': __('Show more information about this groupchat'),
......@@ -1227,9 +1230,6 @@ 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({
......@@ -1238,7 +1238,7 @@ converse.plugins.add('converse-muc-views', {
__('Show the topic message in the heading') :
__('Hide the topic in the heading'),
'handler': ev => this.toggleTopic(ev),
'a_class': '',
'a_class': 'hide-topic',
'icon_class': 'fa-minus-square',
'name': 'toggle-topic'
});
......@@ -1268,12 +1268,15 @@ converse.plugins.add('converse-muc-views', {
* @method _converse.ChatRoomView#generateHeadingTemplate
*/
async generateHeadingTemplate () {
const heading_btns = await this.getHeadingButtons();
const jids = await api.user.settings.get('mucs_with_hidden_subject', [])
const subject_hidden = jids.includes(this.model.get('jid'));
const heading_btns = this.getHeadingButtons(subject_hidden);
const standalone_btns = heading_btns.filter(b => b.standalone);
const dropdown_btns = heading_btns.filter(b => !b.standalone);
return tpl_chatroom_head(
Object.assign(this.model.toJSON(), {
_converse,
subject_hidden,
'dropdown_btns': dropdown_btns.map(b => this.getHeadingDropdownItem(b)),
'standalone_btns': standalone_btns.map(b => this.getHeadingStandaloneButton(b)),
'title': this.model.getDisplayName(),
......
......@@ -529,6 +529,16 @@ const api = _converse.api = {
* @memberOf _converse.api.user
*/
settings: {
/**
* Returns the user settings model. Useful when you want to listen for change events.
* @method _converse.api.user.settings.getModel
* @returns {Model}
* @example _converse.api.user.settings.getModel
*/
getModel () {
return user_settings;
},
/**
* Get the value of a particular user setting.
* @method _converse.api.user.settings.get
......@@ -558,8 +568,13 @@ const api = _converse.api = {
*/
async set (key, val) {
await initUserSettings();
const o = isObject(key) ? key : {key: val};
return user_settings.save(o, {'promise': true});
if (isObject(key)) {
return user_settings.save(key, {'promise': true});
} else {
const o = {};
o[key] = val;
return user_settings.save(o, {'promise': true});
}
}
}
},
......@@ -1086,6 +1101,10 @@ function clearSession () {
_converse.session.destroy();
delete _converse.session;
}
if (_converse.shouldClearCache()) {
const model = _converse.api.user.settings.getModel();
model.clear();
}
/**
* Synchronouse event triggered once the user session has been cleared,
* for example when the user has logged out or when Converse has
......
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