MUC: Add test for showing cached messages before entering

This commit is contained in:
JC Brand 2021-02-02 15:11:28 +01:00
parent a294827211
commit 5feaab9a95
4 changed files with 42 additions and 4 deletions

View File

@ -358,6 +358,45 @@ describe("Groupchats", function () {
describe("A Groupchat", function () { describe("A Groupchat", function () {
it("Can be configured to show cached messages before being joined",
mock.initConverse(['discoInitialized'],
{
'muc_show_logs_before_join': true,
'archived_messages_page_size': 2,
'muc_nickname_from_jid': false,
'muc_clear_messages_on_leave': false,
}, async function (done, _converse) {
const { api } = _converse;
const muc_jid = 'orchard@chat.shakespeare.lit';
const nick = 'romeo';
api.rooms.open(muc_jid);
await mock.getRoomFeatures(_converse, muc_jid);
await mock.waitForReservedNick(_converse, muc_jid);
const view = _converse.chatboxviews.get(muc_jid);
await view.model.messages.fetched;
view.model.messages.create({
'type': 'groupchat',
'to': muc_jid,
'from': `${_converse.bare_jid}/orchard`,
'body': 'Hello world',
'message': 'Hello world',
'time': '2021-02-02T12:00:00Z'
});
expect(view.model.session.get('connection_status')).toBe(converse.ROOMSTATUS.NICKNAME_REQUIRED);
expect(view.el.querySelectorAll('converse-chat-message').length).toBe(1);
view.el.querySelector('[name="nick"]').value = nick;
view.el.querySelector('.muc-nickname-form input[type="submit"]').click();
_converse.connection.IQ_stanzas = [];
await mock.getRoomFeatures(_converse, muc_jid);
await u.waitUntil(() => view.model.session.get('connection_status') === converse.ROOMSTATUS.CONNECTING);
await mock.receiveOwnMUCPresence(_converse, muc_jid, nick);
return done();
}));
it("maintains its state across reloads", it("maintains its state across reloads",
mock.initConverse( mock.initConverse(
['rosterGroupsFetched'], { ['rosterGroupsFetched'], {

View File

@ -30,11 +30,10 @@ converse.plugins.add('converse-mam', {
}); });
Object.assign(api, mam_api); Object.assign(api, mam_api);
// This is mainly done to aid with tests // This is mainly done to aid with tests
Object.assign(_converse, { onMAMError, onMAMPreferences, handleMAMResult }); Object.assign(_converse, { onMAMError, onMAMPreferences, handleMAMResult });
/************************ BEGIN Event Handlers ************************/ /************************ Event Handlers ************************/
api.listen.on('addClientFeatures', () => api.disco.own.features.add(NS.MAM)); api.listen.on('addClientFeatures', () => api.disco.own.features.add(NS.MAM));
api.listen.on('serviceDiscovered', getMAMPrefsFromFeature); api.listen.on('serviceDiscovered', getMAMPrefsFromFeature);
api.listen.on('chatRoomViewInitialized', view => { api.listen.on('chatRoomViewInitialized', view => {
@ -64,6 +63,5 @@ converse.plugins.add('converse-mam', {
fetchNewestMessages(chat); fetchNewestMessages(chat);
} }
}); });
/************************ END Event Handlers **************************/
} }
}); });

View File

@ -2246,7 +2246,6 @@ const ChatRoomMixin = {
if (error?.getAttribute('type') === 'wait' && error?.querySelector('resource-constraint')) { if (error?.getAttribute('type') === 'wait' && error?.querySelector('resource-constraint')) {
// If we get a <resource-constraint> error, we assume it's in context of XEP-0437 RAI. // If we get a <resource-constraint> error, we assume it's in context of XEP-0437 RAI.
// We remove this MUC's host from the list of enabled domains and rejoin the MUC. // We remove this MUC's host from the list of enabled domains and rejoin the MUC.
const muc_domain = Strophe.getDomainFromJid(this.get('jid'));
if (this.session.get('connection_status') === converse.ROOMSTATUS.DISCONNECTED) { if (this.session.get('connection_status') === converse.ROOMSTATUS.DISCONNECTED) {
this.rejoin(); this.rejoin();
} }

View File

@ -1121,6 +1121,8 @@ const ChatRoomViewMixin = {
renderNicknameForm () { renderNicknameForm () {
const tpl_result = tpl_muc_nickname_form(this.model.toJSON()); const tpl_result = tpl_muc_nickname_form(this.model.toJSON());
if (api.settings.get('muc_show_logs_before_join')) { if (api.settings.get('muc_show_logs_before_join')) {
this.hideSpinner();
u.showElement(this.el.querySelector('.chat-area'));
const container = this.el.querySelector('.muc-bottom-panel'); const container = this.el.querySelector('.muc-bottom-panel');
render(tpl_result, container); render(tpl_result, container);
u.addClass('muc-bottom-panel--nickname', container); u.addClass('muc-bottom-panel--nickname', container);