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
3b1d2763
Commit
3b1d2763
authored
Apr 12, 2018
by
worlword
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
problem fixed, that file-upload would not start. Also did some code cleanup
parent
ca40cf65
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
44 deletions
+16
-44
src/converse-chatboxes.js
src/converse-chatboxes.js
+4
-20
src/converse-chatview.js
src/converse-chatview.js
+3
-5
src/converse-http-file-upload.js
src/converse-http-file-upload.js
+8
-18
src/templates/toolbar_fileupload.html
src/templates/toolbar_fileupload.html
+1
-1
No files found.
src/converse-chatboxes.js
View file @
3b1d2763
...
@@ -131,22 +131,16 @@
...
@@ -131,22 +131,16 @@
sendFile
(
file
,
chatbox
)
{
sendFile
(
file
,
chatbox
)
{
const
self
=
this
;
const
self
=
this
;
console
.
log
(
'
Send file via http upload
'
);
const
request_slot_url
=
'
upload.
'
+
_converse
.
domain
;
const
request_slot_url
=
'
upload.
'
+
_converse
.
domain
;
_converse
.
api
.
disco
.
supports
(
Strophe
.
NS
.
HTTPUPLOAD
,
request_slot_url
)
_converse
.
api
.
disco
.
supports
(
Strophe
.
NS
.
HTTPUPLOAD
,
request_slot_url
)
.
then
((
result
)
=>
{
.
then
((
result
)
=>
{
chatbox
.
showHelpMessages
([
__
(
'
The file upload starts now
'
)],
'
info
'
);
chatbox
.
showHelpMessages
([
__
(
'
The file upload starts now
'
)],
'
info
'
);
self
.
requestSlot
(
file
,
request_slot_url
,
function
(
data
)
{
self
.
requestSlot
(
file
,
request_slot_url
,
function
(
data
)
{
if
(
!
data
)
{
if
(
!
data
)
{
// general error
console
.
log
(
'
Unknown error while requesting upload slot.
'
);
alert
(
__
(
'
File upload failed. Please check the log.
'
));
alert
(
__
(
'
File upload failed. Please check the log.
'
));
}
else
if
(
data
.
error
)
{
}
else
if
(
data
.
error
)
{
// specific error
console
.
log
(
'
The XMPP-Server return an error of the type:
'
+
data
.
error
.
type
);
alert
(
__
(
'
File upload failed. Please check the log.
'
));
alert
(
__
(
'
File upload failed. Please check the log.
'
));
}
else
if
(
data
.
get
&&
data
.
put
)
{
}
else
if
(
data
.
get
&&
data
.
put
)
{
console
.
log
(
'
slot received, start upload to
'
+
data
.
put
);
self
.
uploadFile
(
data
.
put
,
file
,
function
()
{
self
.
uploadFile
(
data
.
put
,
file
,
function
()
{
console
.
log
(
data
.
put
);
console
.
log
(
data
.
put
);
chatbox
.
onMessageSubmitted
(
data
.
put
,
null
,
file
);
chatbox
.
onMessageSubmitted
(
data
.
put
,
null
,
file
);
...
@@ -175,7 +169,7 @@
...
@@ -175,7 +169,7 @@
});
});
},
},
uploadFile
(
url
,
file
,
success_cb
)
{
uploadFile
(
url
,
file
,
callback
)
{
console
.
log
(
"
uploadFile start
"
);
console
.
log
(
"
uploadFile start
"
);
const
xmlhttp
=
new
XMLHttpRequest
();
const
xmlhttp
=
new
XMLHttpRequest
();
const
contentType
=
'
application/octet-stream
'
;
const
contentType
=
'
application/octet-stream
'
;
...
@@ -183,13 +177,11 @@
...
@@ -183,13 +177,11 @@
if
(
xmlhttp
.
readyState
===
XMLHttpRequest
.
DONE
)
{
if
(
xmlhttp
.
readyState
===
XMLHttpRequest
.
DONE
)
{
console
.
log
(
"
Status:
"
+
xmlhttp
.
status
);
console
.
log
(
"
Status:
"
+
xmlhttp
.
status
);
if
(
xmlhttp
.
status
===
200
||
xmlhttp
.
status
===
201
)
{
if
(
xmlhttp
.
status
===
200
||
xmlhttp
.
status
===
201
)
{
console
.
log
(
'
file successful uploaded
'
);
if
(
callback
)
{
if
(
success_cb
)
{
callback
();
success_cb
();
}
}
}
}
else
{
else
{
console
.
log
(
'
error while uploading file to
'
+
url
);
alert
(
__
(
'
Could not upload File please try again.
'
));
alert
(
__
(
'
Could not upload File please try again.
'
));
}
}
}
}
...
@@ -198,13 +190,8 @@
...
@@ -198,13 +190,8 @@
xmlhttp
.
open
(
'
PUT
'
,
url
,
true
);
xmlhttp
.
open
(
'
PUT
'
,
url
,
true
);
xmlhttp
.
setRequestHeader
(
"
Content-type
"
,
contentType
);
xmlhttp
.
setRequestHeader
(
"
Content-type
"
,
contentType
);
xmlhttp
.
send
(
file
);
xmlhttp
.
send
(
file
);
console
.
log
(
"
uploadFile end
"
);
},
},
/**
* Process successful response to slot request.
*/
successfulRequestSlotCB
(
stanza
,
cb
)
{
successfulRequestSlotCB
(
stanza
,
cb
)
{
const
slot
=
stanza
.
getElementsByTagName
(
'
slot
'
)[
0
];
const
slot
=
stanza
.
getElementsByTagName
(
'
slot
'
)[
0
];
...
@@ -220,9 +207,6 @@
...
@@ -220,9 +207,6 @@
}
}
},
},
/**
* Process failed response to slot request.
*/
failedRequestSlotCB
(
stanza
,
cb
)
{
failedRequestSlotCB
(
stanza
,
cb
)
{
alert
(
__
(
'
Could not upload File please try again.
'
));
alert
(
__
(
'
Could not upload File please try again.
'
));
},
},
...
...
src/converse-chatview.js
View file @
3b1d2763
...
@@ -116,8 +116,7 @@
...
@@ -116,8 +116,7 @@
'
call
'
:
false
,
'
call
'
:
false
,
'
clear
'
:
true
,
'
clear
'
:
true
,
'
emoji
'
:
true
,
'
emoji
'
:
true
,
'
spoiler
'
:
true
,
'
spoiler
'
:
true
'
fileUpload
'
:
true
},
},
});
});
emojione
.
imagePathPNG
=
_converse
.
emojione_image_path
;
emojione
.
imagePathPNG
=
_converse
.
emojione_image_path
;
...
@@ -379,7 +378,6 @@
...
@@ -379,7 +378,6 @@
'
label_toggle_spoiler
'
:
label_toggle_spoiler
,
'
label_toggle_spoiler
'
:
label_toggle_spoiler
,
'
show_call_button
'
:
_converse
.
visible_toolbar_buttons
.
call
,
'
show_call_button
'
:
_converse
.
visible_toolbar_buttons
.
call
,
'
show_spoiler_button
'
:
_converse
.
visible_toolbar_buttons
.
spoiler
,
'
show_spoiler_button
'
:
_converse
.
visible_toolbar_buttons
.
spoiler
,
'
show_fileUpload_button
'
:
_converse
.
visible_toolbar_buttons
.
fileUpload
,
'
use_emoji
'
:
_converse
.
visible_toolbar_buttons
.
emoji
,
'
use_emoji
'
:
_converse
.
visible_toolbar_buttons
.
emoji
,
});
});
},
},
...
@@ -818,7 +816,7 @@
...
@@ -818,7 +816,7 @@
return
stanza
;
return
stanza
;
},
},
sendMessage
(
message
,
file
=
null
)
{
sendMessage
(
message
,
file
=
null
)
{
/* Responsible for sending off a text message.
/* Responsible for sending off a text message.
*
*
* Parameters:
* Parameters:
...
@@ -828,7 +826,7 @@
...
@@ -828,7 +826,7 @@
// Especially in the OTR case.
// Especially in the OTR case.
var
messageStanza
;
var
messageStanza
;
if
(
file
!==
null
)
{
if
(
file
!==
null
)
{
messageStanza
=
this
.
createFileMessageStanza
(
message
,
this
.
model
.
get
(
'
jid
'
));
messageStanza
=
this
.
model
.
createFileMessageStanza
(
message
,
this
.
model
.
get
(
'
jid
'
));
}
}
else
{
else
{
messageStanza
=
this
.
createMessageStanza
(
message
);
messageStanza
=
this
.
createMessageStanza
(
message
);
...
...
src/converse-http-file-upload.js
View file @
3b1d2763
...
@@ -22,7 +22,6 @@
...
@@ -22,7 +22,6 @@
overrides
:
{
overrides
:
{
ChatBoxView
:
{
ChatBoxView
:
{
events
:
{
events
:
{
'
click .toggle-fileUpload
'
:
'
toggleFileUpload
'
,
'
click .toggle-fileUpload
'
:
'
toggleFileUpload
'
,
'
change .fileUpload_input
'
:
'
handleFileSelect
'
'
change .fileUpload_input
'
:
'
handleFileSelect
'
...
@@ -35,18 +34,6 @@
...
@@ -35,18 +34,6 @@
tpl_toolbar_fileupload
({
'
label_upload_file
'
:
__
(
'
Choose a file to send
'
)}));
tpl_toolbar_fileupload
({
'
label_upload_file
'
:
__
(
'
Choose a file to send
'
)}));
},
},
renderToolbar
(
toolbar
,
options
)
{
const
{
_converse
}
=
this
.
__super__
;
const
result
=
this
.
__super__
.
renderToolbar
.
apply
(
this
,
arguments
);
_converse
.
api
.
disco
.
supports
(
Strophe
.
NS
.
HTTPUPLOAD
,
'
upload.
'
+
_converse
.
domain
)
.
then
((
result
)
=>
{
if
(
result
.
supported
)
{
this
.
addFileUploadButton
();
}
});
return
result
;
},
toggleFileUpload
(
ev
)
{
toggleFileUpload
(
ev
)
{
this
.
el
.
querySelector
(
'
.fileUpload_input
'
).
click
();
this
.
el
.
querySelector
(
'
.fileUpload_input
'
).
click
();
},
},
...
@@ -55,21 +42,24 @@
...
@@ -55,21 +42,24 @@
var
files
=
evt
.
target
.
files
;
var
files
=
evt
.
target
.
files
;
var
file
=
files
[
0
];
var
file
=
files
[
0
];
this
.
model
.
sendFile
(
file
,
this
);
this
.
model
.
sendFile
(
file
,
this
);
}
},
renderToolbar
(
toolbar
,
options
)
{
const
result
=
this
.
__super__
.
renderToolbar
.
apply
(
this
,
arguments
);
this
.
addFileUploadButton
();
return
result
;
},
},
},
ChatRoomView
:
{
ChatRoomView
:
{
events
:
{
events
:
{
'
click .toggle-fileUpload
'
:
'
toggleFileUpload
'
,
'
click .toggle-fileUpload
'
:
'
toggleFileUpload
'
,
'
change .fileUpload_input
'
:
'
handleFileSelect
'
,
'
change .fileUpload_input
'
:
'
handleFileSelect
'
}
}
}
}
},
},
initialize
()
{
initialize
()
{
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
*/
const
{
_converse
}
=
this
,
const
{
_converse
}
=
this
,
{
__
}
=
_converse
;
{
__
}
=
_converse
;
}
}
...
...
src/templates/toolbar_fileupload.html
View file @
3b1d2763
<input
type=
"file"
class=
"fileUpload_input"
style=
"display:none"
/>
<input
type=
"file"
class=
"fileUpload_input"
style=
"display:none"
/>
<li
class=
"toggle-fileUpload"
>
<li
class=
"toggle-fileUpload"
>
<a
class=
"fa fa-paperclip"
title=
"{{{o.label_upload_file}}}"
></a>
<a
class=
"fa fa-paperclip"
title=
"{{{o.label_upload_file}}}"
></a>
</li>
</li>
\ No newline at end of file
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