Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
042c1947
Commit
042c1947
authored
Mar 29, 2018
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add file-upload button
parent
a9d28818
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
15 deletions
+50
-15
spec/http-file-upload.js
spec/http-file-upload.js
+24
-6
src/converse-http-file-upload.js
src/converse-http-file-upload.js
+14
-4
src/converse-mam.js
src/converse-mam.js
+1
-1
src/templates/toolbar_fileupload.html
src/templates/toolbar_fileupload.html
+1
-0
tests/utils.js
tests/utils.js
+10
-4
No files found.
spec/http-file-upload.js
View file @
042c1947
...
...
@@ -23,7 +23,8 @@
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
_converse
.
bare_jid
,
[],
[]).
then
(
function
()
{
test_utils
.
waitUntil
(
function
()
{
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
;
},
300
).
then
(
function
()
{
/* <iq type='result'
...
...
@@ -40,7 +41,8 @@
* </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
];
var
info_IQ_id
=
IQ_ids
[
IQ_stanzas
.
indexOf
(
stanza
)];
...
...
@@ -174,10 +176,26 @@
describe
(
"
A file upload toolbar button
"
,
function
()
{
it
(
"
appears in private chats
"
,
mock
.
initConverseWithAsync
(
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
var
contact_jid
=
mock
.
cur_names
[
2
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
);
done
();
test_utils
.
waitUntilDiscoConfirmed
(
_converse
,
_converse
.
domain
,
[{
'
category
'
:
'
server
'
,
'
type
'
:
'
IM
'
}],
[
'
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
)
{
...
...
src/converse-http-file-upload.js
View file @
042c1947
(
function
(
root
,
factory
)
{
define
([
"
converse-core
"
],
factory
);
}(
this
,
function
(
converse
)
{
define
([
"
converse-core
"
,
"
tpl!toolbar_fileupload
"
],
factory
);
}(
this
,
function
(
converse
,
tpl_toolbar_fileupload
)
{
"
use strict
"
;
const
{
Promise
,
Strophe
,
_
}
=
converse
.
env
;
...
...
@@ -25,14 +28,21 @@
ChatBoxView
:
{
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
)
{
const
{
_converse
}
=
this
.
__super__
;
const
result
=
this
.
__super__
.
renderToolbar
.
apply
(
this
,
arguments
);
// TODO: check results.length
_converse
.
api
.
disco
.
supports
(
Strophe
.
NS
.
HTTPUPLOAD
,
_converse
.
domain
)
.
then
(
this
.
addFileUploadButton
.
bind
(
this
));
.
then
((
result
)
=>
{
if
(
result
.
length
)
{
this
.
addFileUploadButton
();
}
});
return
result
;
}
}
...
...
src/converse-mam.js
View file @
042c1947
...
...
@@ -155,7 +155,7 @@
const
{
_converse
}
=
this
.
__super__
;
_converse
.
api
.
disco
.
supports
(
Strophe
.
NS
.
MAM
,
_converse
.
bare_jid
).
then
(
(
results
)
=>
{
// Success
if
(
result
.
length
)
{
if
(
result
s
.
length
)
{
const
most_recent_msg
=
utils
.
getMostRecentMessage
(
this
.
model
);
if
(
_
.
isNil
(
most_recent_msg
))
{
this
.
fetchArchivedMessages
();
...
...
src/templates/toolbar_fileupload.html
0 → 100644
View file @
042c1947
<li
class=
"upload-file fa fa-paperclip"
title=
"{{{o.tooltip_upload_file}}}"
></li>
tests/utils.js
View file @
042c1947
...
...
@@ -14,11 +14,14 @@
}
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
;
return
utils
.
waitUntil
(
function
()
{
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
;
}).
pop
();
return
!
_
.
isUndefined
(
IQ_disco
);
...
...
@@ -29,14 +32,17 @@
'
from
'
:
entity_jid
,
'
to
'
:
'
dummy@localhost/resource
'
,
'
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
)
{
stanza
.
c
(
'
identity
'
,
{
'
category
'
:
'
pubsub
'
,
'
type
'
:
'
pep
'
}).
up
()
stanza
.
c
(
'
identity
'
,
{
'
category
'
:
identity
.
category
,
'
type
'
:
identity
.
type
}).
up
()
});
_
.
forEach
(
features
,
function
(
feature
)
{
stanza
.
c
(
'
feature
'
,
{
'
var
'
:
feature
}).
up
();
});
_
.
forEach
(
items
,
function
(
item
)
{
stanza
.
c
(
'
item
'
,
{
'
jid
'
:
item
}).
up
();
});
_converse
.
connection
.
_dataRecv
(
utils
.
createRequest
(
stanza
));
});
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment