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
502d2aa0
Commit
502d2aa0
authored
Aug 13, 2019
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
converse-message-view: Refactor to not use _.partial or _.flow
parent
89ac4a69
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
22 deletions
+26
-22
src/converse-message-view.js
src/converse-message-view.js
+26
-22
No files found.
src/converse-message-view.js
View file @
502d2aa0
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
*/
*/
import
URI
from
"
urijs
"
;
import
URI
from
"
urijs
"
;
import
converse
from
"
@converse/headless/converse-core
"
;
import
converse
from
"
@converse/headless/converse-core
"
;
import
{
debounce
}
from
'
lodash
'
import
filesize
from
"
filesize
"
;
import
filesize
from
"
filesize
"
;
import
html
from
"
./utils/html
"
;
import
html
from
"
./utils/html
"
;
import
tpl_csn
from
"
templates/csn.html
"
;
import
tpl_csn
from
"
templates/csn.html
"
;
...
@@ -19,7 +20,7 @@ import tpl_spinner from "templates/spinner.html";
...
@@ -19,7 +20,7 @@ import tpl_spinner from "templates/spinner.html";
import
u
from
"
@converse/headless/utils/emoji
"
;
import
u
from
"
@converse/headless/utils/emoji
"
;
import
xss
from
"
xss/dist/xss
"
;
import
xss
from
"
xss/dist/xss
"
;
const
{
Backbone
,
_
,
dayjs
}
=
converse
.
env
;
const
{
Backbone
,
dayjs
}
=
converse
.
env
;
converse
.
plugins
.
add
(
'
converse-message-view
'
,
{
converse
.
plugins
.
add
(
'
converse-message-view
'
,
{
...
@@ -52,7 +53,7 @@ converse.plugins.add('converse-message-view', {
...
@@ -52,7 +53,7 @@ converse.plugins.add('converse-message-view', {
}
}
const
uri
=
new
URI
(
tag
);
const
uri
=
new
URI
(
tag
);
const
protocol
=
uri
.
protocol
().
toLowerCase
();
const
protocol
=
uri
.
protocol
().
toLowerCase
();
if
(
!
_
.
includes
([
"
https
"
,
"
http
"
,
"
xmpp
"
,
"
ftp
"
],
protocol
))
{
if
(
!
[
"
https
"
,
"
http
"
,
"
xmpp
"
,
"
ftp
"
].
includes
(
protocol
))
{
// Not a URL, the tag will get filtered as usual
// Not a URL, the tag will get filtered as usual
return
;
return
;
}
}
...
@@ -86,7 +87,7 @@ converse.plugins.add('converse-message-view', {
...
@@ -86,7 +87,7 @@ converse.plugins.add('converse-message-view', {
},
},
initialize
()
{
initialize
()
{
this
.
debouncedRender
=
_
.
debounce
(()
=>
{
this
.
debouncedRender
=
debounce
(()
=>
{
// If the model gets destroyed in the meantime,
// If the model gets destroyed in the meantime,
// it no longer has a collection
// it no longer has a collection
if
(
this
.
model
.
collection
)
{
if
(
this
.
model
.
collection
)
{
...
@@ -148,8 +149,8 @@ converse.plugins.add('converse-message-view', {
...
@@ -148,8 +149,8 @@ converse.plugins.add('converse-message-view', {
if
(
this
.
model
.
changed
.
progress
)
{
if
(
this
.
model
.
changed
.
progress
)
{
return
this
.
renderFileUploadProgresBar
();
return
this
.
renderFileUploadProgresBar
();
}
}
if
(
_
.
filter
([
'
correcting
'
,
'
message
'
,
'
type
'
,
'
upload
'
,
'
received
'
],
const
isValidChange
=
prop
=>
Object
.
prototype
.
hasOwnProperty
.
call
(
this
.
model
.
changed
,
prop
);
prop
=>
Object
.
prototype
.
hasOwnProperty
.
call
(
this
.
model
.
changed
,
prop
)
).
length
)
{
if
([
'
correcting
'
,
'
message
'
,
'
type
'
,
'
upload
'
,
'
received
'
].
filter
(
isValidChange
).
length
)
{
await
this
.
debouncedRender
();
await
this
.
debouncedRender
();
}
}
if
(
edited
)
{
if
(
edited
)
{
...
@@ -196,6 +197,23 @@ converse.plugins.add('converse-message-view', {
...
@@ -196,6 +197,23 @@ converse.plugins.add('converse-message-view', {
return
this
.
el
;
return
this
.
el
;
},
},
transformOOBURL
(
url
)
{
url
=
u
.
renderFileURL
(
_converse
,
url
);
url
=
u
.
renderMovieURL
(
_converse
,
url
);
url
=
u
.
renderAudioURL
(
_converse
,
url
);
return
u
.
renderImageURL
(
_converse
,
url
);
},
transformBodyText
(
text
)
{
text
=
this
.
isMeCommand
()
?
text
.
substring
(
4
)
:
text
;
text
=
xss
.
filterXSS
(
text
,
{
'
whiteList
'
:
{},
'
onTag
'
:
onTagFoundDuringXSSFilter
});
text
=
u
.
geoUriToHttp
(
text
,
_converse
.
geouri_replacement
);
text
=
u
.
addMentionsMarkup
(
text
,
this
.
model
.
get
(
'
references
'
),
this
.
model
.
collection
.
chatbox
);
text
=
u
.
addHyperlinks
(
text
);
text
=
u
.
renderNewLines
(
text
);
return
u
.
addEmoji
(
_converse
,
text
);
},
async
renderChatMessage
()
{
async
renderChatMessage
()
{
const
is_me_message
=
this
.
isMeCommand
();
const
is_me_message
=
this
.
isMeCommand
();
const
time
=
dayjs
(
this
.
model
.
get
(
'
time
'
));
const
time
=
dayjs
(
this
.
model
.
get
(
'
time
'
));
...
@@ -220,27 +238,13 @@ converse.plugins.add('converse-message-view', {
...
@@ -220,27 +238,13 @@ converse.plugins.add('converse-message-view', {
const
url
=
this
.
model
.
get
(
'
oob_url
'
);
const
url
=
this
.
model
.
get
(
'
oob_url
'
);
if
(
url
)
{
if
(
url
)
{
msg
.
querySelector
(
'
.chat-msg__media
'
).
innerHTML
=
_
.
flow
(
msg
.
querySelector
(
'
.chat-msg__media
'
).
innerHTML
=
this
.
transformOOBURL
(
url
);
_
.
partial
(
u
.
renderFileURL
,
_converse
),
_
.
partial
(
u
.
renderMovieURL
,
_converse
),
_
.
partial
(
u
.
renderAudioURL
,
_converse
),
_
.
partial
(
u
.
renderImageURL
,
_converse
))(
url
);
}
}
le
t
text
=
this
.
getMessageText
();
cons
t
text
=
this
.
getMessageText
();
const
msg_content
=
msg
.
querySelector
(
'
.chat-msg__text
'
);
const
msg_content
=
msg
.
querySelector
(
'
.chat-msg__text
'
);
if
(
text
&&
text
!==
url
)
{
if
(
text
&&
text
!==
url
)
{
if
(
is_me_message
)
{
msg_content
.
innerHTML
=
this
.
transformBodyText
(
text
);
text
=
text
.
substring
(
4
);
}
text
=
xss
.
filterXSS
(
text
,
{
'
whiteList
'
:
{},
'
onTag
'
:
onTagFoundDuringXSSFilter
});
msg_content
.
innerHTML
=
_
.
flow
(
_
.
partial
(
u
.
geoUriToHttp
,
_
,
_converse
.
geouri_replacement
),
_
.
partial
(
u
.
addMentionsMarkup
,
_
,
this
.
model
.
get
(
'
references
'
),
this
.
model
.
collection
.
chatbox
),
u
.
addHyperlinks
,
u
.
renderNewLines
,
_
.
partial
(
u
.
addEmoji
,
_converse
,
_
)
)(
text
);
}
}
const
promise
=
u
.
renderImageURLs
(
_converse
,
msg_content
);
const
promise
=
u
.
renderImageURLs
(
_converse
,
msg_content
);
if
(
this
.
model
.
get
(
'
type
'
)
!==
'
headline
'
)
{
if
(
this
.
model
.
get
(
'
type
'
)
!==
'
headline
'
)
{
...
...
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