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
901f7027
Commit
901f7027
authored
Jan 21, 2020
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
message-view: Re-use image element and fix autoscroll after image loads
parent
685c9585
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
21 deletions
+28
-21
spec/messages.js
spec/messages.js
+3
-6
src/converse-message-view.js
src/converse-message-view.js
+5
-1
src/utils/html.js
src/utils/html.js
+20
-14
No files found.
spec/messages.js
View file @
901f7027
...
...
@@ -1000,18 +1000,15 @@
expect
(
view
.
model
.
sendMessage
).
toHaveBeenCalled
();
let
msg
=
sizzle
(
'
.chat-content .chat-msg:last .chat-msg__text
'
).
pop
();
expect
(
msg
.
innerHTML
.
trim
()).
toEqual
(
'
<!-- src/templates/image.html -->
\n
'
+
'
<a href="
'
+
base_url
+
'
/logo/conversejs-filled.svg" target="_blank" rel="noopener"><img class="chat-image img-thumbnail"
'
+
'
src="
'
+
message
+
'
"></a>
'
);
`<a target="_blank" rel="noopener" href="
${
base_url
}
/logo/conversejs-filled.svg"><img src="
${
message
}
" class="chat-image img-thumbnail"></a>`
);
message
+=
"
?param1=val1¶m2=val2
"
;
test_utils
.
sendMessage
(
view
,
message
);
await
u
.
waitUntil
(()
=>
view
.
el
.
querySelectorAll
(
'
.chat-content .chat-image
'
).
length
===
2
,
1000
);
expect
(
view
.
model
.
sendMessage
).
toHaveBeenCalled
();
msg
=
sizzle
(
'
.chat-content .chat-msg:last .chat-msg__text
'
).
pop
();
expect
(
msg
.
innerHTML
.
trim
()).
toEqual
(
'
<!-- src/templates/image.html -->
\n
'
+
'
<a href="
'
+
base_url
+
'
/logo/conversejs-filled.svg?param1=val1&param2=val2" target="_blank" rel="noopener"><img
'
+
'
class="chat-image img-thumbnail" src="
'
+
message
.
replace
(
/&/g
,
'
&
'
)
+
'
"></a>
'
)
'
<a target="_blank" rel="noopener" href="
'
+
base_url
+
'
/logo/conversejs-filled.svg?param1=val1&param2=val2"><img
'
+
'
src="
'
+
message
.
replace
(
/&/g
,
'
&
'
)
+
'
" class="chat-image img-thumbnail"></a>
'
)
// Test now with two images in one message
message
+=
'
hello world
'
+
base_url
+
"
/logo/conversejs-filled.svg
"
;
...
...
src/converse-message-view.js
View file @
901f7027
...
...
@@ -276,7 +276,7 @@ converse.plugins.add('converse-message-view', {
if
(
text
&&
text
!==
url
)
{
msg_content
.
innerHTML
=
await
this
.
transformBodyText
(
text
);
if
(
_converse
.
show_images_inline
)
{
await
u
.
renderImageURLs
(
_converse
,
msg_content
);
u
.
renderImageURLs
(
_converse
,
msg_content
).
then
(()
=>
this
.
triggerRendered
()
);
}
}
}
...
...
@@ -284,6 +284,10 @@ converse.plugins.add('converse-message-view', {
this
.
renderAvatar
(
msg
);
}
this
.
replaceElement
(
msg
);
this
.
triggerRendered
();
},
triggerRendered
()
{
if
(
this
.
model
.
collection
)
{
// If the model gets destroyed in the meantime, it no
// longer has a collection.
...
...
src/utils/html.js
View file @
901f7027
...
...
@@ -54,14 +54,12 @@ function slideOutWrapup (el) {
function
isImage
(
url
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
var
img
=
new
Image
();
var
timer
=
window
.
setTimeout
(
function
()
{
reject
(
new
Error
(
"
Could not determine whether it's an image
"
));
img
=
null
;
},
3000
);
const
err_msg
=
`Could not determine whether it's an image:
${
url
}
`
;
const
img
=
new
Image
();
const
timer
=
window
.
setTimeout
(()
=>
reject
(
new
Error
(
err_msg
)),
3000
);
img
.
onerror
=
img
.
onabort
=
function
()
{
clearTimeout
(
timer
);
reject
(
new
Error
(
"
Could not determine whether it's an image
"
));
reject
(
new
Error
(
err_msg
));
};
img
.
onload
=
function
()
{
clearTimeout
(
timer
);
...
...
@@ -182,15 +180,23 @@ u.applyDragResistance = function (value, default_value) {
};
function
renderImage
(
img_url
,
link_url
,
el
,
callback
)
{
async
function
renderImage
(
img_url
,
link_url
,
el
,
callback
)
{
if
(
u
.
isImageURL
(
img_url
))
{
return
isImage
(
img_url
)
.
then
(()
=>
sizzle
(
`a[href="
${
link_url
}
"]`
,
el
).
forEach
(
a
=>
(
a
.
outerHTML
=
tpl_image
({
'
url
'
:
img_url
}))))
.
then
(
callback
)
.
catch
(
callback
);
}
else
{
return
callback
();
let
img
;
try
{
img
=
await
isImage
(
img_url
);
}
catch
(
e
)
{
log
.
error
(
e
);
return
callback
();
}
sizzle
(
`a[href="
${
link_url
}
"]`
,
el
).
forEach
(
a
=>
{
a
.
innerHTML
=
""
;
u
.
addClass
(
'
chat-image
'
,
img
);
u
.
addClass
(
'
img-thumbnail
'
,
img
);
a
.
insertAdjacentElement
(
'
afterBegin
'
,
img
);
});
}
callback
();
}
...
...
@@ -208,7 +214,7 @@ u.renderImageURLs = function (_converse, el) {
const
list
=
el
.
textContent
.
match
(
URL_REGEX
)
||
[];
return
Promise
.
all
(
list
.
map
(
url
=>
new
Promise
(
(
resolve
)
=>
{
new
Promise
(
resolve
=>
{
if
(
url
.
startsWith
(
'
https://imgur.com
'
)
&&
!
u
.
isImageURL
(
url
))
{
const
imgur_url
=
url
+
'
.png
'
;
renderImage
(
imgur_url
,
url
,
el
,
resolve
);
...
...
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