2020-08-31 20:29:51 +02:00
|
|
|
/*global mock, converse */
|
2020-07-08 14:32:06 +02:00
|
|
|
|
2021-02-08 11:27:42 +01:00
|
|
|
const { Strophe, $msg, $pres } = converse.env;
|
2020-07-08 14:32:06 +02:00
|
|
|
const u = converse.env.utils;
|
|
|
|
|
|
|
|
|
2020-07-09 06:27:56 +02:00
|
|
|
describe("An incoming groupchat message", function () {
|
2020-07-08 14:32:06 +02:00
|
|
|
|
|
|
|
it("is specially marked when you are mentioned in it",
|
2021-01-29 11:08:28 +01:00
|
|
|
mock.initConverse(['chatBoxesFetched'], {}, async function (done, _converse) {
|
2020-07-08 14:32:06 +02:00
|
|
|
|
|
|
|
const muc_jid = 'lounge@montague.lit';
|
|
|
|
await mock.openAndEnterChatRoom(_converse, muc_jid, 'romeo');
|
|
|
|
const view = _converse.api.chatviews.get(muc_jid);
|
2020-12-08 12:54:14 +01:00
|
|
|
if (!view.querySelectorAll('.chat-area').length) { view.renderChatArea(); }
|
2020-07-08 14:32:06 +02:00
|
|
|
const message = 'romeo: Your attention is required';
|
|
|
|
const nick = mock.chatroom_names[0],
|
|
|
|
msg = $msg({
|
|
|
|
from: 'lounge@montague.lit/'+nick,
|
|
|
|
id: u.getUniqueId(),
|
|
|
|
to: 'romeo@montague.lit',
|
|
|
|
type: 'groupchat'
|
|
|
|
}).c('body').t(message).tree();
|
|
|
|
await view.model.handleMessageStanza(msg);
|
2021-02-08 11:27:42 +01:00
|
|
|
await u.waitUntil(() => view.querySelectorAll('.chat-msg__text').length);
|
2020-12-08 12:54:14 +01:00
|
|
|
expect(u.hasClass('mentioned', view.querySelector('.chat-msg'))).toBeTruthy();
|
2020-07-08 14:32:06 +02:00
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it("highlights all users mentioned via XEP-0372 references",
|
2021-01-29 11:08:28 +01:00
|
|
|
mock.initConverse([], {}, async function (done, _converse) {
|
2020-07-08 14:32:06 +02:00
|
|
|
|
|
|
|
const muc_jid = 'lounge@montague.lit';
|
|
|
|
await mock.openAndEnterChatRoom(_converse, muc_jid, 'tom');
|
|
|
|
const view = _converse.api.chatviews.get(muc_jid);
|
|
|
|
['z3r0', 'mr.robot', 'gibson', 'sw0rdf1sh'].forEach((nick) => {
|
|
|
|
_converse.connection._dataRecv(mock.createRequest(
|
|
|
|
$pres({
|
|
|
|
'to': 'tom@montague.lit/resource',
|
|
|
|
'from': `lounge@montague.lit/${nick}`
|
|
|
|
})
|
|
|
|
.c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'none',
|
|
|
|
'jid': `${nick}@montague.lit/resource`,
|
|
|
|
'role': 'participant'
|
|
|
|
}))
|
|
|
|
);
|
|
|
|
});
|
2020-11-27 14:47:51 +01:00
|
|
|
let msg = $msg({
|
2020-07-08 14:32:06 +02:00
|
|
|
from: 'lounge@montague.lit/gibson',
|
|
|
|
id: u.getUniqueId(),
|
|
|
|
to: 'romeo@montague.lit',
|
|
|
|
type: 'groupchat'
|
|
|
|
}).c('body').t('hello z3r0 tom mr.robot, how are you?').up()
|
|
|
|
.c('reference', {'xmlns':'urn:xmpp:reference:0', 'begin':'6', 'end':'10', 'type':'mention', 'uri':'xmpp:z3r0@montague.lit'}).up()
|
|
|
|
.c('reference', {'xmlns':'urn:xmpp:reference:0', 'begin':'11', 'end':'14', 'type':'mention', 'uri':'xmpp:romeo@montague.lit'}).up()
|
|
|
|
.c('reference', {'xmlns':'urn:xmpp:reference:0', 'begin':'15', 'end':'23', 'type':'mention', 'uri':'xmpp:mr.robot@montague.lit'}).nodeTree;
|
|
|
|
await view.model.handleMessageStanza(msg);
|
2021-02-08 11:27:42 +01:00
|
|
|
await u.waitUntil(() => view.querySelector('.chat-msg__text')?.innerHTML.replace(/<!---->/g, '') ===
|
2020-11-27 14:47:51 +01:00
|
|
|
'hello <span class="mention">z3r0</span> '+
|
|
|
|
'<span class="mention mention--self badge badge-info">tom</span> '+
|
|
|
|
'<span class="mention">mr.robot</span>, how are you?');
|
2021-02-08 11:27:42 +01:00
|
|
|
let message = view.querySelector('.chat-msg__text')
|
|
|
|
expect(message.classList.length).toEqual(1);
|
2020-11-27 14:47:51 +01:00
|
|
|
|
|
|
|
msg = $msg({
|
|
|
|
from: 'lounge@montague.lit/sw0rdf1sh',
|
|
|
|
id: u.getUniqueId(),
|
|
|
|
to: 'romeo@montague.lit',
|
|
|
|
type: 'groupchat'
|
|
|
|
}).c('body').t('https://conversejs.org/@gibson').up()
|
|
|
|
.c('reference', {'xmlns':'urn:xmpp:reference:0', 'begin':'23', 'end':'29', 'type':'mention', 'uri':'xmpp:gibson@montague.lit'}).nodeTree;
|
|
|
|
await view.model.handleMessageStanza(msg);
|
2020-12-08 12:54:14 +01:00
|
|
|
message = await u.waitUntil(() => view.querySelector('.chat-msg__text'));
|
2020-07-08 14:32:06 +02:00
|
|
|
expect(message.classList.length).toEqual(1);
|
|
|
|
expect(message.innerHTML.replace(/<!---->/g, '')).toBe(
|
|
|
|
'hello <span class="mention">z3r0</span> '+
|
|
|
|
'<span class="mention mention--self badge badge-info">tom</span> '+
|
|
|
|
'<span class="mention">mr.robot</span>, how are you?');
|
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
|
|
|
it("highlights all users mentioned via XEP-0372 references in a quoted message",
|
2021-01-29 11:08:28 +01:00
|
|
|
mock.initConverse([], {}, async function (done, _converse) {
|
2020-07-08 14:32:06 +02:00
|
|
|
|
|
|
|
const muc_jid = 'lounge@montague.lit';
|
|
|
|
await mock.openAndEnterChatRoom(_converse, muc_jid, 'tom');
|
|
|
|
const view = _converse.api.chatviews.get(muc_jid);
|
|
|
|
['z3r0', 'mr.robot', 'gibson', 'sw0rdf1sh'].forEach((nick) => {
|
|
|
|
_converse.connection._dataRecv(mock.createRequest(
|
|
|
|
$pres({
|
|
|
|
'to': 'tom@montague.lit/resource',
|
|
|
|
'from': `lounge@montague.lit/${nick}`
|
|
|
|
})
|
|
|
|
.c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'none',
|
|
|
|
'jid': `${nick}@montague.lit/resource`,
|
|
|
|
'role': 'participant'
|
|
|
|
}))
|
|
|
|
);
|
|
|
|
});
|
|
|
|
const msg = $msg({
|
|
|
|
from: 'lounge@montague.lit/gibson',
|
|
|
|
id: u.getUniqueId(),
|
|
|
|
to: 'romeo@montague.lit',
|
|
|
|
type: 'groupchat'
|
|
|
|
}).c('body').t('>hello z3r0 tom mr.robot, how are you?').up()
|
|
|
|
.c('reference', {'xmlns':'urn:xmpp:reference:0', 'begin':'7', 'end':'11', 'type':'mention', 'uri':'xmpp:z3r0@montague.lit'}).up()
|
|
|
|
.c('reference', {'xmlns':'urn:xmpp:reference:0', 'begin':'12', 'end':'15', 'type':'mention', 'uri':'xmpp:romeo@montague.lit'}).up()
|
|
|
|
.c('reference', {'xmlns':'urn:xmpp:reference:0', 'begin':'16', 'end':'24', 'type':'mention', 'uri':'xmpp:mr.robot@montague.lit'}).nodeTree;
|
2020-07-09 06:27:56 +02:00
|
|
|
|
2020-07-08 14:32:06 +02:00
|
|
|
await view.model.handleMessageStanza(msg);
|
2021-02-08 11:27:42 +01:00
|
|
|
await u.waitUntil(() => view.querySelector('.chat-msg__text')?.innerHTML.replace(/<!---->/g, '') ===
|
2020-10-16 09:02:12 +02:00
|
|
|
'<blockquote>hello <span class="mention">z3r0</span> <span class="mention mention--self badge badge-info">tom</span> <span class="mention">mr.robot</span>, how are you?</blockquote>');
|
2021-02-08 11:27:42 +01:00
|
|
|
const message = view.querySelector('.chat-msg__text');
|
|
|
|
expect(message.classList.length).toEqual(1);
|
2020-07-08 14:32:06 +02:00
|
|
|
done();
|
|
|
|
}));
|
2020-07-09 06:27:56 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe("A sent groupchat message", function () {
|
2020-07-08 14:32:06 +02:00
|
|
|
|
|
|
|
describe("in which someone is mentioned", function () {
|
|
|
|
|
|
|
|
it("gets parsed for mentions which get turned into references",
|
2021-01-29 11:08:28 +01:00
|
|
|
mock.initConverse([], {}, async function (done, _converse) {
|
2020-07-08 14:32:06 +02:00
|
|
|
|
|
|
|
const muc_jid = 'lounge@montague.lit';
|
2021-01-04 14:10:43 +01:00
|
|
|
|
|
|
|
// Making the MUC non-anonymous so that real JIDs are included
|
|
|
|
const 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_nonanonymous'
|
|
|
|
];
|
|
|
|
await mock.openAndEnterChatRoom(_converse, muc_jid, 'tom', features);
|
2020-07-08 14:32:06 +02:00
|
|
|
const view = _converse.api.chatviews.get(muc_jid);
|
|
|
|
['z3r0', 'mr.robot', 'gibson', 'sw0rdf1sh', 'Link Mauve', 'robot'].forEach((nick) => {
|
|
|
|
_converse.connection._dataRecv(mock.createRequest(
|
|
|
|
$pres({
|
|
|
|
'to': 'tom@montague.lit/resource',
|
|
|
|
'from': `lounge@montague.lit/${nick}`
|
|
|
|
})
|
|
|
|
.c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'none',
|
|
|
|
'jid': `${nick.replace(/\s/g, '-')}@montague.lit/resource`,
|
|
|
|
'role': 'participant'
|
|
|
|
})));
|
|
|
|
});
|
|
|
|
|
2020-11-27 14:47:51 +01:00
|
|
|
// Also check that nicks from received messages, (but for which we don't have occupant objects) can be mentioned.
|
2020-07-08 14:32:06 +02:00
|
|
|
const stanza = u.toStanza(`
|
|
|
|
<message xmlns="jabber:client"
|
|
|
|
from="${muc_jid}/gh0st"
|
|
|
|
to="${_converse.connection.bare_jid}"
|
|
|
|
type="groupchat">
|
|
|
|
<body>Boo!</body>
|
|
|
|
</message>`);
|
|
|
|
await view.model.handleMessageStanza(stanza);
|
|
|
|
|
|
|
|
// Run a few unit tests for the parseTextForReferences method
|
|
|
|
let [text, references] = view.model.parseTextForReferences('yo @robot')
|
|
|
|
expect(text).toBe('yo robot');
|
|
|
|
expect(references)
|
|
|
|
.toEqual([{"begin":3,"end":8,"value":"robot","type":"mention","uri":"xmpp:robot@montague.lit"}]);
|
|
|
|
|
2020-11-27 22:00:38 +01:00
|
|
|
[text, references] = view.model.parseTextForReferences('@@gh0st')
|
|
|
|
expect(text).toBe('@gh0st');
|
|
|
|
expect(references.length).toBe(1);
|
|
|
|
expect(references)
|
|
|
|
.toEqual([{"begin":1,"end":6,"value":"gh0st","type":"mention","uri":"xmpp:lounge@montague.lit/gh0st"}]);
|
|
|
|
|
2020-07-08 14:32:06 +02:00
|
|
|
[text, references] = view.model.parseTextForReferences('hello z3r0')
|
|
|
|
expect(references.length).toBe(0);
|
|
|
|
expect(text).toBe('hello z3r0');
|
|
|
|
|
|
|
|
[text, references] = view.model.parseTextForReferences('hello @z3r0')
|
|
|
|
expect(references.length).toBe(1);
|
|
|
|
expect(text).toBe('hello z3r0');
|
|
|
|
expect(references)
|
|
|
|
.toEqual([{"begin":6,"end":10,"value":"z3r0","type":"mention","uri":"xmpp:z3r0@montague.lit"}]);
|
|
|
|
|
|
|
|
[text, references] = view.model.parseTextForReferences('hello @some1 @z3r0 @gibson @mr.robot, how are you?')
|
|
|
|
expect(text).toBe('hello @some1 z3r0 gibson mr.robot, how are you?');
|
|
|
|
expect(references)
|
|
|
|
.toEqual([{"begin":13,"end":17,"value":"z3r0","type":"mention","uri":"xmpp:z3r0@montague.lit"},
|
|
|
|
{"begin":18,"end":24,"value":"gibson","type":"mention","uri":"xmpp:gibson@montague.lit"},
|
|
|
|
{"begin":25,"end":33,"value":"mr.robot","type":"mention","uri":"xmpp:mr.robot@montague.lit"}]);
|
|
|
|
|
|
|
|
[text, references] = view.model.parseTextForReferences('yo @gib')
|
|
|
|
expect(text).toBe('yo @gib');
|
|
|
|
expect(references.length).toBe(0);
|
|
|
|
|
|
|
|
[text, references] = view.model.parseTextForReferences('yo @gibsonian')
|
|
|
|
expect(text).toBe('yo @gibsonian');
|
|
|
|
expect(references.length).toBe(0);
|
|
|
|
|
|
|
|
[text, references] = view.model.parseTextForReferences('yo @GiBsOn')
|
|
|
|
expect(text).toBe('yo gibson');
|
|
|
|
expect(references.length).toBe(1);
|
|
|
|
|
|
|
|
[text, references] = view.model.parseTextForReferences('@gibson')
|
|
|
|
expect(text).toBe('gibson');
|
|
|
|
expect(references.length).toBe(1);
|
|
|
|
expect(references)
|
|
|
|
.toEqual([{"begin":0,"end":6,"value":"gibson","type":"mention","uri":"xmpp:gibson@montague.lit"}]);
|
|
|
|
|
|
|
|
[text, references] = view.model.parseTextForReferences('hi @Link Mauve how are you?')
|
|
|
|
expect(text).toBe('hi Link Mauve how are you?');
|
|
|
|
expect(references.length).toBe(1);
|
|
|
|
expect(references)
|
|
|
|
.toEqual([{"begin":3,"end":13,"value":"Link Mauve","type":"mention","uri":"xmpp:Link-Mauve@montague.lit"}]);
|
|
|
|
|
|
|
|
[text, references] = view.model.parseTextForReferences('https://example.org/@gibson')
|
|
|
|
expect(text).toBe('https://example.org/@gibson');
|
|
|
|
expect(references.length).toBe(0);
|
2020-11-27 14:47:51 +01:00
|
|
|
expect(references).toEqual([]);
|
2020-07-08 14:32:06 +02:00
|
|
|
|
|
|
|
[text, references] = view.model.parseTextForReferences('mail@gibson.com')
|
|
|
|
expect(text).toBe('mail@gibson.com');
|
|
|
|
expect(references.length).toBe(0);
|
|
|
|
expect(references)
|
|
|
|
.toEqual([]);
|
|
|
|
|
2020-07-09 06:27:56 +02:00
|
|
|
[text, references] = view.model.parseTextForReferences(
|
|
|
|
"Welcome @gibson 💩 We have a guide on how to do that here: https://conversejs.org/docs/html/index.html");
|
|
|
|
expect(text).toBe("Welcome gibson 💩 We have a guide on how to do that here: https://conversejs.org/docs/html/index.html");
|
|
|
|
expect(references.length).toBe(1);
|
|
|
|
expect(references).toEqual([{"begin":8,"end":14,"value":"gibson","type":"mention","uri":"xmpp:gibson@montague.lit"}]);
|
|
|
|
|
2020-07-08 14:32:06 +02:00
|
|
|
[text, references] = view.model.parseTextForReferences(
|
|
|
|
'https://linkmauve.fr@Link Mauve/ https://linkmauve.fr/@github/is_back gibson@gibson.com gibson@Link Mauve.fr')
|
|
|
|
expect(text).toBe(
|
|
|
|
'https://linkmauve.fr@Link Mauve/ https://linkmauve.fr/@github/is_back gibson@gibson.com gibson@Link Mauve.fr');
|
|
|
|
expect(references.length).toBe(0);
|
|
|
|
expect(references)
|
|
|
|
.toEqual([]);
|
|
|
|
|
|
|
|
[text, references] = view.model.parseTextForReferences('@gh0st where are you?')
|
|
|
|
expect(text).toBe('gh0st where are you?');
|
|
|
|
expect(references.length).toBe(1);
|
|
|
|
expect(references)
|
|
|
|
.toEqual([{"begin":0,"end":5,"value":"gh0st","type":"mention","uri":"xmpp:lounge@montague.lit/gh0st"}]);
|
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
|
|
|
it("gets parsed for mentions as indicated with an @ preceded by a space or at the start of the text",
|
2021-01-29 11:08:28 +01:00
|
|
|
mock.initConverse([], {}, async function (done, _converse) {
|
2020-07-08 14:32:06 +02:00
|
|
|
|
|
|
|
const muc_jid = 'lounge@montague.lit';
|
|
|
|
await mock.openAndEnterChatRoom(_converse, muc_jid, 'tom');
|
|
|
|
const view = _converse.api.chatviews.get(muc_jid);
|
|
|
|
['NotAnAdress', 'darnuria'].forEach((nick) => {
|
|
|
|
_converse.connection._dataRecv(mock.createRequest(
|
|
|
|
$pres({
|
|
|
|
'to': 'tom@montague.lit/resource',
|
|
|
|
'from': `lounge@montague.lit/${nick}`
|
|
|
|
})
|
|
|
|
.c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'none',
|
|
|
|
'jid': `${nick.replace(/\s/g, '-')}@montague.lit/resource`,
|
|
|
|
'role': 'participant'
|
|
|
|
})));
|
|
|
|
});
|
|
|
|
|
|
|
|
// Test that we don't match @nick in email adresses.
|
|
|
|
let [text, references] = view.model.parseTextForReferences('contact contact@NotAnAdress.eu');
|
|
|
|
expect(references.length).toBe(0);
|
|
|
|
expect(text).toBe('contact contact@NotAnAdress.eu');
|
|
|
|
|
|
|
|
// Test that we don't match @nick in url
|
|
|
|
[text, references] = view.model.parseTextForReferences('nice website https://darnuria.eu/@darnuria');
|
|
|
|
expect(references.length).toBe(0);
|
|
|
|
expect(text).toBe('nice website https://darnuria.eu/@darnuria');
|
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
|
|
|
it("properly encodes the URIs in sent out references",
|
2021-01-29 11:08:28 +01:00
|
|
|
mock.initConverse([], {}, async function (done, _converse) {
|
2020-07-08 14:32:06 +02:00
|
|
|
|
|
|
|
const muc_jid = 'lounge@montague.lit';
|
|
|
|
await mock.openAndEnterChatRoom(_converse, muc_jid, 'tom');
|
|
|
|
const view = _converse.api.roomviews.get(muc_jid);
|
|
|
|
_converse.connection._dataRecv(mock.createRequest(
|
|
|
|
$pres({
|
|
|
|
'to': 'tom@montague.lit/resource',
|
|
|
|
'from': `lounge@montague.lit/Link Mauve`
|
|
|
|
})
|
|
|
|
.c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'none',
|
|
|
|
'role': 'participant'
|
|
|
|
})));
|
|
|
|
await u.waitUntil(() => view.model.occupants.length === 2);
|
|
|
|
|
2021-02-11 15:05:04 +01:00
|
|
|
const textarea = await u.waitUntil(() => view.querySelector('.chat-textarea'));
|
2020-07-08 14:32:06 +02:00
|
|
|
textarea.value = 'hello @Link Mauve'
|
|
|
|
const enter_event = {
|
|
|
|
'target': textarea,
|
|
|
|
'preventDefault': function preventDefault () {},
|
|
|
|
'stopPropagation': function stopPropagation () {},
|
|
|
|
'keyCode': 13 // Enter
|
|
|
|
}
|
2021-02-11 15:05:04 +01:00
|
|
|
const bottom_panel = view.querySelector('converse-muc-bottom-panel');
|
|
|
|
bottom_panel.onKeyDown(enter_event);
|
2021-02-08 11:27:42 +01:00
|
|
|
await u.waitUntil(() => view.querySelectorAll('.chat-msg__text').length);
|
2021-03-13 11:37:07 +01:00
|
|
|
const sent_stanzas = _converse.connection.sent_stanzas;
|
|
|
|
const msg = await u.waitUntil(() => sent_stanzas.filter(s => s.nodeName.toLowerCase() === 'message').pop());
|
|
|
|
expect(Strophe.serialize(msg))
|
|
|
|
.toBe(`<message from="romeo@montague.lit/orchard" id="${msg.getAttribute("id")}" `+
|
2020-07-08 14:32:06 +02:00
|
|
|
`to="lounge@montague.lit" type="groupchat" `+
|
|
|
|
`xmlns="jabber:client">`+
|
|
|
|
`<body>hello Link Mauve</body>`+
|
|
|
|
`<active xmlns="http://jabber.org/protocol/chatstates"/>`+
|
|
|
|
`<reference begin="6" end="16" type="mention" uri="xmpp:lounge@montague.lit/Link%20Mauve" xmlns="urn:xmpp:reference:0"/>`+
|
2021-03-13 11:37:07 +01:00
|
|
|
`<origin-id id="${msg.querySelector('origin-id').getAttribute("id")}" xmlns="urn:xmpp:sid:0"/>`+
|
2020-07-08 14:32:06 +02:00
|
|
|
`</message>`);
|
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
|
|
|
it("can get corrected and given new references",
|
2021-01-29 11:08:28 +01:00
|
|
|
mock.initConverse([], {}, async function (done, _converse) {
|
2020-07-08 14:32:06 +02:00
|
|
|
|
|
|
|
const muc_jid = 'lounge@montague.lit';
|
2021-01-04 14:10:43 +01:00
|
|
|
|
|
|
|
// Making the MUC non-anonymous so that real JIDs are included
|
|
|
|
const 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_nonanonymous'
|
|
|
|
];
|
|
|
|
await mock.openAndEnterChatRoom(_converse, muc_jid, 'tom', features);
|
2020-07-08 14:32:06 +02:00
|
|
|
const view = _converse.api.chatviews.get(muc_jid);
|
|
|
|
['z3r0', 'mr.robot', 'gibson', 'sw0rdf1sh'].forEach((nick) => {
|
|
|
|
_converse.connection._dataRecv(mock.createRequest(
|
|
|
|
$pres({
|
|
|
|
'to': 'tom@montague.lit/resource',
|
|
|
|
'from': `lounge@montague.lit/${nick}`
|
|
|
|
})
|
|
|
|
.c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'none',
|
|
|
|
'jid': `${nick}@montague.lit/resource`,
|
|
|
|
'role': 'participant'
|
|
|
|
})));
|
|
|
|
});
|
|
|
|
await u.waitUntil(() => view.model.occupants.length === 5);
|
|
|
|
|
2021-02-11 15:05:04 +01:00
|
|
|
const textarea = await u.waitUntil(() => view.querySelector('textarea.chat-textarea'));
|
2020-07-08 14:32:06 +02:00
|
|
|
textarea.value = 'hello @z3r0 @gibson @mr.robot, how are you?'
|
|
|
|
const enter_event = {
|
|
|
|
'target': textarea,
|
|
|
|
'preventDefault': function preventDefault () {},
|
|
|
|
'stopPropagation': function stopPropagation () {},
|
|
|
|
'keyCode': 13 // Enter
|
|
|
|
}
|
2021-02-11 15:05:04 +01:00
|
|
|
const bottom_panel = view.querySelector('converse-muc-bottom-panel');
|
|
|
|
bottom_panel.onKeyDown(enter_event);
|
2021-02-08 11:27:42 +01:00
|
|
|
await u.waitUntil(() => view.querySelectorAll('.chat-msg__text').length);
|
2020-07-08 14:32:06 +02:00
|
|
|
|
|
|
|
const last_msg_sel = 'converse-chat-message:last-child .chat-msg__text';
|
|
|
|
await u.waitUntil(() =>
|
2021-03-10 12:17:23 +01:00
|
|
|
view.querySelector(last_msg_sel).innerHTML.replace(/<!---->/g, '') ===
|
2020-07-08 14:32:06 +02:00
|
|
|
'hello <span class="mention">z3r0</span> <span class="mention">gibson</span> <span class="mention">mr.robot</span>, how are you?'
|
|
|
|
);
|
|
|
|
|
2021-03-13 11:37:07 +01:00
|
|
|
const sent_stanzas = _converse.connection.sent_stanzas;
|
|
|
|
const msg = await u.waitUntil(() => sent_stanzas.filter(s => s.nodeName.toLowerCase() === 'message').pop());
|
|
|
|
expect(Strophe.serialize(msg))
|
|
|
|
.toBe(`<message from="romeo@montague.lit/orchard" id="${msg.getAttribute("id")}" `+
|
2020-07-08 14:32:06 +02:00
|
|
|
`to="lounge@montague.lit" type="groupchat" `+
|
|
|
|
`xmlns="jabber:client">`+
|
|
|
|
`<body>hello z3r0 gibson mr.robot, how are you?</body>`+
|
|
|
|
`<active xmlns="http://jabber.org/protocol/chatstates"/>`+
|
|
|
|
`<reference begin="6" end="10" type="mention" uri="xmpp:z3r0@montague.lit" xmlns="urn:xmpp:reference:0"/>`+
|
|
|
|
`<reference begin="11" end="17" type="mention" uri="xmpp:gibson@montague.lit" xmlns="urn:xmpp:reference:0"/>`+
|
|
|
|
`<reference begin="18" end="26" type="mention" uri="xmpp:mr.robot@montague.lit" xmlns="urn:xmpp:reference:0"/>`+
|
2021-03-13 11:37:07 +01:00
|
|
|
`<origin-id id="${msg.querySelector('origin-id').getAttribute("id")}" xmlns="urn:xmpp:sid:0"/>`+
|
2020-07-08 14:32:06 +02:00
|
|
|
`</message>`);
|
|
|
|
|
2020-12-08 12:54:14 +01:00
|
|
|
const action = await u.waitUntil(() => view.querySelector('.chat-msg .chat-msg__action'));
|
2020-07-08 14:32:06 +02:00
|
|
|
action.style.opacity = 1;
|
|
|
|
action.click();
|
|
|
|
|
|
|
|
expect(textarea.value).toBe('hello @z3r0 @gibson @mr.robot, how are you?');
|
|
|
|
expect(view.model.messages.at(0).get('correcting')).toBe(true);
|
2020-12-08 12:54:14 +01:00
|
|
|
expect(view.querySelectorAll('.chat-msg').length).toBe(1);
|
|
|
|
await u.waitUntil(() => u.hasClass('correcting', view.querySelector('.chat-msg')), 500);
|
2020-07-08 14:32:06 +02:00
|
|
|
|
|
|
|
textarea.value = 'hello @z3r0 @gibson @sw0rdf1sh, how are you?';
|
2021-02-11 15:05:04 +01:00
|
|
|
bottom_panel.onKeyDown(enter_event);
|
2020-12-08 12:54:14 +01:00
|
|
|
await u.waitUntil(() => view.querySelector('.chat-msg__text').textContent ===
|
2020-07-08 14:32:06 +02:00
|
|
|
'hello z3r0 gibson sw0rdf1sh, how are you?', 500);
|
|
|
|
|
2021-03-13 11:37:07 +01:00
|
|
|
const correction = sent_stanzas.filter(s => s.nodeName.toLowerCase() === 'message').pop();
|
|
|
|
expect(Strophe.serialize(correction))
|
|
|
|
.toBe(`<message from="romeo@montague.lit/orchard" id="${correction.getAttribute("id")}" `+
|
2020-07-08 14:32:06 +02:00
|
|
|
`to="lounge@montague.lit" type="groupchat" `+
|
|
|
|
`xmlns="jabber:client">`+
|
|
|
|
`<body>hello z3r0 gibson sw0rdf1sh, how are you?</body>`+
|
|
|
|
`<active xmlns="http://jabber.org/protocol/chatstates"/>`+
|
|
|
|
`<reference begin="6" end="10" type="mention" uri="xmpp:z3r0@montague.lit" xmlns="urn:xmpp:reference:0"/>`+
|
|
|
|
`<reference begin="11" end="17" type="mention" uri="xmpp:gibson@montague.lit" xmlns="urn:xmpp:reference:0"/>`+
|
|
|
|
`<reference begin="18" end="27" type="mention" uri="xmpp:sw0rdf1sh@montague.lit" xmlns="urn:xmpp:reference:0"/>`+
|
2021-03-13 11:37:07 +01:00
|
|
|
`<replace id="${msg.getAttribute("id")}" xmlns="urn:xmpp:message-correct:0"/>`+
|
|
|
|
`<origin-id id="${correction.querySelector('origin-id').getAttribute("id")}" xmlns="urn:xmpp:sid:0"/>`+
|
2020-07-08 14:32:06 +02:00
|
|
|
`</message>`);
|
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
2020-10-27 22:48:22 +01:00
|
|
|
it("includes a XEP-0372 references to that person",
|
2021-01-29 11:08:28 +01:00
|
|
|
mock.initConverse([], {}, async function (done, _converse) {
|
2020-07-08 14:32:06 +02:00
|
|
|
|
|
|
|
const muc_jid = 'lounge@montague.lit';
|
|
|
|
await mock.openAndEnterChatRoom(_converse, muc_jid, 'romeo');
|
|
|
|
const view = _converse.api.chatviews.get(muc_jid);
|
|
|
|
['z3r0', 'mr.robot', 'gibson', 'sw0rdf1sh'].forEach((nick) => {
|
|
|
|
_converse.connection._dataRecv(mock.createRequest(
|
|
|
|
$pres({
|
|
|
|
'to': 'tom@montague.lit/resource',
|
|
|
|
'from': `lounge@montague.lit/${nick}`
|
|
|
|
})
|
|
|
|
.c('x', {xmlns: Strophe.NS.MUC_USER})
|
|
|
|
.c('item', {
|
|
|
|
'affiliation': 'none',
|
|
|
|
'jid': `${nick}@montague.lit/resource`,
|
|
|
|
'role': 'participant'
|
|
|
|
})));
|
|
|
|
});
|
|
|
|
await u.waitUntil(() => view.model.occupants.length === 5);
|
|
|
|
|
|
|
|
spyOn(_converse.connection, 'send');
|
2021-02-11 15:05:04 +01:00
|
|
|
const textarea = await u.waitUntil(() => view.querySelector('.chat-textarea'));
|
2020-07-08 14:32:06 +02:00
|
|
|
textarea.value = 'hello @z3r0 @gibson @mr.robot, how are you?'
|
|
|
|
const enter_event = {
|
|
|
|
'target': textarea,
|
|
|
|
'preventDefault': function preventDefault () {},
|
|
|
|
'stopPropagation': function stopPropagation () {},
|
|
|
|
'keyCode': 13 // Enter
|
|
|
|
}
|
2021-02-11 15:05:04 +01:00
|
|
|
const bottom_panel = view.querySelector('converse-muc-bottom-panel');
|
|
|
|
bottom_panel.onKeyDown(enter_event);
|
2021-02-08 11:27:42 +01:00
|
|
|
await u.waitUntil(() => view.querySelectorAll('.chat-msg__text').length);
|
2020-07-08 14:32:06 +02:00
|
|
|
|
2021-03-18 16:21:15 +01:00
|
|
|
const msg = _converse.connection.send.calls.all()[0].args[0];
|
2020-07-08 14:32:06 +02:00
|
|
|
expect(msg.toLocaleString())
|
|
|
|
.toBe(`<message from="romeo@montague.lit/orchard" id="${msg.nodeTree.getAttribute("id")}" `+
|
|
|
|
`to="lounge@montague.lit" type="groupchat" `+
|
|
|
|
`xmlns="jabber:client">`+
|
|
|
|
`<body>hello z3r0 gibson mr.robot, how are you?</body>`+
|
|
|
|
`<active xmlns="http://jabber.org/protocol/chatstates"/>`+
|
2021-01-04 14:10:43 +01:00
|
|
|
`<reference begin="6" end="10" type="mention" uri="xmpp:${muc_jid}/z3r0" xmlns="urn:xmpp:reference:0"/>`+
|
|
|
|
`<reference begin="11" end="17" type="mention" uri="xmpp:${muc_jid}/gibson" xmlns="urn:xmpp:reference:0"/>`+
|
|
|
|
`<reference begin="18" end="26" type="mention" uri="xmpp:${muc_jid}/mr.robot" xmlns="urn:xmpp:reference:0"/>`+
|
2020-07-08 14:32:06 +02:00
|
|
|
`<origin-id id="${msg.nodeTree.querySelector('origin-id').getAttribute("id")}" xmlns="urn:xmpp:sid:0"/>`+
|
|
|
|
`</message>`);
|
|
|
|
done();
|
|
|
|
}));
|
|
|
|
});
|
2020-07-09 06:27:56 +02:00
|
|
|
|
|
|
|
it("highlights all users mentioned via XEP-0372 references in a quoted message",
|
2021-01-29 11:08:28 +01:00
|
|
|
mock.initConverse([], {}, async function (done, _converse) {
|
2020-07-09 06:27:56 +02:00
|
|
|
|
|
|
|
const members = [{'jid': 'gibson@gibson.net', 'nick': 'gibson', 'affiliation': 'member'}];
|
|
|
|
const muc_jid = 'lounge@montague.lit';
|
|
|
|
await mock.openAndEnterChatRoom(_converse, muc_jid, 'tom', [], members);
|
|
|
|
const view = _converse.api.chatviews.get(muc_jid);
|
2021-02-11 15:05:04 +01:00
|
|
|
const textarea = await u.waitUntil(() => view.querySelector('.chat-textarea'));
|
2020-07-09 06:27:56 +02:00
|
|
|
textarea.value = "Welcome @gibson 💩 We have a guide on how to do that here: https://conversejs.org/docs/html/index.html";
|
|
|
|
const enter_event = {
|
|
|
|
'target': textarea,
|
|
|
|
'preventDefault': function preventDefault () {},
|
|
|
|
'stopPropagation': function stopPropagation () {},
|
|
|
|
'keyCode': 13 // Enter
|
|
|
|
}
|
2021-02-11 15:05:04 +01:00
|
|
|
const bottom_panel = view.querySelector('converse-muc-bottom-panel');
|
|
|
|
bottom_panel.onKeyDown(enter_event);
|
2020-12-08 12:54:14 +01:00
|
|
|
const message = await u.waitUntil(() => view.querySelector('.chat-msg__text'));
|
2020-07-09 06:27:56 +02:00
|
|
|
expect(message.innerHTML.replace(/<!---->/g, '')).toEqual(
|
|
|
|
`Welcome <span class="mention">gibson</span> <span title=":poop:">💩</span> `+
|
|
|
|
`We have a guide on how to do that here: `+
|
|
|
|
`<a target="_blank" rel="noopener" href="https://conversejs.org/docs/html/index.html">https://conversejs.org/docs/html/index.html</a>`);
|
|
|
|
done();
|
|
|
|
}));
|
2020-07-08 14:32:06 +02:00
|
|
|
});
|