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
d6da643a
Commit
d6da643a
authored
Feb 02, 2018
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add an (incomplete) test for a received spoiler message
parent
b1ffb34b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
22 deletions
+53
-22
spec/spoilers.js
spec/spoilers.js
+40
-0
src/converse-spoilers.js
src/converse-spoilers.js
+13
-22
No files found.
spec/spoilers.js
View file @
d6da643a
...
...
@@ -9,9 +9,49 @@
}
(
this
,
function
(
jasmine
,
utils
,
mock
,
converse
,
test_utils
)
{
var
_
=
converse
.
env
.
_
;
var
$msg
=
converse
.
env
.
$msg
;
return
describe
(
"
A spoiler message
"
,
function
()
{
it
(
"
can be received with a hint
"
,
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
function
(
done
,
_converse
)
{
test_utils
.
createContacts
(
_converse
,
'
current
'
);
var
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
/* <message to='romeo@montague.net/orchard' from='juliet@capulet.net/balcony' id='spoiler2'>
* <body>And at the end of the story, both of them die! It is so tragic!</body>
* <spoiler xmlns='urn:xmpp:spoiler:0'>Love story end</spoiler>
* </message>
*/
const
spoiler_hint
=
"
Love story end
"
const
spoiler
=
"
And at the end of the story, both of them die! It is so tragic!
"
;
var
msg
=
$msg
({
'
xmlns
'
:
'
jabber:client
'
,
'
to
'
:
_converse
.
bare_jid
,
'
from
'
:
sender_jid
,
'
type
'
:
'
chat
'
}).
c
(
'
body
'
).
t
(
spoiler
).
up
()
.
c
(
'
spoiler
'
,
{
'
xmlns
'
:
'
urn:xmpp:spoiler:0
'
,
}).
t
(
spoiler_hint
)
.
tree
();
_converse
.
chatboxes
.
onMessage
(
msg
);
var
chatboxview
=
_converse
.
chatboxviews
.
get
(
sender_jid
);
var
message_content
=
chatboxview
.
el
.
querySelector
(
'
.chat-message .chat-msg-content
'
);
// TODO add better assertions, currently only checks whether the
// text is in the DOM, not whether the spoiler is shown or
// not. Before updating this the spoiler rendering code needs
// improvement.
expect
(
_
.
includes
(
message_content
.
outerHTML
,
spoiler_hint
)).
toBeTruthy
();
expect
(
_
.
includes
(
message_content
.
outerHTML
,
spoiler
)).
toBeTruthy
();
done
();
}));
it
(
"
can be sent without a hint
"
,
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
...
...
src/converse-spoilers.js
View file @
d6da643a
...
...
@@ -173,9 +173,9 @@
const
msg
=
this
.
__super__
.
renderMessage
.
apply
(
this
,
arguments
);
console
.
log
(
msg
);
//Spoiler logic
//The value of the "spoiler" attribute, corresponds to the spoiler's hint.
if
(
"
spoiler
"
in
attrs
)
{
//
Spoiler logic
//
The value of the "spoiler" attribute, corresponds to the spoiler's hint.
if
(
attrs
.
is_spoiler
)
{
console
.
log
(
'
Spoiler in attrs
\n
'
);
const
button
=
document
.
createElement
(
"
button
"
);
const
container
=
document
.
createElement
(
"
div
"
);
...
...
@@ -184,7 +184,7 @@
const
contentHidden
=
document
.
createElement
(
"
div
"
);
const
messageContent
=
msg
.
querySelector
(
"
.chat-msg-content
"
);
hint
.
appendChild
(
document
.
createTextNode
(
attrs
.
spoiler
));
hint
.
appendChild
(
document
.
createTextNode
(
attrs
.
spoiler
_hint
));
for
(
var
i
=
0
;
i
<
messageContent
.
childNodes
.
length
;
i
++
){
contentHidden
.
append
(
messageContent
.
childNodes
[
i
]);
...
...
@@ -218,30 +218,21 @@
messageContent
.
append
(
document
.
createElement
(
"
br
"
));
messageContent
.
append
(
container
);
}
return
msg
;
}
},
'
ChatBox
'
:
{
'
getMessageAttributes
'
:
function
(
message
,
delay
,
original_stanza
)
{
const
{
_converse
}
=
this
.
__super__
,
{
__
}
=
_converse
;
const
messageAttributes
=
this
.
__super__
.
getMessageAttributes
.
apply
(
this
,
arguments
);
console
.
log
(
arguments
);
//Check if message is spoiler
let
spoiler
=
null
,
i
=
0
,
found
=
false
;
while
(
i
<
message
.
childNodes
.
length
&&
!
found
)
{
if
(
message
.
childNodes
[
i
].
nodeName
==
"
spoiler
"
)
{
spoiler
=
message
.
childNodes
[
i
];
found
=
true
;
}
i
++
;
}
getMessageAttributes
(
message
,
delay
,
original_stanza
)
{
const
attrs
=
this
.
__super__
.
getMessageAttributes
.
apply
(
this
,
arguments
);
const
spoiler
=
message
.
querySelector
(
`spoiler[xmlns="
${
Strophe
.
NS
.
SPOILER
}
"]`
)
if
(
spoiler
)
{
messageAttributes
.
spoiler
=
spoiler
.
textContent
.
length
>
0
?
spoiler
.
textContent
:
__
(
'
Spoiler
'
);
const
{
__
}
=
this
.
__super__
.
_converse
;
attrs
.
is_spoiler
=
true
;
attrs
.
spoiler_hint
=
spoiler
.
textContent
.
length
>
0
?
spoiler
.
textContent
:
__
(
'
Spoiler
'
);
}
return
messageAttribute
s
;
return
attr
s
;
}
}
},
...
...
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