Commit 8bd968a0 authored by JC Brand's avatar JC Brand

Also use the VCard cache for the user's own status

parent 708b1dbe
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
var view; var view;
test_utils.createContacts(_converse, 'current'); test_utils.createContacts(_converse, 'current');
test_utils.waitUntilDiscoConfirmed(_converse, 'localhost', [], ['vcard-temp']) test_utils.waitUntilDiscoConfirmed(_converse, 'localhost', [], ['vcard-temp'])
.then(() => test_utils.waitUntil(() => _converse.xmppstatus.get('fullname')), 300) .then(() => test_utils.waitUntil(() => _converse.xmppstatus.vcard.get('fullname')), 300)
.then(function () { .then(function () {
test_utils.openControlBox(); test_utils.openControlBox();
expect(_converse.chatboxes.length).toEqual(1); expect(_converse.chatboxes.length).toEqual(1);
...@@ -753,7 +753,7 @@ ...@@ -753,7 +753,7 @@
test_utils.waitUntilDiscoConfirmed(_converse, 'localhost', [], ['vcard-temp']) test_utils.waitUntilDiscoConfirmed(_converse, 'localhost', [], ['vcard-temp'])
.then(function () { .then(function () {
return test_utils.waitUntil(function () { return test_utils.waitUntil(function () {
return _converse.xmppstatus.get('fullname'); return _converse.xmppstatus.vcard.get('fullname');
}, 300); }, 300);
}).then(function () { }).then(function () {
test_utils.createContacts(_converse, 'current'); test_utils.createContacts(_converse, 'current');
...@@ -783,7 +783,6 @@ ...@@ -783,7 +783,6 @@
// Check that the message was received and check the message parameters // Check that the message was received and check the message parameters
expect(chatbox.messages.length).toEqual(1); expect(chatbox.messages.length).toEqual(1);
var msg_obj = chatbox.messages.models[0]; var msg_obj = chatbox.messages.models[0];
expect(msg_obj.get('fullname')).toEqual(_converse.xmppstatus.get('fullname'));
expect(msg_obj.get('sender')).toEqual('me'); expect(msg_obj.get('sender')).toEqual('me');
expect(msg_obj.get('delayed')).toEqual(false); expect(msg_obj.get('delayed')).toEqual(false);
var $chat_content = $(chatboxview.el).find('.chat-content'); var $chat_content = $(chatboxview.el).find('.chat-content');
...@@ -902,7 +901,7 @@ ...@@ -902,7 +901,7 @@
test_utils.waitUntilDiscoConfirmed(_converse, 'localhost', [], ['vcard-temp']) test_utils.waitUntilDiscoConfirmed(_converse, 'localhost', [], ['vcard-temp'])
.then(function () { .then(function () {
return test_utils.waitUntil(function () { return test_utils.waitUntil(function () {
return _converse.xmppstatus.get('fullname'); return _converse.xmppstatus.vcard.get('fullname');
}, 300); }, 300);
}).then(function () { }).then(function () {
test_utils.createContacts(_converse, 'current'); test_utils.createContacts(_converse, 'current');
...@@ -932,7 +931,6 @@ ...@@ -932,7 +931,6 @@
// Check that the message was received and check the message parameters // Check that the message was received and check the message parameters
expect(chatbox.messages.length).toEqual(1); expect(chatbox.messages.length).toEqual(1);
var msg_obj = chatbox.messages.models[0]; var msg_obj = chatbox.messages.models[0];
expect(msg_obj.get('fullname')).toEqual(_converse.xmppstatus.get('fullname'));
expect(msg_obj.get('sender')).toEqual('me'); expect(msg_obj.get('sender')).toEqual('me');
expect(msg_obj.get('delayed')).toEqual(false); expect(msg_obj.get('delayed')).toEqual(false);
var $chat_content = $(chatboxview.el).find('.chat-content'); var $chat_content = $(chatboxview.el).find('.chat-content');
......
...@@ -851,9 +851,7 @@ ...@@ -851,9 +851,7 @@
test_utils.waitUntilDiscoConfirmed(_converse, 'localhost', [], ['vcard-temp']) test_utils.waitUntilDiscoConfirmed(_converse, 'localhost', [], ['vcard-temp'])
.then(function () { .then(function () {
return test_utils.waitUntil(function () { return test_utils.waitUntil(() => _converse.xmppstatus.vcard.get('fullname'))
return _converse.xmppstatus.get('fullname');
}, 300);
}).then(function () { }).then(function () {
test_utils.createContacts(_converse, 'current'); test_utils.createContacts(_converse, 'current');
return test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy'); return test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy');
......
...@@ -1137,7 +1137,7 @@ ...@@ -1137,7 +1137,7 @@
var msg_object = chatbox.messages.models[0]; var msg_object = chatbox.messages.models[0];
var msg_author = view.el.querySelector('.chat-content .chat-msg:last-child .chat-msg-author'); var msg_author = view.el.querySelector('.chat-content .chat-msg:last-child .chat-msg-author');
expect(msg_author.textContent).toBe('dummy@localhost'); expect(msg_author.textContent).toBe('Max Mustermann');
var msg_time = view.el.querySelector('.chat-content .chat-msg:last-child .chat-msg-time'); var msg_time = view.el.querySelector('.chat-content .chat-msg:last-child .chat-msg-time');
var time = moment(msg_object.get('time')).format(_converse.time_format); var time = moment(msg_object.get('time')).format(_converse.time_format);
......
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
test_utils.waitUntilDiscoConfirmed(_converse, 'localhost', [], ['vcard-temp']) test_utils.waitUntilDiscoConfirmed(_converse, 'localhost', [], ['vcard-temp'])
.then(function () { .then(function () {
return test_utils.waitUntil(function () { return test_utils.waitUntil(function () {
return _converse.xmppstatus.get('fullname'); return _converse.xmppstatus.vcard.get('fullname');
}, 300); }, 300);
}).then(function () { }).then(function () {
/* The process by which a user subscribes to a contact, including /* The process by which a user subscribes to a contact, including
......
...@@ -33,25 +33,23 @@ ...@@ -33,25 +33,23 @@
allow_registration: true }, allow_registration: true },
function (done, _converse) { function (done, _converse) {
test_utils.waitUntil(function () { test_utils.waitUntil(() => _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel'), 300)
return _.get(_converse.chatboxviews.get('controlbox'), 'registerpanel');
}, 300)
.then(function () { .then(function () {
var cbview = _converse.chatboxviews.get('controlbox'); var cbview = _converse.chatboxviews.get('controlbox');
test_utils.openControlBox(); test_utils.openControlBox();
var $panels = $(cbview.el.querySelector('.controlbox-panes')); var $panels = $(cbview.el.querySelector('.controlbox-panes'));
var $login = $panels.children().first(); var $login = $panels.children().first();
var $registration = $panels.children().last(); var $registration = $panels.children().last();
var register_link = cbview.el.querySelector('a.register-account'); var register_link = cbview.el.querySelector('a.register-account');
expect(register_link.textContent).toBe("Create an account"); expect(register_link.textContent).toBe("Create an account");
register_link.click(); register_link.click();
test_utils.waitUntil(function () { test_utils.waitUntil(function () {
return $registration.is(':visible'); return $registration.is(':visible');
}, 300).then(function () { }, 300).then(function () {
expect($login.is(':visible')).toBe(false); expect($login.is(':visible')).toBe(false);
done(); done();
}); });
}); });
})); }));
......
...@@ -155,7 +155,7 @@ ...@@ -155,7 +155,7 @@
expect(body_el.textContent).toBe('This is the spoiler'); expect(body_el.textContent).toBe('This is the spoiler');
/* Test the HTML spoiler message */ /* Test the HTML spoiler message */
expect(view.el.querySelector('.chat-msg-author').textContent).toBe('dummy@localhost'); expect(view.el.querySelector('.chat-msg-author').textContent).toBe('Max Mustermann');
var spoiler_msg_el = view.el.querySelector('.chat-msg-text.spoiler'); var spoiler_msg_el = view.el.querySelector('.chat-msg-text.spoiler');
expect(spoiler_msg_el.textContent).toBe('This is the spoiler'); expect(spoiler_msg_el.textContent).toBe('This is the spoiler');
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
expect(body_el.textContent).toBe('This is the spoiler'); expect(body_el.textContent).toBe('This is the spoiler');
/* Test the HTML spoiler message */ /* Test the HTML spoiler message */
expect(view.el.querySelector('.chat-msg-author').textContent).toBe('dummy@localhost'); expect(view.el.querySelector('.chat-msg-author').textContent).toBe('Max Mustermann');
var spoiler_msg_el = view.el.querySelector('.chat-msg-text.spoiler'); var spoiler_msg_el = view.el.querySelector('.chat-msg-text.spoiler');
expect(spoiler_msg_el.textContent).toBe('This is the spoiler'); expect(spoiler_msg_el.textContent).toBe('This is the spoiler');
......
...@@ -836,15 +836,16 @@ ...@@ -836,15 +836,16 @@
defaults () { defaults () {
return { return {
"jid": _converse.bare_jid, "jid": _converse.bare_jid,
"nickname": _converse.nickname,
"status": _converse.default_state, "status": _converse.default_state,
"vcard_updated": null,
'image': _converse.DEFAULT_IMAGE,
'image_type': _converse.DEFAULT_IMAGE_TYPE
} }
}, },
initialize () { initialize () {
this.vcard = _converse.vcards.findWhere({'jid': this.get('jid')});
if (_.isNil(this.vcard)) {
this.vcard = _converse.vcards.create({'jid': this.get('jid')});
}
this.on('change:status', (item) => { this.on('change:status', (item) => {
const status = this.get('status'); const status = this.get('status');
this.sendPresence(status); this.sendPresence(status);
......
...@@ -57,7 +57,9 @@ ...@@ -57,7 +57,9 @@
}, },
toHTML () { toHTML () {
return tpl_profile_modal(_.extend(this.model.toJSON(), { return tpl_profile_modal(_.extend(
this.model.toJSON(),
this.model.vcard.toJSON(), {
'heading_profile': __('Your Profile'), 'heading_profile': __('Your Profile'),
'label_close': __('Close'), 'label_close': __('Close'),
'label_email': __('Email'), 'label_email': __('Email'),
...@@ -88,7 +90,7 @@ ...@@ -88,7 +90,7 @@
setVCard (body, data) { setVCard (body, data) {
_converse.api.vcard.set(data) _converse.api.vcard.set(data)
.then(() => { .then(() => {
_converse.api.vcard.update(this.model, true); _converse.api.vcard.update(this.model.vcard, true);
const html = tpl_alert({ const html = tpl_alert({
'message': __('Profile data succesfully saved'), 'message': __('Profile data succesfully saved'),
...@@ -145,19 +147,22 @@ ...@@ -145,19 +147,22 @@
}, },
toHTML () { toHTML () {
return tpl_chat_status_modal(_.extend(this.model.toJSON(), { return tpl_chat_status_modal(
'label_away': __('Away'), _.extend(
'label_close': __('Close'), this.model.toJSON(),
'label_busy': __('Busy'), this.model.vcard.toJSON(), {
'label_cancel': __('Cancel'), 'label_away': __('Away'),
'label_custom_status': __('Custom status'), 'label_close': __('Close'),
'label_offline': __('Offline'), 'label_busy': __('Busy'),
'label_online': __('Online'), 'label_cancel': __('Cancel'),
'label_save': __('Save'), 'label_custom_status': __('Custom status'),
'label_xa': __('Away for long'), 'label_offline': __('Offline'),
'modal_title': __('Change chat status'), 'label_online': __('Online'),
'placeholder_status_message': __('Personal status message') 'label_save': __('Save'),
})); 'label_xa': __('Away for long'),
'modal_title': __('Change chat status'),
'placeholder_status_message': __('Personal status message')
}));
}, },
afterRender () { afterRender () {
...@@ -196,12 +201,15 @@ ...@@ -196,12 +201,15 @@
initialize () { initialize () {
this.model.on("change", this.render, this); this.model.on("change", this.render, this);
this.model.vcard.on("change", this.render, this);
}, },
toHTML () { toHTML () {
const chat_status = this.model.get('status') || 'offline'; const chat_status = this.model.get('status') || 'offline';
return tpl_profile_view(_.extend(this.model.toJSON(), { return tpl_profile_view(_.extend(
'fullname': this.model.get('fullname') || _converse.bare_jid, this.model.toJSON(),
this.model.vcard.toJSON(), {
'fullname': this.model.vcard.get('fullname') || _converse.bare_jid,
'status_message': this.model.get('status_message') || 'status_message': this.model.get('status_message') ||
__("I am %1$s", this.getPrettyStatus(chat_status)), __("I am %1$s", this.getPrettyStatus(chat_status)),
'chat_status': chat_status, 'chat_status': chat_status,
......
...@@ -159,7 +159,7 @@ ...@@ -159,7 +159,7 @@
if (message && message !== "") { if (message && message !== "") {
pres.c("status").t(message).up(); pres.c("status").t(message).up();
} }
const nick = _converse.xmppstatus.get('nickname') || _converse.xmppstatus.get('fullname'); const nick = _converse.xmppstatus.vcard.get('nickname') || _converse.xmppstatus.vcard.get('fullname');
if (nick) { if (nick) {
pres.c('nick', {'xmlns': Strophe.NS.NICK}).t(nick).up(); pres.c('nick', {'xmlns': Strophe.NS.NICK}).t(nick).up();
} }
...@@ -388,7 +388,7 @@ ...@@ -388,7 +388,7 @@
if (item.getAttribute('action') === 'add') { if (item.getAttribute('action') === 'add') {
_converse.roster.addAndSubscribe( _converse.roster.addAndSubscribe(
item.getAttribute('jid'), item.getAttribute('jid'),
_converse.xmppstatus.get('nickname') || _converse.xmppstatus.get('fullname') _converse.xmppstatus.vcard.get('nickname') || _converse.xmppstatus.vcard.get('fullname')
); );
} }
}); });
......
...@@ -111,15 +111,6 @@ ...@@ -111,15 +111,6 @@
_converse.api.disco.addFeature(Strophe.NS.VCARD); _converse.api.disco.addFeature(Strophe.NS.VCARD);
}); });
_converse.on('statusInitialized', function fetchOwnVCard () {
_converse.api.disco.supports(Strophe.NS.VCARD, _converse.domain)
.then((result) => {
if (result.length) {
_converse.api.vcard.update(_converse.xmppstatus);
}})
.catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
});
_.extend(_converse.api, { _.extend(_converse.api, {
'vcard': { 'vcard': {
'set': setVCard, 'set': setVCard,
......
...@@ -94,14 +94,11 @@ ...@@ -94,14 +94,11 @@
'animate': false, 'animate': false,
'use_emojione': false, 'use_emojione': false,
'no_trimming': true, 'no_trimming': true,
'auto_login': true,
'jid': 'dummy@localhost',
'view_mode': mock.view_mode, 'view_mode': mock.view_mode,
'password': 'secret',
'debug': false 'debug': false
}, settings || {})); }, settings || {}));
_converse.ChatBoxViews.prototype.trimChat = function () {};
_converse.ChatBoxViews.prototype.trimChat = function () {};
_converse.api.vcard.get = function (model, force) { _converse.api.vcard.get = function (model, force) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let jid; let jid;
...@@ -132,7 +129,12 @@ ...@@ -132,7 +129,12 @@
resolve(result); resolve(result);
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL)); }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
}; };
if (_.get(settings, 'auto_login') !== false) {
_converse.api.user.login({
'jid': 'dummy@localhost',
'password': 'secret'
});
}
window.converse_disable_effects = true; window.converse_disable_effects = true;
return _converse; return _converse;
} }
......
...@@ -144,12 +144,16 @@ ...@@ -144,12 +144,16 @@
utils.waitUntil(() => { utils.waitUntil(() => {
return _.filter( return _.filter(
_converse.connection.IQ_stanzas, (node) => node.nodeTree.querySelector('query').getAttribute('node') === 'x-roomuser-item' _converse.connection.IQ_stanzas, (node) => {
).length const query = node.nodeTree.querySelector('query');
return query && query.getAttribute('node') === 'x-roomuser-item'
}).length
}).then(function () { }).then(function () {
const last_stanza = _.filter( const last_stanza = _.filter(
_converse.connection.IQ_stanzas, (node) => node.nodeTree.querySelector('query').getAttribute('node') === 'x-roomuser-item' _converse.connection.IQ_stanzas, (node) => {
).pop().nodeTree; const query = node.nodeTree.querySelector('query');
return query && query.getAttribute('node') === 'x-roomuser-item'
}).pop().nodeTree;
// The XMPP server returns the reserved nick for this user. // The XMPP server returns the reserved nick for this user.
const IQ_id = last_stanza.getAttribute('id'); const IQ_id = last_stanza.getAttribute('id');
......
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