Looser coupling with converse-vcard

To make it easier to remove it without breaking stuff.
This commit is contained in:
JC Brand 2019-04-09 20:34:23 +02:00
parent 36761f290e
commit f1899d0977
7 changed files with 181 additions and 81 deletions

104
dist/converse.js vendored
View File

@ -48641,19 +48641,24 @@ const AvatarMixin = {
return;
}
const image_type = this.model.vcard.get('image_type'),
image = this.model.vcard.get('image');
canvas_el.outerHTML = templates_avatar_svg__WEBPACK_IMPORTED_MODULE_4___default()({
const data = {
'classes': canvas_el.getAttribute('class'),
'width': canvas_el.width,
'height': canvas_el.height,
'image': "data:" + image_type + ";base64," + image
});
'height': canvas_el.height
};
if (this.model.vcard) {
const image_type = this.model.vcard.get('image_type'),
image = this.model.vcard.get('image');
data['image'] = "data:" + image_type + ";base64," + image;
}
canvas_el.outerHTML = templates_avatar_svg__WEBPACK_IMPORTED_MODULE_4___default()(data);
}
};
_converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-chatboxviews', {
dependencies: ["converse-chatboxes"],
dependencies: ["converse-chatboxes", "converse-vcard"],
overrides: {
// Overrides mentioned here will be picked up by converse.js's
// plugin architecture they will replace existing methods on the
@ -61849,6 +61854,11 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
},
setVCard() {
if (!_converse.vcards) {
// VCards aren't supported
return;
}
if (this.get('type') === 'error') {
return;
} else if (this.get('type') === 'groupchat') {
@ -61870,12 +61880,12 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
getDisplayName() {
if (this.get('type') === 'groupchat') {
return this.get('nick');
} else if (this.contact) {
return this.contact.getDisplayName();
} else if (this.vcard) {
return this.vcard.getDisplayName();
} else {
if (this.contact) {
return this.contact.getDisplayName();
}
return this.vcard.get('nickname') || this.vcard.get('fullname') || this.get('from');
return this.get('from');
}
},
@ -62015,22 +62025,25 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
// This happens when the controlbox is in browser storage,
// but we're in embedded mode.
return;
}
this.vcard = _converse.vcards.findWhere({
'jid': jid
}) || _converse.vcards.create({
'jid': jid
}); // XXX: this creates a dependency on converse-roster, which we
} // XXX: this creates a dependency on converse-roster, which we
// probably shouldn't have here, so we should probably move
// ChatBox out of converse-chatboxes
this.presence = _converse.presences.findWhere({
'jid': jid
}) || _converse.presences.create({
'jid': jid
});
if (_converse.vcards) {
this.vcard = _converse.vcards.findWhere({
'jid': jid
}) || _converse.vcards.create({
'jid': jid
});
}
if (this.get('type') === _converse.PRIVATE_CHAT_TYPE) {
this.setRosterContact(jid);
}
@ -62070,9 +62083,11 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
getDisplayName() {
if (this.contact) {
return this.contact.getDisplayName();
} else if (this.vcard) {
return this.vcard.getDisplayName();
} else {
return this.get('jid');
}
return this.vcard.get('nickname') || this.vcard.get('fullname') || this.get('jid');
},
getUpdatedMessageAttributes(message, stanza) {
@ -64254,16 +64269,6 @@ _converse.initialize = async function (settings, callback) {
},
initialize() {
this.vcard = _converse.vcards.findWhere({
'jid': this.get('jid')
});
if (_lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.isNil(this.vcard)) {
this.vcard = _converse.vcards.create({
'jid': this.get('jid')
});
}
this.on('change:status', item => {
const status = this.get('status');
this.sendPresence(status);
@ -68820,6 +68825,11 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
},
setVCard() {
if (!_converse.vcards) {
// VCards aren't supported
return;
}
const jid = this.get('jid');
this.vcard = _converse.vcards.findWhere({
'jid': jid
@ -68873,11 +68883,21 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
},
getDisplayName() {
return this.get('nickname') || this.vcard.get('nickname') || this.vcard.get('fullname') || this.get('jid');
if (this.get('nickname')) {
return this.get('nickname');
} else if (this.vcard) {
return this.vcard.getDisplayName();
} else {
return this.get('jid');
}
},
getFullname() {
return this.vcard.get('fullname');
if (this.vcard) {
return this.vcard.get('fullname');
} else {
return this.get('jid');
}
},
/**
@ -69828,6 +69848,10 @@ _converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins.add('converse-vca
} else {
return Backbone.Model.prototype.set.apply(this, arguments);
}
},
getDisplayName() {
return this.get('nickname') || this.get('fullname') || this.get('jid');
}
});
@ -69925,6 +69949,18 @@ _converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins.add('converse-vca
_converse.api.listen.on('sessionInitialized', _converse.initVCardCollection);
_converse.api.listen.on('statusInitialized', () => {
const vcards = _converse.vcards;
const jid = _converse.xmppstatus.get('jid');
_converse.xmppstatus.vcard = vcards.findWhere({
'jid': jid
}) || vcards.create({
'jid': jid
});
});
_converse.api.listen.on('addClientFeatures', () => {
_converse.api.disco.own.features.add(Strophe.NS.VCARD);
});
@ -94517,7 +94553,7 @@ __p += '\n </span>\n ';
__p += '<div class="chat-msg__body">';
} ;
__p += '\n ';
if (o.received) { ;
if (o.received && !o.is_me_message) { ;
__p += ' <span class="fa fa-check chat-msg__receipt"></span> ';
} ;
__p += '\n ';

View File

@ -23,22 +23,24 @@ const AvatarMixin = {
if (_.isNull(canvas_el)) {
return;
}
const image_type = this.model.vcard.get('image_type'),
image = this.model.vcard.get('image');
canvas_el.outerHTML = tpl_avatar({
const data = {
'classes': canvas_el.getAttribute('class'),
'width': canvas_el.width,
'height': canvas_el.height,
'image': "data:" + image_type + ";base64," + image,
});
}
if (this.model.vcard) {
const image_type = this.model.vcard.get('image_type'),
image = this.model.vcard.get('image');
data['image'] = "data:" + image_type + ";base64," + image;
}
canvas_el.outerHTML = tpl_avatar(data);
},
};
converse.plugins.add('converse-chatboxviews', {
dependencies: ["converse-chatboxes"],
dependencies: ["converse-chatboxes", "converse-vcard"],
overrides: {
// Overrides mentioned here will be picked up by converse.js's

View File

@ -118,6 +118,10 @@ converse.plugins.add('converse-chatboxes', {
},
setVCard () {
if (!_converse.vcards) {
// VCards aren't supported
return;
}
if (this.get('type') === 'error') {
return;
} else if (this.get('type') === 'groupchat') {
@ -135,11 +139,12 @@ converse.plugins.add('converse-chatboxes', {
getDisplayName () {
if (this.get('type') === 'groupchat') {
return this.get('nick');
} else if (this.contact) {
return this.contact.getDisplayName();
} else if (this.vcard) {
return this.vcard.getDisplayName();
} else {
if (this.contact) {
return this.contact.getDisplayName();
}
return this.vcard.get('nickname') || this.vcard.get('fullname') || this.get('from');
return this.get('from');
}
},
@ -271,12 +276,15 @@ converse.plugins.add('converse-chatboxes', {
// but we're in embedded mode.
return;
}
this.vcard = _converse.vcards.findWhere({'jid': jid}) || _converse.vcards.create({'jid': jid});
// XXX: this creates a dependency on converse-roster, which we
// probably shouldn't have here, so we should probably move
// ChatBox out of converse-chatboxes
this.presence = _converse.presences.findWhere({'jid': jid}) || _converse.presences.create({'jid': jid});
if (_converse.vcards) {
this.vcard = _converse.vcards.findWhere({'jid': jid}) || _converse.vcards.create({'jid': jid});
}
if (this.get('type') === _converse.PRIVATE_CHAT_TYPE) {
this.setRosterContact(jid);
}
@ -317,8 +325,11 @@ converse.plugins.add('converse-chatboxes', {
getDisplayName () {
if (this.contact) {
return this.contact.getDisplayName();
} else if (this.vcard) {
return this.vcard.getDisplayName();
} else {
return this.get('jid');
}
return this.vcard.get('nickname') || this.vcard.get('fullname') || this.get('jid');
},
getUpdatedMessageAttributes (message, stanza) {

View File

@ -1059,11 +1059,6 @@ _converse.initialize = async function (settings, callback) {
},
initialize () {
this.vcard = _converse.vcards.findWhere({'jid': this.get('jid')});
if (_.isNil(this.vcard)) {
this.vcard = _converse.vcards.create({'jid': this.get('jid')});
}
this.on('change:status', (item) => {
const status = this.get('status');
this.sendPresence(status);

View File

@ -211,6 +211,10 @@ converse.plugins.add('converse-roster', {
},
setVCard () {
if (!_converse.vcards) {
// VCards aren't supported
return;
}
const jid = this.get('jid');
this.vcard = _converse.vcards.findWhere({'jid': jid}) || _converse.vcards.create({'jid': jid});
},
@ -258,11 +262,21 @@ converse.plugins.add('converse-roster', {
},
getDisplayName () {
return this.get('nickname') || this.vcard.get('nickname') || this.vcard.get('fullname') || this.get('jid');
if (this.get('nickname')) {
return this.get('nickname');
} else if (this.vcard) {
return this.vcard.getDisplayName();
} else {
return this.get('jid');
}
},
getFullname () {
return this.vcard.get('fullname');
if (this.vcard) {
return this.vcard.get('fullname');
} else {
return this.get('jid');
}
},
/**

View File

@ -43,6 +43,10 @@ converse.plugins.add('converse-vcard', {
} else {
return Backbone.Model.prototype.set.apply(this, arguments);
}
},
getDisplayName () {
return this.get('nickname') || this.get('fullname') || this.get('jid');
}
});
@ -124,6 +128,13 @@ converse.plugins.add('converse-vcard', {
_converse.api.listen.on('sessionInitialized', _converse.initVCardCollection);
_converse.api.listen.on('statusInitialized', () => {
const vcards = _converse.vcards;
const jid = _converse.xmppstatus.get('jid');
_converse.xmppstatus.vcard = vcards.findWhere({'jid': jid}) || vcards.create({'jid': jid});
});
_converse.api.listen.on('addClientFeatures', () => {
_converse.api.disco.own.features.add(Strophe.NS.VCARD);
});

View File

@ -40371,6 +40371,11 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
},
setVCard() {
if (!_converse.vcards) {
// VCards aren't supported
return;
}
if (this.get('type') === 'error') {
return;
} else if (this.get('type') === 'groupchat') {
@ -40392,12 +40397,12 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
getDisplayName() {
if (this.get('type') === 'groupchat') {
return this.get('nick');
} else if (this.contact) {
return this.contact.getDisplayName();
} else if (this.vcard) {
return this.vcard.getDisplayName();
} else {
if (this.contact) {
return this.contact.getDisplayName();
}
return this.vcard.get('nickname') || this.vcard.get('fullname') || this.get('from');
return this.get('from');
}
},
@ -40537,22 +40542,25 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
// This happens when the controlbox is in browser storage,
// but we're in embedded mode.
return;
}
this.vcard = _converse.vcards.findWhere({
'jid': jid
}) || _converse.vcards.create({
'jid': jid
}); // XXX: this creates a dependency on converse-roster, which we
} // XXX: this creates a dependency on converse-roster, which we
// probably shouldn't have here, so we should probably move
// ChatBox out of converse-chatboxes
this.presence = _converse.presences.findWhere({
'jid': jid
}) || _converse.presences.create({
'jid': jid
});
if (_converse.vcards) {
this.vcard = _converse.vcards.findWhere({
'jid': jid
}) || _converse.vcards.create({
'jid': jid
});
}
if (this.get('type') === _converse.PRIVATE_CHAT_TYPE) {
this.setRosterContact(jid);
}
@ -40592,9 +40600,11 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
getDisplayName() {
if (this.contact) {
return this.contact.getDisplayName();
} else if (this.vcard) {
return this.vcard.getDisplayName();
} else {
return this.get('jid');
}
return this.vcard.get('nickname') || this.vcard.get('fullname') || this.get('jid');
},
getUpdatedMessageAttributes(message, stanza) {
@ -42776,16 +42786,6 @@ _converse.initialize = async function (settings, callback) {
},
initialize() {
this.vcard = _converse.vcards.findWhere({
'jid': this.get('jid')
});
if (_lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.isNil(this.vcard)) {
this.vcard = _converse.vcards.create({
'jid': this.get('jid')
});
}
this.on('change:status', item => {
const status = this.get('status');
this.sendPresence(status);
@ -47342,6 +47342,11 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
},
setVCard() {
if (!_converse.vcards) {
// VCards aren't supported
return;
}
const jid = this.get('jid');
this.vcard = _converse.vcards.findWhere({
'jid': jid
@ -47395,11 +47400,21 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
},
getDisplayName() {
return this.get('nickname') || this.vcard.get('nickname') || this.vcard.get('fullname') || this.get('jid');
if (this.get('nickname')) {
return this.get('nickname');
} else if (this.vcard) {
return this.vcard.getDisplayName();
} else {
return this.get('jid');
}
},
getFullname() {
return this.vcard.get('fullname');
if (this.vcard) {
return this.vcard.get('fullname');
} else {
return this.get('jid');
}
},
/**
@ -48350,6 +48365,10 @@ _converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins.add('converse-vca
} else {
return Backbone.Model.prototype.set.apply(this, arguments);
}
},
getDisplayName() {
return this.get('nickname') || this.get('fullname') || this.get('jid');
}
});
@ -48447,6 +48466,18 @@ _converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins.add('converse-vca
_converse.api.listen.on('sessionInitialized', _converse.initVCardCollection);
_converse.api.listen.on('statusInitialized', () => {
const vcards = _converse.vcards;
const jid = _converse.xmppstatus.get('jid');
_converse.xmppstatus.vcard = vcards.findWhere({
'jid': jid
}) || vcards.create({
'jid': jid
});
});
_converse.api.listen.on('addClientFeatures', () => {
_converse.api.disco.own.features.add(Strophe.NS.VCARD);
});