Commit 6b09416b authored by Weblate's avatar Weblate

Merge remote-tracking branch 'origin/master'

parents d00412e1 3b8c2d1b
......@@ -1755,31 +1755,42 @@
test_utils.openContactsPanel(_converse);
test_utils.waitUntil(function () {
return _converse.rosterview.$el.find('dt').length;
}, 300).then(function () {
}, 500).then(function () {
// Make the timeouts shorter so that we can test
_converse.TIMEOUTS.PAUSED = 200;
_converse.TIMEOUTS.INACTIVE = 200;
contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
test_utils.openChatBoxFor(_converse, contact_jid);
view = _converse.chatboxviews.get(contact_jid);
return test_utils.waitUntil(function () {
return view.model.get('chat_state') === 'active';
}, 500);
}).then(function () {
console.log('chat_state set to active');
view = _converse.chatboxviews.get(contact_jid);
expect(view.model.get('chat_state')).toBe('active');
view.keyPressed({
target: view.$el.find('textarea.chat-textarea'),
keyCode: 1
});
return test_utils.waitUntil(function () {
return view.model.get('chat_state') === 'composing';
}, 500);
}).then(function () {
console.log('chat_state set to composing');
view = _converse.chatboxviews.get(contact_jid);
expect(view.model.get('chat_state')).toBe('composing');
spyOn(_converse.connection, 'send');
return test_utils.waitUntil(function () {
if (view.model.get('chat_state') === 'paused') {
return true;
}
return false;
}, 300);
return view.model.get('chat_state') === 'paused';
}, 500);
}).then(function () {
console.log('chat_state set to paused');
return test_utils.waitUntil(function () {
return view.model.get('chat_state') === 'inactive';
}, 300);
}, 500);
}).then(function () {
console.log('chat_state set to inactive');
expect(_converse.connection.send).toHaveBeenCalled();
var calls = _.filter(_converse.connection.send.calls.all(), function (call) {
return call.args[0] instanceof Strophe.Builder;
......@@ -1799,7 +1810,7 @@
expect($stanza.children().get(1).tagName).toBe('no-store');
expect($stanza.children().get(2).tagName).toBe('no-permanent-store');
done();
});
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
}));
it("is sent when the user a minimizes a chat box",
......
......@@ -3,20 +3,42 @@
} (this, function ($, jasmine, mock, converse, test_utils) {
var Strophe = converse.env.Strophe;
var $iq = converse.env.$iq;
var _ = converse.env._;
describe("The Registration Panel", function () {
it("is not available unless allow_registration=true", mock.initConverse(function (_converse) {
it("is not available unless allow_registration=true",
mock.initConverseWithPromises(
null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false,
allow_registration: false },
function (done, _converse) {
test_utils.waitUntil(function () {
return _converse.chatboxviews.get('controlbox');
}, 300)
.then(function () {
test_utils.openControlBox();
var cbview = _converse.chatboxviews.get('controlbox');
expect(cbview.$('#controlbox-tabs li').length).toBe(1);
expect(cbview.$('#controlbox-tabs li').text().trim()).toBe("Sign in");
}, { auto_login: false,
allow_registration: false,
done();
});
}));
it("can be opened by clicking on the registration tab", mock.initConverse(function (_converse) {
it("can be opened by clicking on the registration tab",
mock.initConverseWithPromises(
null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false,
allow_registration: true },
function (done, _converse) {
test_utils.waitUntil(function () {
return _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel');
}, 300)
.then(function () {
var cbview = _converse.chatboxviews.get('controlbox');
test_utils.openControlBox();
var $tabs = cbview.$('#controlbox-tabs');
......@@ -32,12 +54,22 @@
expect($login.is(':visible')).toBe(false);
expect($registration.is(':visible')).toBe(true);
expect(cbview.switchTab).toHaveBeenCalled();
}, { auto_login: false,
allow_registration: true,
done();
});
}));
it("allows the user to choose an XMPP provider's domain", mock.initConverse(function (_converse) {
it("allows the user to choose an XMPP provider's domain",
mock.initConverseWithPromises(
null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false,
allow_registration: true },
function (done, _converse) {
test_utils.waitUntil(function () {
return _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel');
}, 300)
.then(function () {
var cbview = _converse.chatboxviews.get('controlbox');
var registerview = cbview.registerpanel;
spyOn(registerview, 'onProviderChosen').and.callThrough();
......@@ -59,11 +91,22 @@
$form.find('input[type=submit]').click();
expect(registerview.onProviderChosen).toHaveBeenCalled();
expect(_converse.connection.connect).toHaveBeenCalled();
}, { auto_login: false,
allow_registration: true,
}));
done();
});
}));
it("will render a registration form as received from the XMPP provider",
mock.initConverseWithPromises(
null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false,
allow_registration: true },
function (done, _converse) {
test_utils.waitUntil(function () {
return _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel');
}, 300)
.then(function () {
it("will render a registration form as received from the XMPP provider", mock.initConverse(function (_converse) {
var cbview = _converse.chatboxviews.get('controlbox');
cbview.$('#controlbox-tabs').find('li').last().find('a').click(); // Click the Register tab
var registerview = _converse.chatboxviews.get('controlbox').registerpanel;
......@@ -107,14 +150,25 @@
expect(registerview.$('input').length).toBe(5);
expect(registerview.$('input[type=submit]').length).toBe(1);
expect(registerview.$('input[type=button]').length).toBe(1);
}, { auto_login: false,
allow_registration: true,
}));
done();
});
}));
it("will set form_type to legacy and submit it as legacy",
mock.initConverseWithPromises(
null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false,
allow_registration: true },
function (done, _converse) {
test_utils.waitUntil(function () {
return _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel');
}, 300)
.then(function () {
it("will set form_type to legacy and submit it as legacy", mock.initConverse(function (_converse) {
var cbview = _converse.chatboxviews.get('controlbox');
cbview.$('#controlbox-tabs').find('li').last().find('a').click(); // Click the Register tab
var registerview = _converse.chatboxviews.get('controlbox').registerpanel;
var registerview = cbview.registerpanel;
spyOn(registerview, 'onProviderChosen').and.callThrough();
spyOn(registerview, 'getRegistrationFields').and.callThrough();
spyOn(registerview, 'onRegistrationFields').and.callThrough();
......@@ -156,11 +210,22 @@
var $stanza = $(_converse.connection.send.calls.argsFor(0)[0].tree());
expect($stanza.children('query').children().length).toBe(3);
expect($stanza.children('query').children()[0].tagName).toBe('username');
}, { auto_login: false,
allow_registration: true,
}));
done();
});
}));
it("will set form_type to xform and submit it as xform",
mock.initConverseWithPromises(
null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false,
allow_registration: true },
function (done, _converse) {
test_utils.waitUntil(function () {
return _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel');
}, 300)
.then(function () {
it("will set form_type to xform and submit it as xform", mock.initConverse(function (_converse) {
var cbview = _converse.chatboxviews.get('controlbox');
cbview.$('#controlbox-tabs').find('li').last().find('a').click(); // Click the Register tab
var registerview = _converse.chatboxviews.get('controlbox').registerpanel;
......@@ -208,8 +273,8 @@
expect($stanza.children('query').children().length).toBe(1);
expect($stanza.children('query').children().children().length).toBe(3);
expect($stanza.children('query').children().children()[0].tagName).toBe('field');
}, { auto_login: false,
allow_registration: true,
}));
done();
});
}));
});
}));
......@@ -53,6 +53,7 @@ require.config({
"inverse": "src/inverse",
"converse-bookmarks": "src/converse-bookmarks",
"converse-chatboxes": "src/converse-chatboxes",
"converse-chatview": "src/converse-chatview",
"converse-controlbox": "src/converse-controlbox",
"converse-core": "src/converse-core",
......
This diff is collapsed.
......@@ -10,6 +10,7 @@
define([
"jquery.noconflict",
"converse-core",
"converse-chatboxes",
"emojione",
"xss",
"tpl!chatbox",
......@@ -25,6 +26,7 @@
}(this, function (
$,
converse,
dummy,
emojione,
xss,
tpl_chatbox,
......@@ -706,10 +708,10 @@
}
if (state === _converse.COMPOSING) {
this.chat_state_timeout = window.setTimeout(
this.setChatState.bind(this), _converse.TIMEOUTS.PAUSED, _converse.PAUSED);
this.setChatState.bind(this), _converse.TIMEOUTS.PAUSED, _converse.PAUSED);
} else if (state === _converse.PAUSED) {
this.chat_state_timeout = window.setTimeout(
this.setChatState.bind(this), _converse.TIMEOUTS.INACTIVE, _converse.INACTIVE);
this.setChatState.bind(this), _converse.TIMEOUTS.INACTIVE, _converse.INACTIVE);
}
if (!no_save && this.model.get('chat_state') !== state) {
this.model.set('chat_state', state);
......
......@@ -48,7 +48,7 @@
const USERS_PANEL_ID = 'users';
const CHATBOX_TYPE = 'chatbox';
const { Strophe, Backbone, utils, _, moment } = converse.env;
const { Strophe, Backbone, Promise, utils, _, moment } = converse.env;
converse.plugins.add('converse-controlbox', {
......@@ -60,18 +60,6 @@
//
// New functions which don't exist yet can also be added.
initChatBoxes () {
this.__super__.initChatBoxes.apply(this, arguments);
this.controlboxtoggle = new this.ControlBoxToggle();
},
initConnection () {
this.__super__.initConnection.apply(this, arguments);
if (this.connection) {
this.addControlBox();
}
},
_tearDown () {
this.__super__._tearDown.apply(this, arguments);
if (this.rosterview) {
......@@ -102,8 +90,8 @@
},
onChatBoxesFetched (collection, resp) {
const { _converse } = this.__super__;
this.__super__.onChatBoxesFetched.apply(this, arguments);
const { _converse } = this.__super__;
if (!_.includes(_.map(collection, 'id'), 'controlbox')) {
_converse.addControlBox();
}
......@@ -159,7 +147,6 @@
}
},
ChatBox: {
initialize () {
if (this.get('id') === 'controlbox') {
......@@ -170,7 +157,6 @@
},
},
ChatBoxView: {
insertIntoDOM () {
const { _converse } = this.__super__;
......@@ -199,14 +185,14 @@
const LABEL_CONTACTS = __('Contacts');
_converse.addControlBox = () =>
_converse.addControlBox = () => {
_converse.chatboxes.add({
id: 'controlbox',
box_id: 'controlbox',
type: 'controlbox',
closed: !_converse.show_controlbox_by_default
})
;
};
_converse.ControlBoxView = _converse.ChatBoxView.extend({
tagName: 'div',
......@@ -218,6 +204,7 @@
},
initialize () {
_converse.controlboxtoggle = new _converse.ControlBoxToggle();
this.$el.insertAfter(_converse.controlboxtoggle.$el);
this.model.on('change:connected', this.onConnected, this);
this.model.on('destroy', this.hide, this);
......@@ -226,7 +213,9 @@
this.model.on('change:closed', this.ensureClosedState, this);
this.render();
if (this.model.get('connected')) {
this.insertRoster();
_converse.api.waitUntil('rosterViewInitialized')
.then(this.insertRoster.bind(this))
.catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
}
},
......@@ -259,7 +248,10 @@
onConnected () {
if (this.model.get('connected')) {
this.render().insertRoster();
this.render();
_converse.api.waitUntil('rosterViewInitialized')
.then(this.insertRoster.bind(this))
.catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
this.model.save();
}
},
......@@ -735,15 +727,15 @@
},
initialize () {
_converse.chatboxviews.$el.prepend(this.render());
_converse.chatboxviews.$el.prepend(this.render().el);
this.updateOnlineCount();
const that = this;
_converse.on('initialized', function () {
_converse.api.waitUntil('initialized').then(() => {
_converse.roster.on("add", that.updateOnlineCount, that);
_converse.roster.on('change', that.updateOnlineCount, that);
_converse.roster.on("destroy", that.updateOnlineCount, that);
_converse.roster.on("remove", that.updateOnlineCount, that);
});
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
},
render () {
......@@ -751,11 +743,10 @@
// the ControlBox or the Toggle must be shown. This prevents
// artifacts (i.e. on page load the toggle is shown only to then
// seconds later be hidden in favor of the control box).
return this.$el.html(
tpl_controlbox_toggle({
'label_toggle': __('Toggle chat')
})
);
this.el.innerHTML = tpl_controlbox_toggle({
'label_toggle': __('Toggle chat')
})
return this;
},
updateOnlineCount: _.debounce(function () {
......@@ -805,6 +796,12 @@
}
});
Promise.all([
_converse.api.waitUntil('connectionInitialized'),
_converse.api.waitUntil('chatBoxesInitialized')
]).then(_converse.addControlBox)
.catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
const disconnect = function () {
/* Upon disconnection, set connected to `false`, so that if
* we reconnect,
......
This diff is collapsed.
......@@ -13,8 +13,8 @@
"tpl!toggle_chats",
"tpl!trimmed_chat",
"tpl!chats_panel",
"converse-controlbox",
"converse-chatview",
"converse-controlbox",
"converse-muc"
], factory);
}(this, function (
......@@ -27,7 +27,7 @@
) {
"use strict";
const { _ , utils, Backbone, b64_sha1, moment } = converse.env;
const { _ , utils, Backbone, Promise, Strophe, b64_sha1, moment } = converse.env;
converse.plugins.add('converse-minimize', {
overrides: {
......@@ -37,15 +37,6 @@
//
// New functions which don't exist yet can also be added.
initChatBoxes () {
const { _converse } = this.__super__;
const result = this.__super__.initChatBoxes.apply(this, arguments);
_converse.minimized_chats = new _converse.MinimizedChats({
model: _converse.chatboxes
});
return result;
},
registerGlobalEventHandlers () {
const { _converse } = this.__super__;
$(window).on("resize", _.debounce(function (ev) {
......@@ -251,29 +242,31 @@
// fullscreen. In this case we don't trim.
return;
}
const $minimized = _converse.minimized_chats.$el,
minimized_width = _.includes(this.model.pluck('minimized'), true) ? $minimized.outerWidth(true) : 0,
new_id = newchat ? newchat.model.get('id') : null;
const boxes_width = _.reduce(
this.xget(new_id),
(memo, view) => memo + this.getChatBoxWidth(view),
newchat ? newchat.$el.outerWidth(true) : 0);
if ((minimized_width + boxes_width) > $('body').outerWidth(true)) {
const oldest_chat = this.getOldestMaximizedChat([new_id]);
if (oldest_chat) {
// We hide the chat immediately, because waiting
// for the event to fire (and letting the
// ChatBoxView hide it then) causes race
// conditions.
const view = this.get(oldest_chat.get('id'));
if (view) {
view.hide();
_converse.api.waitUntil('chatBoxesInitialized').then(() => {
const $minimized = _.get(_converse.minimized_chats, '$el'),
minimized_width = _.includes(this.model.pluck('minimized'), true) ? $minimized.outerWidth(true) : 0,
new_id = newchat ? newchat.model.get('id') : null;
const boxes_width = _.reduce(
this.xget(new_id),
(memo, view) => memo + this.getChatBoxWidth(view),
newchat ? newchat.$el.outerWidth(true) : 0);
if ((minimized_width + boxes_width) > $('body').outerWidth(true)) {
const oldest_chat = this.getOldestMaximizedChat([new_id]);
if (oldest_chat) {
// We hide the chat immediately, because waiting
// for the event to fire (and letting the
// ChatBoxView hide it then) causes race
// conditions.
const view = this.get(oldest_chat.get('id'));
if (view) {
view.hide();
}
oldest_chat.minimize();
}
oldest_chat.minimize();
}
}
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
},
getOldestMaximizedChat (exclude_ids) {
......@@ -312,6 +305,8 @@
no_trimming: false, // Set to true for phantomjs tests (where browser apparently has no width)
});
_converse.api.promises.add('minimizedChatsInitialized');
_converse.MinimizedChatBoxView = Backbone.View.extend({
tagName: 'div',
className: 'chat-head',
......@@ -492,7 +487,17 @@
}
});
const renderMinimizeButton = function (view) {
Promise.all([
_converse.api.waitUntil('connectionInitialized'),
_converse.api.waitUntil('chatBoxesInitialized')
]).then(() => {
_converse.minimized_chats = new _converse.MinimizedChats({
model: _converse.chatboxes
});
_converse.emit('minimizedChatsInitialized');
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
_converse.on('chatBoxOpened', function renderMinimizeButton (view) {
// Inserts a "minimize" button in the chatview's header
const $el = view.$el.find('.toggle-chatbox-button');
const $new_el = tpl_chatbox_minimize(
......@@ -503,8 +508,7 @@
} else {
view.$el.find('.close-chatbox-button').after($new_el);
}
};
_converse.on('chatBoxOpened', renderMinimizeButton);
});
_converse.on('controlBoxOpened', function (chatbox) {
// Wrapped in anon method because at scan time, chatboxviews
......
......@@ -14,7 +14,8 @@
"tpl!requesting_contact",
"tpl!roster",
"tpl!roster_filter",
"tpl!roster_item"
"tpl!roster_item",
"converse-chatboxes"
], factory);
}(this, function (
$,
......@@ -75,6 +76,7 @@
allow_contact_removal: true,
show_toolbar: true,
});
_converse.api.promises.add('rosterViewInitialized');
const STATUSES = {
'dnd': __('This contact is busy'),
......@@ -949,6 +951,7 @@
'model': _converse.rostergroups
});
_converse.rosterview.render();
_converse.emit('rosterViewInitialized');
};
_converse.api.listen.on('rosterInitialized', initRoster);
_converse.api.listen.on('rosterReadyAfterReconnection', initRoster);
......
......@@ -131,28 +131,32 @@
});
const updateVCardForChatBox = function (chatbox) {
if (!_converse.use_vcards) { return; }
const jid = chatbox.model.get('jid'),
contact = _converse.roster.get(jid);
if ((contact) && (!contact.get('vcard_updated'))) {
_converse.getVCard(
jid,
function (iq, jid, fullname, image, image_type, url) {
chatbox.model.save({
'fullname' : fullname || jid,
'url': url,
'image_type': image_type,
'image': image
});
},
function () {
_converse.log(
"updateVCardForChatBox: Error occured while fetching vcard",
Strophe.LogLevel.ERROR
);
}
);
if (!_converse.use_vcards || chatbox.model.get('type') === 'headline') {
return;
}
_converse.api.waitUntil('rosterInitialized').then(() => {
const jid = chatbox.model.get('jid'),
contact = _converse.roster.get(jid);
if ((contact) && (!contact.get('vcard_updated'))) {
_converse.getVCard(
jid,
function (iq, jid, fullname, image, image_type, url) {
chatbox.model.save({
'fullname' : fullname || jid,
'url': url,
'image_type': image_type,
'image': image
});
},
function () {
_converse.log(
"updateVCardForChatBox: Error occured while fetching vcard",
Strophe.LogLevel.ERROR
);
}
);
}
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
};
_converse.on('chatBoxInitialized', updateVCardForChatBox);
......
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