Commit 6c513ad4 authored by JC Brand's avatar JC Brand

Remove dependency on strophe's vcard plugin

parent 2d2dcd4a
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
"moment", "moment",
"strophe", "strophe",
"strophe.rsm", "strophe.rsm",
"strophe.vcard",
"strophe.ping", "strophe.ping",
"otr", "otr",
"lodash", "lodash",
......
...@@ -56,7 +56,6 @@ require.config({ ...@@ -56,7 +56,6 @@ require.config({
"strophe": "node_modules/strophe.js/strophe", "strophe": "node_modules/strophe.js/strophe",
"strophe.ping": "node_modules/strophejs-plugin-ping/strophe.ping", "strophe.ping": "node_modules/strophejs-plugin-ping/strophe.ping",
"strophe.rsm": "node_modules/strophejs-plugin-rsm/strophe.rsm", "strophe.rsm": "node_modules/strophejs-plugin-rsm/strophe.rsm",
"strophe.vcard": "node_modules/strophejs-plugin-vcard/strophe.vcard",
"text": "node_modules/text/text", "text": "node_modules/text/text",
"tovnode": "node_modules/snabbdom/dist/tovnode", "tovnode": "node_modules/snabbdom/dist/tovnode",
"tpl": "node_modules/lodash-template-loader/loader", "tpl": "node_modules/lodash-template-loader/loader",
......
...@@ -47,8 +47,9 @@ ...@@ -47,8 +47,9 @@
Strophe.addNamespace('RSM', 'http://jabber.org/protocol/rsm'); Strophe.addNamespace('RSM', 'http://jabber.org/protocol/rsm');
Strophe.addNamespace('SID', 'urn:xmpp:sid:0'); Strophe.addNamespace('SID', 'urn:xmpp:sid:0');
Strophe.addNamespace('SPOILER', 'urn:xmpp:spoiler:0'); Strophe.addNamespace('SPOILER', 'urn:xmpp:spoiler:0');
Strophe.addNamespace('XFORM', 'jabber:x:data'); Strophe.addNamespace('VCARD', 'vcard-temp');
Strophe.addNamespace('VCARDUPDATE', 'vcard-temp:x:update'); Strophe.addNamespace('VCARDUPDATE', 'vcard-temp:x:update');
Strophe.addNamespace('XFORM', 'jabber:x:data');
// Use Mustache style syntax for variable interpolation // Use Mustache style syntax for variable interpolation
/* Configuration of Lodash templates (this config is distinct to the /* Configuration of Lodash templates (this config is distinct to the
......
...@@ -5,10 +5,10 @@ ...@@ -5,10 +5,10 @@
// Licensed under the Mozilla Public License (MPLv2) // Licensed under the Mozilla Public License (MPLv2)
(function (root, factory) { (function (root, factory) {
define(["converse-core", "crypto", "strophe.vcard"], factory); define(["converse-core", "crypto"], factory);
}(this, function (converse, CryptoJS) { }(this, function (converse, CryptoJS) {
"use strict"; "use strict";
const { Backbone, Promise, Strophe, SHA1, _, b64_sha1, moment, sizzle } = converse.env; const { Backbone, Promise, Strophe, SHA1, _, $iq, b64_sha1, moment, sizzle } = converse.env;
const u = converse.env.utils; const u = converse.env.utils;
...@@ -39,6 +39,15 @@ ...@@ -39,6 +39,15 @@
} }
} }
function createStanza (type, jid, vcard_el) {
const iq = $iq(jid ? {'type': type, 'to': jid} : {'type': type});
iq.c("vCard", {'xmlns': Strophe.NS.VCARD});
if (vcard_el) {
iq.cnode(vcard_el);
}
return iq;
}
function getVCard (_converse, jid) { function getVCard (_converse, jid) {
/* Request the VCard of another user. Returns a promise. /* Request the VCard of another user. Returns a promise.
* *
...@@ -46,12 +55,13 @@ ...@@ -46,12 +55,13 @@
* (String) jid - The Jabber ID of the user whose VCard * (String) jid - The Jabber ID of the user whose VCard
* is being requested. * is being requested.
*/ */
const to = Strophe.getBareJidFromJid(jid) === _converse.bare_jid ? null : jid; jid = Strophe.getBareJidFromJid(jid) === _converse.bare_jid ? null : jid;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
_converse.connection.vcard.get( _converse.connection.sendIQ(
createStanza("get", jid),
_.partial(onVCardData, _converse, jid, _, resolve), _.partial(onVCardData, _converse, jid, _, resolve),
to, _.partial(onVCardError, _converse, jid, _, resolve),
_.partial(onVCardError, _converse, jid, _, resolve) 5000
); );
}); });
} }
......
...@@ -44,7 +44,6 @@ ...@@ -44,7 +44,6 @@
var emptyFunction = function () { }; var emptyFunction = function () { };
define('strophe.ping', ['strophe'], strophePlugin); define('strophe.ping', ['strophe'], strophePlugin);
define('strophe.rsm', ['strophe'], strophePlugin); define('strophe.rsm', ['strophe'], strophePlugin);
define('strophe.vcard', ['strophe'], strophePlugin);
define('backbone', [], function () { return Backbone; }); define('backbone', [], function () { return Backbone; });
define('backbone.noconflict', [], function () { return Backbone; }); define('backbone.noconflict', [], function () { return Backbone; });
define('backbone.browserStorage', ['backbone'], emptyFunction); define('backbone.browserStorage', ['backbone'], emptyFunction);
......
...@@ -63,23 +63,6 @@ ...@@ -63,23 +63,6 @@
return id; return id;
} }
c.vcard = {
'get': function (callback, jid) {
var fullname;
if (!jid) {
jid = 'dummy@localhost';
fullname = 'Max Mustermann' ;
} else {
var name = jid.split('@')[0].replace(/\./g, ' ').split(' ');
var last = name.length-1;
name[0] = name[0].charAt(0).toUpperCase()+name[0].slice(1);
name[last] = name[last].charAt(0).toUpperCase()+name[last].slice(1);
fullname = name.join(' ');
}
var vcard = $iq().c('vCard').c('FN').t(fullname);
callback(vcard.tree());
}
};
c._proto._connect = function () { c._proto._connect = function () {
c.authenticated = true; c.authenticated = true;
c.connected = true; c.connected = true;
...@@ -119,6 +102,37 @@ ...@@ -119,6 +102,37 @@
}, settings || {})); }, settings || {}));
_converse.ChatBoxViews.prototype.trimChat = function () {}; _converse.ChatBoxViews.prototype.trimChat = function () {};
_converse.api.vcard.get = function (model, force) {
return new Promise((resolve, reject) => {
let jid;
if (_.isString(model)) {
jid = model;
} else if (!model.get('vcard_updated') || force) {
jid = model.get('jid') || model.get('muc_jid');
}
var fullname;
if (!jid || jid == 'dummy@localhost') {
jid = 'dummy@localhost';
fullname = 'Max Mustermann' ;
} else {
var name = jid.split('@')[0].replace(/\./g, ' ').split(' ');
var last = name.length-1;
name[0] = name[0].charAt(0).toUpperCase()+name[0].slice(1);
name[last] = name[last].charAt(0).toUpperCase()+name[last].slice(1);
fullname = name.join(' ');
}
var vcard = $iq().c('vCard').c('FN').t(fullname).nodeTree;
var result = {
'stanza': vcard,
'fullname': _.get(vcard.querySelector('FN'), 'textContent'),
'image': _.get(vcard.querySelector('PHOTO BINVAL'), 'textContent'),
'image_type': _.get(vcard.querySelector('PHOTO TYPE'), 'textContent'),
'url': _.get(vcard.querySelector('URL'), 'textContent')
};
resolve(result);
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
};
window.converse_disable_effects = true; window.converse_disable_effects = true;
return _converse; return _converse;
} }
......
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