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
025cdbf1
Commit
025cdbf1
authored
Nov 20, 2019
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check for support before allowing message moderation
parent
ad77ba60
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
74 additions
and
26 deletions
+74
-26
spec/retractions.js
spec/retractions.js
+46
-10
src/converse-message-view.js
src/converse-message-view.js
+7
-3
src/headless/converse-muc.js
src/headless/converse-muc.js
+5
-0
src/templates/message.html
src/templates/message.html
+1
-2
tests/mock.js
tests/mock.js
+14
-0
tests/utils.js
tests/utils.js
+1
-11
No files found.
spec/retractions.js
View file @
025cdbf1
...
...
@@ -48,7 +48,8 @@
async
function
(
done
,
_converse
)
{
const
muc_jid
=
'
lounge@montague.lit
'
;
await
test_utils
.
openAndEnterChatRoom
(
_converse
,
muc_jid
,
'
romeo
'
);
const
features
=
[...
mock
.
default_muc_features
,
Strophe
.
NS
.
MODERATE
];
await
test_utils
.
openAndEnterChatRoom
(
_converse
,
muc_jid
,
'
romeo
'
,
features
);
const
received_stanza
=
u
.
toStanza
(
`
<message to='
${
_converse
.
jid
}
' from='
${
muc_jid
}
/eve' type='groupchat' id='
${
_converse
.
connection
.
getUniqueId
()}
'>
...
...
@@ -92,7 +93,8 @@
const
date
=
(
new
Date
()).
toISOString
();
const
muc_jid
=
'
lounge@montague.lit
'
;
await
test_utils
.
openAndEnterChatRoom
(
_converse
,
muc_jid
,
'
romeo
'
);
const
features
=
[...
mock
.
default_muc_features
,
Strophe
.
NS
.
MODERATE
];
await
test_utils
.
openAndEnterChatRoom
(
_converse
,
muc_jid
,
'
romeo
'
,
features
);
const
retraction_stanza
=
u
.
toStanza
(
`
<message type="groupchat" id='retraction-id-1' from="
${
muc_jid
}
/eve" to="
${
muc_jid
}
/romeo">
...
...
@@ -321,7 +323,8 @@
async
function
(
done
,
_converse
)
{
const
muc_jid
=
'
lounge@montague.lit
'
;
await
test_utils
.
openAndEnterChatRoom
(
_converse
,
muc_jid
,
'
romeo
'
);
const
features
=
[...
mock
.
default_muc_features
,
Strophe
.
NS
.
MODERATE
];
await
test_utils
.
openAndEnterChatRoom
(
_converse
,
muc_jid
,
'
romeo
'
,
features
);
const
received_stanza
=
u
.
toStanza
(
`
<message to='
${
_converse
.
jid
}
' from='
${
muc_jid
}
/eve' type='groupchat' id='
${
_converse
.
connection
.
getUniqueId
()}
'>
...
...
@@ -363,7 +366,9 @@
async
function
(
done
,
_converse
)
{
const
muc_jid
=
'
lounge@montague.lit
'
;
await
test_utils
.
openAndEnterChatRoom
(
_converse
,
muc_jid
,
'
romeo
'
);
const
features
=
[...
mock
.
default_muc_features
,
Strophe
.
NS
.
MODERATE
];
await
test_utils
.
openAndEnterChatRoom
(
_converse
,
muc_jid
,
'
romeo
'
,
features
);
const
view
=
_converse
.
api
.
chatviews
.
get
(
muc_jid
);
const
occupant
=
view
.
model
.
getOwnOccupant
();
expect
(
occupant
.
get
(
'
role
'
)).
toBe
(
'
moderator
'
);
...
...
@@ -439,6 +444,31 @@
done
();
}));
it
(
"
can not be retracted if the MUC doesn't support message moderation
"
,
mock
.
initConverse
(
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
async
function
(
done
,
_converse
)
{
const
muc_jid
=
'
lounge@montague.lit
'
;
await
test_utils
.
openAndEnterChatRoom
(
_converse
,
muc_jid
,
'
romeo
'
);
const
view
=
_converse
.
api
.
chatviews
.
get
(
muc_jid
);
const
occupant
=
view
.
model
.
getOwnOccupant
();
expect
(
occupant
.
get
(
'
role
'
)).
toBe
(
'
moderator
'
);
const
received_stanza
=
u
.
toStanza
(
`
<message to='
${
_converse
.
jid
}
' from='
${
muc_jid
}
/mallory' type='groupchat' id='
${
_converse
.
connection
.
getUniqueId
()}
'>
<body>Visit this site to get free Bitcoin!</body>
<stanza-id xmlns='urn:xmpp:sid:0' id='stanza-id-1' by='
${
muc_jid
}
'/>
</message>
`
);
await
view
.
model
.
onMessage
(
received_stanza
);
await
u
.
waitUntil
(()
=>
view
.
el
.
querySelector
(
'
.chat-msg__content
'
));
expect
(
view
.
el
.
querySelector
(
'
.chat-msg__content .chat-msg__action-retract
'
)).
toBe
(
null
);
const
result
=
await
view
.
model
.
canRetractMessages
();
expect
(
result
).
toBe
(
false
);
done
();
}));
it
(
"
can be retracted by a moderator, with the retraction message received before the IQ response
"
,
mock
.
initConverse
(
...
...
@@ -446,7 +476,8 @@
async
function
(
done
,
_converse
)
{
const
muc_jid
=
'
lounge@montague.lit
'
;
await
test_utils
.
openAndEnterChatRoom
(
_converse
,
muc_jid
,
'
romeo
'
);
const
features
=
[...
mock
.
default_muc_features
,
Strophe
.
NS
.
MODERATE
];
await
test_utils
.
openAndEnterChatRoom
(
_converse
,
muc_jid
,
'
romeo
'
,
features
);
const
view
=
_converse
.
api
.
chatviews
.
get
(
muc_jid
);
const
occupant
=
view
.
model
.
getOwnOccupant
();
expect
(
occupant
.
get
(
'
role
'
)).
toBe
(
'
moderator
'
);
...
...
@@ -514,7 +545,8 @@
async
function
(
done
,
_converse
)
{
const
muc_jid
=
'
lounge@montague.lit
'
;
await
test_utils
.
openAndEnterChatRoom
(
_converse
,
muc_jid
,
'
romeo
'
);
const
features
=
[...
mock
.
default_muc_features
,
Strophe
.
NS
.
MODERATE
];
await
test_utils
.
openAndEnterChatRoom
(
_converse
,
muc_jid
,
'
romeo
'
,
features
);
const
view
=
_converse
.
api
.
chatviews
.
get
(
muc_jid
);
const
occupant
=
view
.
model
.
getOwnOccupant
();
expect
(
occupant
.
get
(
'
role
'
)).
toBe
(
'
moderator
'
);
...
...
@@ -565,7 +597,8 @@
async
function
(
done
,
_converse
)
{
const
muc_jid
=
'
lounge@montague.lit
'
;
await
test_utils
.
openAndEnterChatRoom
(
_converse
,
muc_jid
,
'
romeo
'
);
const
features
=
[...
mock
.
default_muc_features
,
Strophe
.
NS
.
MODERATE
];
await
test_utils
.
openAndEnterChatRoom
(
_converse
,
muc_jid
,
'
romeo
'
,
features
);
const
view
=
_converse
.
api
.
chatviews
.
get
(
muc_jid
);
const
occupant
=
view
.
model
.
getOwnOccupant
();
expect
(
occupant
.
get
(
'
role
'
)).
toBe
(
'
moderator
'
);
...
...
@@ -615,7 +648,8 @@
_converse
.
STANZA_TIMEOUT
=
1
;
const
muc_jid
=
'
lounge@montague.lit
'
;
await
test_utils
.
openAndEnterChatRoom
(
_converse
,
muc_jid
,
'
romeo
'
);
const
features
=
[...
mock
.
default_muc_features
,
Strophe
.
NS
.
MODERATE
];
await
test_utils
.
openAndEnterChatRoom
(
_converse
,
muc_jid
,
'
romeo
'
,
features
);
const
view
=
_converse
.
api
.
chatviews
.
get
(
muc_jid
);
const
occupant
=
view
.
model
.
getOwnOccupant
();
expect
(
occupant
.
get
(
'
role
'
)).
toBe
(
'
moderator
'
);
...
...
@@ -740,7 +774,8 @@
async
function
(
done
,
_converse
)
{
const
muc_jid
=
'
lounge@montague.lit
'
;
await
test_utils
.
openAndEnterChatRoom
(
_converse
,
muc_jid
,
'
romeo
'
);
const
features
=
[...
mock
.
default_muc_features
,
Strophe
.
NS
.
MODERATE
];
await
test_utils
.
openAndEnterChatRoom
(
_converse
,
muc_jid
,
'
romeo
'
,
features
);
const
view
=
_converse
.
chatboxviews
.
get
(
muc_jid
);
const
sent_IQs
=
_converse
.
connection
.
IQ_stanzas
;
...
...
@@ -816,7 +851,8 @@
async
function
(
done
,
_converse
)
{
const
muc_jid
=
'
lounge@montague.lit
'
;
await
test_utils
.
openAndEnterChatRoom
(
_converse
,
muc_jid
,
'
romeo
'
);
const
features
=
[...
mock
.
default_muc_features
,
Strophe
.
NS
.
MODERATE
];
await
test_utils
.
openAndEnterChatRoom
(
_converse
,
muc_jid
,
'
romeo
'
,
features
);
const
view
=
_converse
.
chatboxviews
.
get
(
muc_jid
);
const
sent_IQs
=
_converse
.
connection
.
IQ_stanzas
;
...
...
src/converse-message-view.js
View file @
025cdbf1
...
...
@@ -242,15 +242,19 @@ converse.plugins.add('converse-message-view', {
const
role
=
this
.
model
.
vcard
?
this
.
model
.
vcard
.
get
(
'
role
'
)
:
null
;
const
roles
=
role
?
role
.
split
(
'
,
'
)
:
[];
const
is_retracted
=
this
.
model
.
get
(
'
retracted
'
)
||
this
.
model
.
get
(
'
moderated
'
)
===
'
retracted
'
;
const
is_groupchat_message
=
this
.
model
.
get
(
'
type
'
)
===
'
groupchat
'
;
const
is_own_message
=
this
.
model
.
get
(
'
sender
'
)
===
'
me
'
;
const
chatbox
=
this
.
model
.
collection
.
chatbox
;
const
retractable
=
is_groupchat_message
?
await
chatbox
.
canRetractMessages
()
:
is_own_message
;
const
msg
=
u
.
stringToElement
(
tpl_message
(
Object
.
assign
(
this
.
model
.
toJSON
(),
{
__
,
is_groupchat_message
,
is_retracted
,
'
extra_classes
'
:
this
.
getExtraMessageClasses
(),
'
is_groupchat_message
'
:
this
.
model
.
get
(
'
type
'
)
===
'
groupchat
'
,
retractable
,
'
is_me_message
'
:
this
.
model
.
isMeCommand
(),
'
extra_classes
'
:
this
.
getExtraMessageClasses
(),
'
label_show
'
:
__
(
'
Show more
'
),
'
occupant
'
:
this
.
model
.
occupant
,
'
pretty_time
'
:
time
.
format
(
_converse
.
time_format
),
...
...
src/headless/converse-muc.js
View file @
025cdbf1
...
...
@@ -707,6 +707,11 @@ converse.plugins.add('converse-muc', {
return
_converse
.
ChatBox
.
prototype
.
close
.
call
(
this
);
},
canRetractMessages
()
{
const
self
=
this
.
getOwnOccupant
();
return
self
&&
self
.
isModerator
()
&&
_converse
.
api
.
disco
.
supports
(
Strophe
.
NS
.
MODERATE
,
this
.
get
(
'
jid
'
));
},
sendUnavailablePresence
(
exit_msg
)
{
const
presence
=
$pres
({
type
:
"
unavailable
"
,
...
...
src/templates/message.html
View file @
025cdbf1
...
...
@@ -41,8 +41,7 @@
{[ if (o.editable) { ]}
<button
class=
"chat-msg__action chat-msg__action-edit fa fa-pencil-alt"
title=
"{{{o.__('Edit this message')}}}"
></button>
{[ } ]}
<!-- FIXME -->
{[ if ((o.sender === 'me' || o.is_groupchat_message)
&&
true) { ]}
{[ if (o.retractable) { ]}
<button
class=
"chat-msg__action chat-msg__action-retract fa fa-trash-alt"
title=
"{{{o.__('Retract this message')}}}"
></button>
{[ } ]}
</div>
...
...
tests/mock.js
View file @
025cdbf1
...
...
@@ -69,6 +69,20 @@
};
const
mock
=
{};
mock
.
default_muc_features
=
[
'
http://jabber.org/protocol/muc
'
,
'
jabber:iq:register
'
,
Strophe
.
NS
.
SID
,
Strophe
.
NS
.
MAM
,
'
muc_passwordprotected
'
,
'
muc_hidden
'
,
'
muc_temporary
'
,
'
muc_open
'
,
'
muc_unmoderated
'
,
'
muc_anonymous
'
];
mock
.
view_mode
=
'
overlayed
'
;
// Names from http://www.fakenamegenerator.com/
...
...
tests/utils.js
View file @
025cdbf1
...
...
@@ -167,17 +167,7 @@
'
type
'
:
'
text
'
}).
up
();
features
=
features
.
length
?
features
:
[
'
http://jabber.org/protocol/muc
'
,
'
jabber:iq:register
'
,
Strophe
.
NS
.
SID
,
Strophe
.
NS
.
MAM
,
'
muc_passwordprotected
'
,
'
muc_hidden
'
,
'
muc_temporary
'
,
'
muc_open
'
,
'
muc_unmoderated
'
,
'
muc_anonymous
'
]
features
=
features
.
length
?
features
:
mock
.
default_muc_features
;
features
.
forEach
(
f
=>
features_stanza
.
c
(
'
feature
'
,
{
'
var
'
:
f
}).
up
());
features_stanza
.
c
(
'
x
'
,
{
'
xmlns
'
:
'
jabber:x:data
'
,
'
type
'
:
'
result
'
})
.
c
(
'
field
'
,
{
'
var
'
:
'
FORM_TYPE
'
,
'
type
'
:
'
hidden
'
})
...
...
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