Commit 042c1947 authored by JC Brand's avatar JC Brand

Add file-upload button

parent a9d28818
...@@ -23,7 +23,8 @@ ...@@ -23,7 +23,8 @@
test_utils.waitUntilDiscoConfirmed(_converse, _converse.bare_jid, [], []).then(function () { test_utils.waitUntilDiscoConfirmed(_converse, _converse.bare_jid, [], []).then(function () {
test_utils.waitUntil(function () { test_utils.waitUntil(function () {
return _.filter(IQ_stanzas, function (iq) { return _.filter(IQ_stanzas, function (iq) {
return iq.nodeTree.querySelector('iq[to="localhost"] query[xmlns="http://jabber.org/protocol/disco#info"]'); return iq.nodeTree.querySelector(
'iq[to="localhost"] query[xmlns="http://jabber.org/protocol/disco#info"]');
}).length > 0; }).length > 0;
}, 300).then(function () { }, 300).then(function () {
/* <iq type='result' /* <iq type='result'
...@@ -40,7 +41,8 @@ ...@@ -40,7 +41,8 @@
* </iq> * </iq>
*/ */
var stanza = _.filter(IQ_stanzas, function (iq) { var stanza = _.filter(IQ_stanzas, function (iq) {
return iq.nodeTree.querySelector('iq[to="localhost"] query[xmlns="http://jabber.org/protocol/disco#info"]'); return iq.nodeTree.querySelector(
'iq[to="localhost"] query[xmlns="http://jabber.org/protocol/disco#info"]');
})[0]; })[0];
var info_IQ_id = IQ_ids[IQ_stanzas.indexOf(stanza)]; var info_IQ_id = IQ_ids[IQ_stanzas.indexOf(stanza)];
...@@ -174,10 +176,26 @@ ...@@ -174,10 +176,26 @@
describe("A file upload toolbar button", function () { describe("A file upload toolbar button", function () {
it("appears in private chats", mock.initConverseWithAsync(function (done, _converse) { it("appears in private chats", mock.initConverseWithAsync(function (done, _converse) {
test_utils.createContacts(_converse, 'current'); test_utils.waitUntilDiscoConfirmed(
var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost'; _converse, _converse.domain,
test_utils.openChatBoxFor(_converse, contact_jid); [{'category': 'server', 'type':'IM'}],
done(); ['http://jabber.org/protocol/disco#items'], [], 'info').then(function () {
test_utils.waitUntilDiscoConfirmed(_converse, _converse.domain, [], [], ['upload.localhost'], 'items').then(function () {
test_utils.waitUntilDiscoConfirmed(_converse, 'upload.localhost', [], [Strophe.NS.HTTPUPLOAD], []).then(function () {
test_utils.createContacts(_converse, 'current');
var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
test_utils.openChatBoxFor(_converse, contact_jid);
var view = _converse.chatboxviews.get(contact_jid);
test_utils.waitUntil(function () {
return view.el.querySelector('.upload-file');
}, 150).then(function () {
expect(view.el.querySelector('.chat-toolbar .upload-file')).not.toBe(null);
done();
});
});
});
});
})); }));
it("appears in MUC chats", mock.initConverseWithAsync(function (done, _converse) { it("appears in MUC chats", mock.initConverseWithAsync(function (done, _converse) {
......
(function (root, factory) { (function (root, factory) {
define(["converse-core"], factory); define([
}(this, function (converse) { "converse-core",
"tpl!toolbar_fileupload"
], factory);
}(this, function (converse, tpl_toolbar_fileupload) {
"use strict"; "use strict";
const { Promise, Strophe, _ } = converse.env; const { Promise, Strophe, _ } = converse.env;
...@@ -25,14 +28,21 @@ ...@@ -25,14 +28,21 @@
ChatBoxView: { ChatBoxView: {
addFileUploadButton (options) { addFileUploadButton (options) {
const { __ } = this.__super__._converse;
this.el.querySelector('.chat-toolbar').insertAdjacentHTML(
'beforeend',
tpl_toolbar_fileupload({'tooltip_upload_file': __('Choose a file to send')}));
}, },
renderToolbar (toolbar, options) { renderToolbar (toolbar, options) {
const { _converse } = this.__super__; const { _converse } = this.__super__;
const result = this.__super__.renderToolbar.apply(this, arguments); const result = this.__super__.renderToolbar.apply(this, arguments);
// TODO: check results.length
_converse.api.disco.supports(Strophe.NS.HTTPUPLOAD, _converse.domain) _converse.api.disco.supports(Strophe.NS.HTTPUPLOAD, _converse.domain)
.then(this.addFileUploadButton.bind(this)); .then((result) => {
if (result.length) {
this.addFileUploadButton();
}
});
return result; return result;
} }
} }
......
...@@ -155,7 +155,7 @@ ...@@ -155,7 +155,7 @@
const { _converse } = this.__super__; const { _converse } = this.__super__;
_converse.api.disco.supports(Strophe.NS.MAM, _converse.bare_jid).then( _converse.api.disco.supports(Strophe.NS.MAM, _converse.bare_jid).then(
(results) => { // Success (results) => { // Success
if (result.length) { if (results.length) {
const most_recent_msg = utils.getMostRecentMessage(this.model); const most_recent_msg = utils.getMostRecentMessage(this.model);
if (_.isNil(most_recent_msg)) { if (_.isNil(most_recent_msg)) {
this.fetchArchivedMessages(); this.fetchArchivedMessages();
......
<li class="upload-file fa fa-paperclip" title="{{{o.tooltip_upload_file}}}"></li>
...@@ -14,11 +14,14 @@ ...@@ -14,11 +14,14 @@
} }
utils.waitUntil = waitUntilPromise.default; utils.waitUntil = waitUntilPromise.default;
utils.waitUntilDiscoConfirmed = function (_converse, entity_jid, identities, features) { utils.waitUntilDiscoConfirmed = function (_converse, entity_jid, identities, features, items, type) {
if (_.isNil(type)) {
type = 'info';
}
var IQ_disco, stanza; var IQ_disco, stanza;
return utils.waitUntil(function () { return utils.waitUntil(function () {
IQ_disco = _.filter(_converse.connection.IQ_stanzas, function (iq) { IQ_disco = _.filter(_converse.connection.IQ_stanzas, function (iq) {
return iq.nodeTree.querySelector('query[xmlns="http://jabber.org/protocol/disco#info"]') && return iq.nodeTree.querySelector('query[xmlns="http://jabber.org/protocol/disco#'+type+'"]') &&
iq.nodeTree.getAttribute('to') === entity_jid; iq.nodeTree.getAttribute('to') === entity_jid;
}).pop(); }).pop();
return !_.isUndefined(IQ_disco); return !_.isUndefined(IQ_disco);
...@@ -29,14 +32,17 @@ ...@@ -29,14 +32,17 @@
'from': entity_jid, 'from': entity_jid,
'to': 'dummy@localhost/resource', 'to': 'dummy@localhost/resource',
'id': info_IQ_id 'id': info_IQ_id
}).c('query', {'xmlns': 'http://jabber.org/protocol/disco#info'}); }).c('query', {'xmlns': 'http://jabber.org/protocol/disco#'+type});
_.forEach(identities, function (identity) { _.forEach(identities, function (identity) {
stanza.c('identity', {'category': 'pubsub', 'type': 'pep'}).up() stanza.c('identity', {'category': identity.category, 'type': identity.type}).up()
}); });
_.forEach(features, function (feature) { _.forEach(features, function (feature) {
stanza.c('feature', {'var': feature}).up(); stanza.c('feature', {'var': feature}).up();
}); });
_.forEach(items, function (item) {
stanza.c('item', {'jid': item}).up();
});
_converse.connection._dataRecv(utils.createRequest(stanza)); _converse.connection._dataRecv(utils.createRequest(stanza));
}); });
} }
......
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