Commit 2cbc4aaa authored by JC Brand's avatar JC Brand

Fixes #1494. Trim whitespace around messages

parent 83bc851f
......@@ -37,6 +37,7 @@
- #1445: Participants list uses big font in embedded mode
- #1455: Avatar in controlbox status-view not updated
- #1465: When highlighting a roster contact, they're incorrectly shown as online
- #1494: Trim whitespace around messages
- #1495: Mentions should always include a URI attribute
- #1502: Fatal error when using prebind
- #1532: Converse reloads on enter pressed in the filter box
......
......@@ -1396,6 +1396,26 @@
done();
}));
describe("when sent", function () {
it("will be trimmed of leading and trailing whitespace",
mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) {
await test_utils.waitForRoster(_converse, 'current', 1);
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
await test_utils.openChatBoxFor(_converse, contact_jid)
const view = _converse.chatboxviews.get(contact_jid);
const message = ' \nThis message is sent from this chatbox \n \n';
await test_utils.sendMessage(view, message);
expect(view.model.messages.at(0).get('message')).toEqual(message.trim());
const message_el = sizzle('.chat-content .chat-msg:last .chat-msg__text', view.el).pop();
expect(message_el.textContent).toEqual(message.trim());
done();
}));
});
describe("when received from someone else", function () {
......@@ -1445,6 +1465,35 @@
done();
}));
it("will be trimmed of leading and trailing whitespace",
mock.initConverse(
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
await test_utils.waitForRoster(_converse, 'current', 1, false);
await test_utils.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length, 300);
const message = '\n\n This is a received message \n\n';
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
_converse.chatboxes.onMessage(
$msg({
'from': sender_jid,
'to': _converse.connection.jid,
'type': 'chat',
'id': (new Date()).getTime()
}).c('body').t(message).up()
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree()
);
await test_utils.waitUntil(() => (_converse.api.chats.get().length === 2));
const view = _converse.api.chatviews.get(sender_jid);
expect(view.model.messages.length).toEqual(1);
const msg_obj = view.model.messages.at(0);
expect(msg_obj.get('message')).toEqual(message.trim());
const chat_content = view.el.querySelector('.chat-content');
expect(chat_content.querySelector('.chat-msg .chat-msg__text').textContent).toEqual(message.trim());
done();
}));
it("can be replaced with a correction",
mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
......
......@@ -914,7 +914,7 @@ converse.plugins.add('converse-chatview', {
async onFormSubmitted (ev) {
ev.preventDefault();
const textarea = this.el.querySelector('.chat-textarea');
const message = textarea.value;
const message = textarea.value.trim();
if (_converse.message_limit && message.length > _converse.message_limit) {
return;
}
......
......@@ -841,7 +841,10 @@ converse.plugins.add('converse-chatboxes', {
if (type === 'error') {
return this.getErrorMessage(stanza);
} else {
return _.propertyOf(stanza.querySelector('body'))('textContent');
const body = stanza.querySelector('body');
if (body) {
return body.textContent.trim();
}
}
},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment