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
234b273c
Commit
234b273c
authored
Jan 21, 2020
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
message-view: Add support for rendering Imgur URLs
parent
b0a9782d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
14 deletions
+19
-14
src/converse-message-view.js
src/converse-message-view.js
+3
-1
src/utils/html.js
src/utils/html.js
+16
-13
No files found.
src/converse-message-view.js
View file @
234b273c
...
@@ -275,9 +275,11 @@ converse.plugins.add('converse-message-view', {
...
@@ -275,9 +275,11 @@ converse.plugins.add('converse-message-view', {
const
msg_content
=
msg
.
querySelector
(
'
.chat-msg__text
'
);
const
msg_content
=
msg
.
querySelector
(
'
.chat-msg__text
'
);
if
(
text
&&
text
!==
url
)
{
if
(
text
&&
text
!==
url
)
{
msg_content
.
innerHTML
=
await
this
.
transformBodyText
(
text
);
msg_content
.
innerHTML
=
await
this
.
transformBodyText
(
text
);
if
(
_converse
.
show_images_inline
)
{
await
u
.
renderImageURLs
(
_converse
,
msg_content
);
await
u
.
renderImageURLs
(
_converse
,
msg_content
);
}
}
}
}
}
if
(
this
.
model
.
get
(
'
type
'
)
!==
'
headline
'
)
{
if
(
this
.
model
.
get
(
'
type
'
)
!==
'
headline
'
)
{
this
.
renderAvatar
(
msg
);
this
.
renderAvatar
(
msg
);
}
}
...
...
src/utils/html.js
View file @
234b273c
...
@@ -182,6 +182,18 @@ u.applyDragResistance = function (value, default_value) {
...
@@ -182,6 +182,18 @@ u.applyDragResistance = function (value, default_value) {
};
};
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
();
}
}
/**
/**
* Returns a Promise which resolves once all images have been loaded.
* Returns a Promise which resolves once all images have been loaded.
* @method u#renderImageURLs
* @method u#renderImageURLs
...
@@ -197,20 +209,11 @@ u.renderImageURLs = function (_converse, el) {
...
@@ -197,20 +209,11 @@ u.renderImageURLs = function (_converse, el) {
return
Promise
.
all
(
return
Promise
.
all
(
list
.
map
(
url
=>
list
.
map
(
url
=>
new
Promise
((
resolve
)
=>
{
new
Promise
((
resolve
)
=>
{
if
(
u
.
isImageURL
(
url
))
{
if
(
url
.
startsWith
(
'
https://imgur.com
'
)
&&
!
u
.
isImageURL
(
url
))
{
return
isImage
(
url
).
then
(
img
=>
{
const
imgur_url
=
url
+
'
.png
'
;
const
i
=
new
Image
();
renderImage
(
imgur_url
,
url
,
el
,
resolve
);
i
.
src
=
img
.
src
;
i
.
addEventListener
(
'
load
'
,
resolve
);
// We also resolve (instead of reject) for non-images,
// otherwise the Promise.all resolves prematurely.
i
.
addEventListener
(
'
error
'
,
resolve
);
const
{
__
}
=
_converse
;
sizzle
(
`a[href="
${
url
}
"]`
,
el
)
.
forEach
(
a
=>
(
a
.
outerHTML
=
tpl_image
({
url
,
'
label_download
'
:
__
(
'
Download
'
)})));
}).
catch
(
resolve
)
}
else
{
}
else
{
re
turn
resolve
(
);
re
nderImage
(
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