Skip to content

Commit

Permalink
Looser coupling with converse-vcard
Browse files Browse the repository at this point in the history
To make it easier to remove it without breaking stuff.
  • Loading branch information
jcbrand committed Apr 10, 2019
1 parent 36761f2 commit f1899d0
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 81 deletions.
104 changes: 70 additions & 34 deletions dist/converse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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') {
Expand All @@ -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');
}
},

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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');
}
},

/**
Expand Down Expand Up @@ -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');
}

});
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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 ';
Expand Down
16 changes: 9 additions & 7 deletions src/converse-chatboxviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 18 additions & 7 deletions src/headless/converse-chatboxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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');
}
},

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 0 additions & 5 deletions src/headless/converse-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 16 additions & 2 deletions src/headless/converse-roster.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
},
Expand Down Expand Up @@ -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');
}
},

/**
Expand Down
11 changes: 11 additions & 0 deletions src/headless/converse-vcard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
});

Expand Down Expand Up @@ -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);
});
Expand Down
Loading

0 comments on commit f1899d0

Please sign in to comment.