Commit 27760a7d authored by JC Brand's avatar JC Brand

vcard: remove jQuery as dependency

parent 1487e639
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
/*global define */ /*global define */
(function (root, factory) { (function (root, factory) {
define(["jquery.noconflict", "converse-core", "strophe.vcard"], factory); define(["converse-core", "strophe.vcard"], factory);
}(this, function ($, converse) { }(this, function (converse) {
"use strict"; "use strict";
const { Strophe, _, moment } = converse.env; const { Strophe, _, moment, sizzle } = converse.env;
converse.plugins.add('converse-vcard', { converse.plugins.add('converse-vcard', {
...@@ -62,13 +62,16 @@ ...@@ -62,13 +62,16 @@
_converse.createRequestingContactFromVCard = function (presence, iq, jid, fullname, img, img_type, url) { _converse.createRequestingContactFromVCard = function (presence, iq, jid, fullname, img, img_type, url) {
const bare_jid = Strophe.getBareJidFromJid(jid); const bare_jid = Strophe.getBareJidFromJid(jid);
const nick = $(presence).children(`nick[xmlns="${Strophe.NS.NICK}"]`).text(); if (!fullname) {
const nick_el = sizzle(`nick[xmlns="${Strophe.NS.NICK}"]`, presence);
fullname = nick_el.length ? nick_el[0].textContent : bare_jid;
}
const user_data = { const user_data = {
jid: bare_jid, jid: bare_jid,
subscription: 'none', subscription: 'none',
ask: null, ask: null,
requesting: true, requesting: true,
fullname: fullname || nick || bare_jid, fullname: fullname,
image: img, image: img,
image_type: img_type, image_type: img_type,
url, url,
...@@ -87,16 +90,16 @@ ...@@ -87,16 +90,16 @@
}; };
_converse.onVCardData = function (jid, iq, callback) { _converse.onVCardData = function (jid, iq, callback) {
const $vcard = $(iq).find('vCard'), const vcard = iq.querySelector('vCard'),
img_type = $vcard.find('TYPE').text(), img_type = _.get(vcard.querySelector('TYPE'), 'textContent'),
img = $vcard.find('BINVAL').text(), img = _.get(vcard.querySelector('BINVAL'), 'textContent'),
url = $vcard.find('URL').text(); url = _.get(vcard.querySelector('URL'), 'textContent');
let fullname = $vcard.find('FN').text(); let fullname = vcard.querySelector('FN').textContent;
if (jid) { if (jid) {
const contact = _converse.roster.get(jid); const contact = _converse.roster.get(jid);
if (contact) { if (contact) {
fullname = _.isEmpty(fullname)? contact.get('fullname') || jid: fullname; fullname = _.isEmpty(fullname) ? _.get(contact, 'fullname', jid) : fullname;
contact.save({ contact.save({
'fullname': fullname, 'fullname': fullname,
'image_type': img_type, 'image_type': img_type,
......
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