Commit 4a5603ab authored by JC Brand's avatar JC Brand

More specific selector for markers and another test

Updates #1442
parent dbcf6002
...@@ -66988,11 +66988,32 @@ _converse_core__WEBPACK_IMPORTED_MODULE_6__["default"].plugins.add('converse-muc ...@@ -66988,11 +66988,32 @@ _converse_core__WEBPACK_IMPORTED_MODULE_6__["default"].plugins.add('converse-muc
}, },
isReceipt(stanza) { isReceipt(stanza) {
return sizzle(`[xmlns="${Strophe.NS.RECEIPTS}"]`, stanza).length > 0; return sizzle(`received[xmlns="${Strophe.NS.RECEIPTS}"]`, stanza).length > 0;
}, },
isChatMarker(stanza) { isChatMarker(stanza) {
return sizzle(`[xmlns="${Strophe.NS.MARKERS}"]`, stanza).length > 0; return sizzle(`received[xmlns="${Strophe.NS.MARKERS}"],
displayed[xmlns="${Strophe.NS.MARKERS}"],
acknowledged[xmlns="${Strophe.NS.MARKERS}"]`, stanza).length > 0;
},
subjectChangeHandled(attrs) {
if (attrs.subject && !attrs.thread && !attrs.message) {
// https://xmpp.org/extensions/xep-0045.html#subject-mod
// -----------------------------------------------------
// The subject is changed by sending a message of type "groupchat" to the <room@service>,
// where the <message/> MUST contain a <subject/> element that specifies the new subject but
// MUST NOT contain a <body/> element (or a <thread/> element).
_utils_form__WEBPACK_IMPORTED_MODULE_7__["default"].safeSave(this, {
'subject': {
'author': attrs.nick,
'text': attrs.subject || ''
}
});
return true;
}
return false;
}, },
async onMessage(stanza) { async onMessage(stanza) {
...@@ -67019,22 +67040,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_6__["default"].plugins.add('converse-muc ...@@ -67019,22 +67040,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_6__["default"].plugins.add('converse-muc
return; return;
} }
if (!this.handleMessageCorrection(stanza) && !this.isReceipt(stanza) && !this.isChatMarker(stanza)) { if (!this.handleMessageCorrection(stanza) && !this.isReceipt(stanza) && !this.isChatMarker(stanza) && !this.subjectChangeHandled(attrs)) {
if (attrs.subject && !attrs.thread && !attrs.message) {
// https://xmpp.org/extensions/xep-0045.html#subject-mod
// -----------------------------------------------------
// The subject is changed by sending a message of type "groupchat" to the <room@service>,
// where the <message/> MUST contain a <subject/> element that specifies the new subject but
// MUST NOT contain a <body/> element (or a <thread/> element).
_utils_form__WEBPACK_IMPORTED_MODULE_7__["default"].safeSave(this, {
'subject': {
'author': attrs.nick,
'text': attrs.subject || ''
}
});
return;
}
const is_csn = _utils_form__WEBPACK_IMPORTED_MODULE_7__["default"].isOnlyChatStateNotification(attrs), const is_csn = _utils_form__WEBPACK_IMPORTED_MODULE_7__["default"].isOnlyChatStateNotification(attrs),
own_message = Strophe.getResourceFromJid(attrs.from) == this.get('nick'); own_message = Strophe.getResourceFromJid(attrs.from) == this.get('nick');
...@@ -67043,15 +67049,13 @@ _converse_core__WEBPACK_IMPORTED_MODULE_6__["default"].plugins.add('converse-muc ...@@ -67043,15 +67049,13 @@ _converse_core__WEBPACK_IMPORTED_MODULE_6__["default"].plugins.add('converse-muc
return; return;
} }
const msg = await this.messages.create(attrs); const msg = await this.createMessage(stanza, original_stanza);
if (forwarded && msg && msg.get('sender') === 'me') { if (forwarded && msg && msg.get('sender') === 'me') {
msg.save({ msg.save({
'received': moment().format() 'received': moment().format()
}); });
} }
this.incrementUnreadMsgCounter(msg);
} }
if (attrs.nick !== this.get('nick')) { if (attrs.nick !== this.get('nick')) {
...@@ -2347,7 +2347,7 @@ ...@@ -2347,7 +2347,7 @@
done(); done();
})); }));
it("can cause a delivery receipt", it("can cause a delivery receipt to be returned",
mock.initConverse( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
async function (done, _converse) { async function (done, _converse) {
...@@ -2381,6 +2381,73 @@ ...@@ -2381,6 +2381,73 @@
done(); done();
})); }));
it("can cause a chat marker to be returned",
mock.initConverse(
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
test_utils.createContacts(_converse, 'current');
await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy');
const view = _converse.chatboxviews.get('lounge@localhost');
const textarea = view.el.querySelector('textarea.chat-textarea');
textarea.value = 'But soft, what light through yonder airlock breaks?';
view.keyPressed({
target: textarea,
preventDefault: _.noop,
keyCode: 13 // Enter
});
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
expect(view.el.querySelectorAll('.chat-msg').length).toBe(1);
const msg_obj = view.model.messages.at(0);
let stanza = u.toStanza(`
<message xml:lang="en" to="dummy@localhost/resource"
from="lounge@localhost/some1" type="groupchat" xmlns="jabber:client">
<received xmlns="urn:xmpp:chat-markers:0" id="${msg_obj.get('msgid')}"/>
</message>`);
spyOn(_converse, 'emit').and.callThrough();
_converse.connection._dataRecv(test_utils.createRequest(stanza));
await test_utils.waitUntil(() => _converse.emit.calls.count() === 1);
expect(view.el.querySelectorAll('.chat-msg').length).toBe(1);
expect(view.el.querySelectorAll('.chat-msg__receipt').length).toBe(0);
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
stanza = u.toStanza(`
<message xml:lang="en" to="dummy@localhost/resource"
from="lounge@localhost/some1" type="groupchat" xmlns="jabber:client">
<displayed xmlns="urn:xmpp:chat-markers:0" id="${msg_obj.get('msgid')}"/>
</message>`);
_converse.connection._dataRecv(test_utils.createRequest(stanza));
await test_utils.waitUntil(() => _converse.emit.calls.count() === 2);
expect(view.el.querySelectorAll('.chat-msg').length).toBe(1);
expect(view.el.querySelectorAll('.chat-msg__receipt').length).toBe(0);
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
stanza = u.toStanza(`
<message xml:lang="en" to="dummy@localhost/resource"
from="lounge@localhost/some1" type="groupchat" xmlns="jabber:client">
<acknowledged xmlns="urn:xmpp:chat-markers:0" id="${msg_obj.get('msgid')}"/>
</message>`);
_converse.connection._dataRecv(test_utils.createRequest(stanza));
await test_utils.waitUntil(() => _converse.emit.calls.count() === 3);
expect(view.el.querySelectorAll('.chat-msg').length).toBe(1);
expect(view.el.querySelectorAll('.chat-msg__receipt').length).toBe(0);
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
stanza = u.toStanza(`
<message xml:lang="en" to="dummy@localhost/resource"
from="lounge@localhost/some1" type="groupchat" xmlns="jabber:client">
<body>'tis I!</body>
<markable xmlns="urn:xmpp:chat-markers:0"/>
</message>`);
_converse.connection._dataRecv(test_utils.createRequest(stanza));
await test_utils.waitUntil(() => _converse.emit.calls.count() === 5);
expect(view.el.querySelectorAll('.chat-msg').length).toBe(2);
expect(view.el.querySelectorAll('.chat-msg__receipt').length).toBe(0);
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
done();
}));
describe("when received", function () { describe("when received", function () {
it("highlights all users mentioned via XEP-0372 references", it("highlights all users mentioned via XEP-0372 references",
......
...@@ -979,11 +979,27 @@ converse.plugins.add('converse-muc', { ...@@ -979,11 +979,27 @@ converse.plugins.add('converse-muc', {
}, },
isReceipt (stanza) { isReceipt (stanza) {
return sizzle(`[xmlns="${Strophe.NS.RECEIPTS}"]`, stanza).length > 0; return sizzle(`received[xmlns="${Strophe.NS.RECEIPTS}"]`, stanza).length > 0;
}, },
isChatMarker (stanza) { isChatMarker (stanza) {
return sizzle(`[xmlns="${Strophe.NS.MARKERS}"]`, stanza).length > 0; return sizzle(
`received[xmlns="${Strophe.NS.MARKERS}"],
displayed[xmlns="${Strophe.NS.MARKERS}"],
acknowledged[xmlns="${Strophe.NS.MARKERS}"]`, stanza).length > 0;
},
subjectChangeHandled (attrs) {
if (attrs.subject && !attrs.thread && !attrs.message) {
// https://xmpp.org/extensions/xep-0045.html#subject-mod
// -----------------------------------------------------
// The subject is changed by sending a message of type "groupchat" to the <room@service>,
// where the <message/> MUST contain a <subject/> element that specifies the new subject but
// MUST NOT contain a <body/> element (or a <thread/> element).
u.safeSave(this, {'subject': {'author': attrs.nick, 'text': attrs.subject || ''}});
return true;
}
return false;
}, },
async onMessage (stanza) { async onMessage (stanza) {
...@@ -1008,17 +1024,8 @@ converse.plugins.add('converse-muc', { ...@@ -1008,17 +1024,8 @@ converse.plugins.add('converse-muc', {
} }
if (!this.handleMessageCorrection(stanza) && if (!this.handleMessageCorrection(stanza) &&
!this.isReceipt(stanza) && !this.isReceipt(stanza) &&
!this.isChatMarker(stanza)) { !this.isChatMarker(stanza) &&
!this.subjectChangeHandled(attrs)) {
if (attrs.subject && !attrs.thread && !attrs.message) {
// https://xmpp.org/extensions/xep-0045.html#subject-mod
// -----------------------------------------------------
// The subject is changed by sending a message of type "groupchat" to the <room@service>,
// where the <message/> MUST contain a <subject/> element that specifies the new subject but
// MUST NOT contain a <body/> element (or a <thread/> element).
u.safeSave(this, {'subject': {'author': attrs.nick, 'text': attrs.subject || ''}});
return;
}
const is_csn = u.isOnlyChatStateNotification(attrs), const is_csn = u.isOnlyChatStateNotification(attrs),
own_message = Strophe.getResourceFromJid(attrs.from) == this.get('nick'); own_message = Strophe.getResourceFromJid(attrs.from) == this.get('nick');
...@@ -1026,11 +1033,10 @@ converse.plugins.add('converse-muc', { ...@@ -1026,11 +1033,10 @@ converse.plugins.add('converse-muc', {
// No need showing delayed or our own CSN messages // No need showing delayed or our own CSN messages
return; return;
} }
const msg = await this.messages.create(attrs); const msg = await this.createMessage(stanza, original_stanza);
if (forwarded && msg && msg.get('sender') === 'me') { if (forwarded && msg && msg.get('sender') === 'me') {
msg.save({'received': moment().format()}); msg.save({'received': moment().format()});
} }
this.incrementUnreadMsgCounter(msg);
} }
if (attrs.nick !== this.get('nick')) { if (attrs.nick !== this.get('nick')) {
// We only emit an event if it's not our own message // We only emit an event if it's not our own message
......
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