Commit 16b2a1b2 authored by JC Brand's avatar JC Brand

Avatar/VCard refactoring

- Refer to VCards instead of Avatars where appropriate
- Fetch VCards for non-groupchat messages as well
parent d5c8acea
......@@ -22,6 +22,8 @@
converse.plugins.add('converse-chatboxes', {
dependencies: ["converse-vcard"],
overrides: {
// Overrides mentioned here will be picked up by converse.js's
// plugin architecture they will replace existing methods on the
......@@ -95,9 +97,9 @@
},
initialize () {
this.avatar = _converse.avatars.findWhere({'jid': this.get('from')});
if (_.isNil(this.avatar)) {
this.avatar = _converse.avatars.create({'jid': this.get('from')});
this.vcard = _converse.vcards.findWhere({'jid': this.get('from')});
if (_.isNil(this.vcard)) {
this.vcard = _converse.vcards.create({'jid': this.get('from')});
}
if (this.get('file')) {
......
......@@ -268,17 +268,6 @@
});
_converse.Avatars = Backbone.Collection.extend({
model: _converse.ModelWithDefaultAvatar,
initialize () {
this.on('add', (avatar) => {
_converse.api.vcard.update(avatar);
});
}
});
_converse.initialize = function (settings, callback) {
"use strict";
settings = !_.isUndefined(settings) ? settings : {};
......@@ -1820,11 +1809,6 @@
_converse.emit('connectionInitialized');
};
this.initAvatars = function () {
_converse.avatars = new _converse.Avatars();
_converse.avatars.browserStorage = new Backbone.BrowserStorage.local(b64_sha1(`converse.avatars`));
_converse.avatars.fetch();
};
this._tearDown = function () {
/* Remove those views which are only allowed with a valid
......@@ -1895,7 +1879,6 @@
function finishInitialization () {
_converse.initPlugins();
_converse.initConnection();
_converse.initAvatars();
_converse.setUpXMLLogging();
_converse.logIn();
_converse.registerGlobalEventHandlers();
......
......@@ -53,9 +53,7 @@
})
}
});
this.model.avatar.on('change:image', () => {
this.renderAvatar();
});
this.model.vcard.on('change:image', () => this.renderAvatar());
this.model.on('change:fullname', this.render, this);
this.model.on('change:progress', this.renderFileUploadProgresBar, this);
this.model.on('change:type', this.render, this);
......@@ -128,8 +126,8 @@
if (_.isNull(canvas_el)) {
return;
}
const image_type = this.model.avatar.get('image_type'),
image = this.model.avatar.get('image'),
const image_type = this.model.vcard.get('image_type'),
image = this.model.vcard.get('image'),
img_src = "data:" + image_type + ";base64," + image,
img = new Image();
......
......@@ -996,12 +996,12 @@
},
onAvatarChanged () {
this.avatar = _converse.avatars.findWhere({'jid': this.get('from')});
if (!this.avatar) { return; }
const vcard = _converse.vcards.findWhere({'jid': this.get('from')});
if (!vcard) { return; }
const hash = this.get('image_hash');
if (hash && this.avatar.get('image_hash') !== hash) {
_converse.api.vcard.update(this.avatar);
if (hash && vcard.get('image_hash') !== hash) {
_converse.api.vcard.update(vcard);
}
}
});
......
......@@ -10,7 +10,7 @@
define(["converse-core", "crypto", "strophe.vcard"], factory);
}(this, function (converse, CryptoJS) {
"use strict";
const { Promise, Strophe, SHA1, _, moment, sizzle } = converse.env;
const { Backbone, Promise, Strophe, SHA1, _, b64_sha1, moment, sizzle } = converse.env;
const u = converse.env.utils;
......@@ -110,6 +110,15 @@
*/
const { _converse } = this;
_converse.VCards = Backbone.Collection.extend({
model: _converse.ModelWithDefaultAvatar,
initialize () {
this.on('add', (model) => _converse.api.vcard.update(model));
}
});
_converse.createRequestingContactFromVCard = function (presence, vcard) {
const bare_jid = Strophe.getBareJidFromJid(presence.getAttribute('from'));
let fullname = vcard.fullname;
......@@ -134,6 +143,14 @@
};
/* Event handlers */
_converse.initVCardCollection = function () {
_converse.vcards = new _converse.VCards();
_converse.vcards.browserStorage = new Backbone.BrowserStorage.local(b64_sha1(`converse.vcards`));
_converse.vcards.fetch();
}
_converse.api.listen.on('connectionInitialized', _converse.initVCardCollection);
_converse.on('addClientFeatures', () => {
_converse.connection.disco.addFeature(Strophe.NS.VCARD);
});
......
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