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
23455679
Commit
23455679
authored
Apr 10, 2019
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Provide a more user-friendly error message to muted users
parent
f1899d09
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
112 additions
and
39 deletions
+112
-39
dist/converse.js
dist/converse.js
+26
-13
spec/muc.js
spec/muc.js
+33
-0
src/headless/converse-chatboxes.js
src/headless/converse-chatboxes.js
+18
-13
src/headless/converse-core.js
src/headless/converse-core.js
+1
-0
src/headless/converse-muc.js
src/headless/converse-muc.js
+8
-0
src/headless/dist/converse-headless.js
src/headless/dist/converse-headless.js
+26
-13
No files found.
dist/converse.js
View file @
23455679
...
...
@@ -62126,7 +62126,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
const older_versions = message.get('older_versions') || [];
older_versions.push(message.get('message'));
message.save({
'message':
_converse.chatboxe
s.getMessageBody(stanza),
'message':
thi
s.getMessageBody(stanza),
'references': this.getReferencesFromStanza(stanza),
'older_versions': older_versions,
'edited': moment().format()
...
...
@@ -62529,6 +62529,18 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
return !_.isNil(sizzle(`result[xmlns="${Strophe.NS.MAM}"]`, original_stanza).pop());
},
getMessageBody(stanza) {
/* Given a message stanza, return the text contained in its body.
*/
const type = stanza.getAttribute('type');
if (type === 'error') {
return this.getErrorMessage(stanza);
} else {
return _.propertyOf(stanza.querySelector('body'))('textContent');
}
},
/**
* Parses a passed in message stanza and returns an object
* of attributes.
...
...
@@ -62542,7 +62554,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
getMessageAttributesFromStanza(stanza, original_stanza) {
const spoiler = sizzle(`spoiler[xmlns="${Strophe.NS.SPOILER}"]`, original_stanza).pop(),
delay = sizzle(`delay[xmlns="${Strophe.NS.DELAY}"]`, original_stanza).pop(),
text =
_converse.chatboxe
s.getMessageBody(stanza) || undefined,
text =
thi
s.getMessageBody(stanza) || undefined,
chat_state = stanza.getElementsByTagName(_converse.COMPOSING).length && _converse.COMPOSING || stanza.getElementsByTagName(_converse.PAUSED).length && _converse.PAUSED || stanza.getElementsByTagName(_converse.INACTIVE).length && _converse.INACTIVE || stanza.getElementsByTagName(_converse.ACTIVE).length && _converse.ACTIVE || stanza.getElementsByTagName(_converse.GONE).length && _converse.GONE;
const attrs = _.extend({
...
...
@@ -62737,17 +62749,9 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
chatbox.messages.create(attrs);
},
getMessageBody(stanza) {
/* Given a message stanza, return the text contained in its body.
*/
const type = stanza.getAttribute('type');
if (type === 'error') {
const error = stanza.querySelector('error');
return _.propertyOf(error.querySelector('text'))('textContent') || __('Sorry, an error occurred:') + ' ' + error.innerHTML;
} else {
return _.propertyOf(stanza.querySelector('body'))('textContent');
}
getErrorMessage(stanza) {
const error = stanza.querySelector('error');
return _.propertyOf(error.querySelector('text'))('textContent') || __('Sorry, an error occurred:') + ' ' + error.innerHTML;
},
/**
...
...
@@ -63172,6 +63176,7 @@ strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].addNamespace('ROSTERX', 'http
strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].addNamespace('RSM', 'http://jabber.org/protocol/rsm');
strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].addNamespace('SID', 'urn:xmpp:sid:0');
strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].addNamespace('SPOILER', 'urn:xmpp:spoiler:0');
strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].addNamespace('STANZAS', 'urn:ietf:params:xml:ns:xmpp-stanzas');
strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].addNamespace('VCARD', 'vcard-temp');
strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].addNamespace('VCARDUPDATE', 'vcard-temp:x:update');
strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].addNamespace('XFORM', 'jabber:x:data'); // Use Mustache style syntax for variable interpolation
...
...
@@ -67663,6 +67668,14 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc
return attrs;
},
getErrorMessage(stanza) {
if (sizzle(`forbidden[xmlns="${Strophe.NS.STANZAS}"]`, stanza).length) {
return __("Your message was not delivered because you're not allowed to send messages in this groupchat.");
} else {
return _converse.ChatBox.prototype.getErrorMessage.apply(this, arguments);
}
},
/**
* Handler for all MUC messages sent to this groupchat.
* @private
spec/muc.js
View file @
23455679
...
...
@@ -4636,5 +4636,38 @@
}));
});
});
describe
(
"
A muted user
"
,
function
()
{
it
(
"
will receive a user-friendly error message when trying to send a message
"
,
mock
.
initConverse
(
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
async
function
(
done
,
_converse
)
{
await
test_utils
.
openAndEnterChatRoom
(
_converse
,
'
trollbox
'
,
'
localhost
'
,
'
troll
'
);
var
sent_IQ
,
IQ_id
;
var
sendIQ
=
_converse
.
connection
.
sendIQ
;
spyOn
(
_converse
.
connection
,
'
sendIQ
'
).
and
.
callFake
(
function
(
iq
,
callback
,
errback
)
{
sent_IQ
=
iq
;
IQ_id
=
sendIQ
.
bind
(
this
)(
iq
,
callback
,
errback
);
});
const
view
=
_converse
.
chatboxviews
.
get
(
'
trollbox@localhost
'
);
const
textarea
=
view
.
el
.
querySelector
(
'
.chat-textarea
'
);
textarea
.
value
=
'
Hello world
'
;
view
.
onFormSubmitted
(
new
Event
(
'
submit
'
));
const
stanza
=
u
.
toStanza
(
`
<message xmlns="jabber:client" type="error" to="troll@localhost/resource" from="trollbox@localhost">
<error type="auth"><forbidden xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error>
</message>`
);
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
await
new
Promise
((
resolve
,
reject
)
=>
view
.
once
(
'
messageInserted
'
,
resolve
));
expect
(
view
.
el
.
querySelector
(
'
.chat-error
'
).
textContent
).
toBe
(
"
Your message was not delivered because you're not allowed to send messages in this groupchat.
"
);
done
();
}));
});
});
}));
src/headless/converse-chatboxes.js
View file @
23455679
...
...
@@ -361,7 +361,7 @@ converse.plugins.add('converse-chatboxes', {
const
older_versions
=
message
.
get
(
'
older_versions
'
)
||
[];
older_versions
.
push
(
message
.
get
(
'
message
'
));
message
.
save
({
'
message
'
:
_converse
.
chatboxe
s
.
getMessageBody
(
stanza
),
'
message
'
:
thi
s
.
getMessageBody
(
stanza
),
'
references
'
:
this
.
getReferencesFromStanza
(
stanza
),
'
older_versions
'
:
older_versions
,
'
edited
'
:
moment
().
format
()
...
...
@@ -696,6 +696,18 @@ converse.plugins.add('converse-chatboxes', {
return
!
_
.
isNil
(
sizzle
(
`result[xmlns="
${
Strophe
.
NS
.
MAM
}
"]`
,
original_stanza
).
pop
());
},
getMessageBody
(
stanza
)
{
/* Given a message stanza, return the text contained in its body.
*/
const
type
=
stanza
.
getAttribute
(
'
type
'
);
if
(
type
===
'
error
'
)
{
return
this
.
getErrorMessage
(
stanza
);
}
else
{
return
_
.
propertyOf
(
stanza
.
querySelector
(
'
body
'
))(
'
textContent
'
);
}
},
/**
* Parses a passed in message stanza and returns an object
* of attributes.
...
...
@@ -709,7 +721,7 @@ converse.plugins.add('converse-chatboxes', {
getMessageAttributesFromStanza
(
stanza
,
original_stanza
)
{
const
spoiler
=
sizzle
(
`spoiler[xmlns="
${
Strophe
.
NS
.
SPOILER
}
"]`
,
original_stanza
).
pop
(),
delay
=
sizzle
(
`delay[xmlns="
${
Strophe
.
NS
.
DELAY
}
"]`
,
original_stanza
).
pop
(),
text
=
_converse
.
chatboxe
s
.
getMessageBody
(
stanza
)
||
undefined
,
text
=
thi
s
.
getMessageBody
(
stanza
)
||
undefined
,
chat_state
=
stanza
.
getElementsByTagName
(
_converse
.
COMPOSING
).
length
&&
_converse
.
COMPOSING
||
stanza
.
getElementsByTagName
(
_converse
.
PAUSED
).
length
&&
_converse
.
PAUSED
||
stanza
.
getElementsByTagName
(
_converse
.
INACTIVE
).
length
&&
_converse
.
INACTIVE
||
...
...
@@ -887,17 +899,10 @@ converse.plugins.add('converse-chatboxes', {
chatbox
.
messages
.
create
(
attrs
);
},
getMessageBody
(
stanza
)
{
/* Given a message stanza, return the text contained in its body.
*/
const
type
=
stanza
.
getAttribute
(
'
type
'
);
if
(
type
===
'
error
'
)
{
const
error
=
stanza
.
querySelector
(
'
error
'
);
return
_
.
propertyOf
(
error
.
querySelector
(
'
text
'
))(
'
textContent
'
)
||
__
(
'
Sorry, an error occurred:
'
)
+
'
'
+
error
.
innerHTML
;
}
else
{
return
_
.
propertyOf
(
stanza
.
querySelector
(
'
body
'
))(
'
textContent
'
);
}
getErrorMessage
(
stanza
)
{
const
error
=
stanza
.
querySelector
(
'
error
'
);
return
_
.
propertyOf
(
error
.
querySelector
(
'
text
'
))(
'
textContent
'
)
||
__
(
'
Sorry, an error occurred:
'
)
+
'
'
+
error
.
innerHTML
;
},
/**
...
...
src/headless/converse-core.js
View file @
23455679
...
...
@@ -41,6 +41,7 @@ Strophe.addNamespace('ROSTERX', 'http://jabber.org/protocol/rosterx');
Strophe
.
addNamespace
(
'
RSM
'
,
'
http://jabber.org/protocol/rsm
'
);
Strophe
.
addNamespace
(
'
SID
'
,
'
urn:xmpp:sid:0
'
);
Strophe
.
addNamespace
(
'
SPOILER
'
,
'
urn:xmpp:spoiler:0
'
);
Strophe
.
addNamespace
(
'
STANZAS
'
,
'
urn:ietf:params:xml:ns:xmpp-stanzas
'
);
Strophe
.
addNamespace
(
'
VCARD
'
,
'
vcard-temp
'
);
Strophe
.
addNamespace
(
'
VCARDUPDATE
'
,
'
vcard-temp:x:update
'
);
Strophe
.
addNamespace
(
'
XFORM
'
,
'
jabber:x:data
'
);
...
...
src/headless/converse-muc.js
View file @
23455679
...
...
@@ -1040,6 +1040,14 @@ converse.plugins.add('converse-muc', {
return
attrs
;
},
getErrorMessage
(
stanza
)
{
if
(
sizzle
(
`forbidden[xmlns="
${
Strophe
.
NS
.
STANZAS
}
"]`
,
stanza
).
length
)
{
return
__
(
"
Your message was not delivered because you're not allowed to send messages in this groupchat.
"
);
}
else
{
return
_converse
.
ChatBox
.
prototype
.
getErrorMessage
.
apply
(
this
,
arguments
);
}
},
/**
* Handler for all MUC messages sent to this groupchat.
* @private
...
...
src/headless/dist/converse-headless.js
View file @
23455679
...
...
@@ -40643,7 +40643,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
const older_versions = message.get('older_versions') || [];
older_versions.push(message.get('message'));
message.save({
'message':
_converse.chatboxe
s.getMessageBody(stanza),
'message':
thi
s.getMessageBody(stanza),
'references': this.getReferencesFromStanza(stanza),
'older_versions': older_versions,
'edited': moment().format()
...
...
@@ -41046,6 +41046,18 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
return !_.isNil(sizzle(`result[xmlns="${Strophe.NS.MAM}"]`, original_stanza).pop());
},
getMessageBody(stanza) {
/* Given a message stanza, return the text contained in its body.
*/
const type = stanza.getAttribute('type');
if (type === 'error') {
return this.getErrorMessage(stanza);
} else {
return _.propertyOf(stanza.querySelector('body'))('textContent');
}
},
/**
* Parses a passed in message stanza and returns an object
* of attributes.
...
...
@@ -41059,7 +41071,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
getMessageAttributesFromStanza(stanza, original_stanza) {
const spoiler = sizzle(`spoiler[xmlns="${Strophe.NS.SPOILER}"]`, original_stanza).pop(),
delay = sizzle(`delay[xmlns="${Strophe.NS.DELAY}"]`, original_stanza).pop(),
text =
_converse.chatboxe
s.getMessageBody(stanza) || undefined,
text =
thi
s.getMessageBody(stanza) || undefined,
chat_state = stanza.getElementsByTagName(_converse.COMPOSING).length && _converse.COMPOSING || stanza.getElementsByTagName(_converse.PAUSED).length && _converse.PAUSED || stanza.getElementsByTagName(_converse.INACTIVE).length && _converse.INACTIVE || stanza.getElementsByTagName(_converse.ACTIVE).length && _converse.ACTIVE || stanza.getElementsByTagName(_converse.GONE).length && _converse.GONE;
const attrs = _.extend({
...
...
@@ -41254,17 +41266,9 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
chatbox.messages.create(attrs);
},
getMessageBody(stanza) {
/* Given a message stanza, return the text contained in its body.
*/
const type = stanza.getAttribute('type');
if (type === 'error') {
const error = stanza.querySelector('error');
return _.propertyOf(error.querySelector('text'))('textContent') || __('Sorry, an error occurred:') + ' ' + error.innerHTML;
} else {
return _.propertyOf(stanza.querySelector('body'))('textContent');
}
getErrorMessage(stanza) {
const error = stanza.querySelector('error');
return _.propertyOf(error.querySelector('text'))('textContent') || __('Sorry, an error occurred:') + ' ' + error.innerHTML;
},
/**
...
...
@@ -41689,6 +41693,7 @@ strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].addNamespace('ROSTERX', 'http
strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].addNamespace('RSM', 'http://jabber.org/protocol/rsm');
strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].addNamespace('SID', 'urn:xmpp:sid:0');
strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].addNamespace('SPOILER', 'urn:xmpp:spoiler:0');
strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].addNamespace('STANZAS', 'urn:ietf:params:xml:ns:xmpp-stanzas');
strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].addNamespace('VCARD', 'vcard-temp');
strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].addNamespace('VCARDUPDATE', 'vcard-temp:x:update');
strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].addNamespace('XFORM', 'jabber:x:data'); // Use Mustache style syntax for variable interpolation
...
...
@@ -46180,6 +46185,14 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc
return attrs;
},
getErrorMessage(stanza) {
if (sizzle(`forbidden[xmlns="${Strophe.NS.STANZAS}"]`, stanza).length) {
return __("Your message was not delivered because you're not allowed to send messages in this groupchat.");
} else {
return _converse.ChatBox.prototype.getErrorMessage.apply(this, arguments);
}
},
/**
* Handler for all MUC messages sent to this groupchat.
* @private
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