Remove dependency on strophe's vcard plugin
This commit is contained in:
parent
2d2dcd4a6d
commit
6c513ad4be
@ -71,7 +71,6 @@
|
||||
"strophejs-plugin-ping": "0.0.1",
|
||||
"strophejs-plugin-register": "0.0.1",
|
||||
"strophejs-plugin-rsm": "0.0.1",
|
||||
"strophejs-plugin-vcard": "0.0.1",
|
||||
"text": "requirejs/text#2.0.15",
|
||||
"uglify-es": "^3.0.24",
|
||||
"urijs": "^1.19.1",
|
||||
|
@ -10,7 +10,6 @@
|
||||
"moment",
|
||||
"strophe",
|
||||
"strophe.rsm",
|
||||
"strophe.vcard",
|
||||
"strophe.ping",
|
||||
"otr",
|
||||
"lodash",
|
||||
|
@ -56,7 +56,6 @@ require.config({
|
||||
"strophe": "node_modules/strophe.js/strophe",
|
||||
"strophe.ping": "node_modules/strophejs-plugin-ping/strophe.ping",
|
||||
"strophe.rsm": "node_modules/strophejs-plugin-rsm/strophe.rsm",
|
||||
"strophe.vcard": "node_modules/strophejs-plugin-vcard/strophe.vcard",
|
||||
"text": "node_modules/text/text",
|
||||
"tovnode": "node_modules/snabbdom/dist/tovnode",
|
||||
"tpl": "node_modules/lodash-template-loader/loader",
|
||||
|
@ -47,8 +47,9 @@
|
||||
Strophe.addNamespace('RSM', 'http://jabber.org/protocol/rsm');
|
||||
Strophe.addNamespace('SID', 'urn:xmpp:sid: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('XFORM', 'jabber:x:data');
|
||||
|
||||
// Use Mustache style syntax for variable interpolation
|
||||
/* Configuration of Lodash templates (this config is distinct to the
|
||||
|
@ -5,10 +5,10 @@
|
||||
// Licensed under the Mozilla Public License (MPLv2)
|
||||
|
||||
(function (root, factory) {
|
||||
define(["converse-core", "crypto", "strophe.vcard"], factory);
|
||||
define(["converse-core", "crypto"], factory);
|
||||
}(this, function (converse, CryptoJS) {
|
||||
"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;
|
||||
|
||||
|
||||
@ -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) {
|
||||
/* Request the VCard of another user. Returns a promise.
|
||||
*
|
||||
@ -46,12 +55,13 @@
|
||||
* (String) jid - The Jabber ID of the user whose VCard
|
||||
* 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) => {
|
||||
_converse.connection.vcard.get(
|
||||
_converse.connection.sendIQ(
|
||||
createStanza("get", jid),
|
||||
_.partial(onVCardData, _converse, jid, _, resolve),
|
||||
to,
|
||||
_.partial(onVCardError, _converse, jid, _, resolve)
|
||||
_.partial(onVCardError, _converse, jid, _, resolve),
|
||||
5000
|
||||
);
|
||||
});
|
||||
}
|
||||
|
@ -44,7 +44,6 @@
|
||||
var emptyFunction = function () { };
|
||||
define('strophe.ping', ['strophe'], strophePlugin);
|
||||
define('strophe.rsm', ['strophe'], strophePlugin);
|
||||
define('strophe.vcard', ['strophe'], strophePlugin);
|
||||
define('backbone', [], function () { return Backbone; });
|
||||
define('backbone.noconflict', [], function () { return Backbone; });
|
||||
define('backbone.browserStorage', ['backbone'], emptyFunction);
|
||||
|
@ -63,23 +63,6 @@
|
||||
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.authenticated = true;
|
||||
c.connected = true;
|
||||
@ -119,6 +102,37 @@
|
||||
}, settings || {}));
|
||||
_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;
|
||||
return _converse;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user