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