Skip to content

Commit

Permalink
Fixes #3585
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbrand committed Feb 12, 2025
1 parent c13dcd8 commit 4fc23a6
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 133 deletions.
2 changes: 1 addition & 1 deletion src/headless/shared/model-with-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ export default function ModelWithMessages(BaseModel) {

const stanza = stx`
<message xmlns="jabber:client"
from="${message.get('from') || api.connection.get().jid}"
from="${message.get('type') === 'groupchat' ? api.connection.get().jid : message.get('from')}"
to="${message.get('to') || this.get('jid')}"
type="${this.get('message_type')}"
id="${(edited && u.getUniqueId()) || msgid}">
Expand Down
22 changes: 13 additions & 9 deletions src/plugins/muc-views/tests/corrections.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const { Strophe, u, stx } = converse.env;

describe("A Groupchat Message", function () {

beforeAll(() => jasmine.addMatchers({ toEqualStanza: jasmine.toEqualStanza }));

it("can be replaced with a correction",
mock.initConverse([], {}, async function (_converse) {

Expand Down Expand Up @@ -173,6 +175,8 @@ describe("A Groupchat Message", function () {
it("can be sent as a correction by using the up arrow",
mock.initConverse([], {}, async function (_converse) {

const { api } = _converse;
const { jid: own_jid } = api.connection.get();
const nick = 'romeo'
const muc_jid = '[email protected]';
await mock.openAndEnterChatRoom(_converse, muc_jid, nick);
Expand Down Expand Up @@ -220,15 +224,15 @@ describe("A Groupchat Message", function () {

expect(_converse.api.connection.get().send).toHaveBeenCalled();
const msg = _converse.api.connection.get().send.calls.all()[0].args[0];
expect(Strophe.serialize(msg)).toBe(
`<message from="${muc_jid}/${nick}" id="${msg.getAttribute("id")}" `+
`to="[email protected]" type="groupchat" `+
`xmlns="jabber:client">`+
`<body>But soft, what light through yonder window breaks?</body>`+
`<active xmlns="http://jabber.org/protocol/chatstates"/>`+
`<replace id="${first_msg.get("msgid")}" xmlns="urn:xmpp:message-correct:0"/>`+
`<origin-id id="${msg.querySelector('origin-id').getAttribute("id")}" xmlns="urn:xmpp:sid:0"/>`+
`</message>`);
expect(msg).toEqualStanza(stx`
<message from="${own_jid}" id="${msg.getAttribute("id")}"
to="[email protected]" type="groupchat"
xmlns="jabber:client">
<body>But soft, what light through yonder window breaks?</body>
<active xmlns="http://jabber.org/protocol/chatstates"/>
<replace id="${first_msg.get("msgid")}" xmlns="urn:xmpp:message-correct:0"/>
<origin-id id="${msg.querySelector('origin-id').getAttribute("id")}" xmlns="urn:xmpp:sid:0"/>
</message>`);

expect(view.model.messages.models.length).toBe(1);
const corrected_message = view.model.messages.at(0);
Expand Down
30 changes: 16 additions & 14 deletions src/plugins/muc-views/tests/http-file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const { Strophe, sizzle, u, stx } = converse.env;

describe("XEP-0363: HTTP File Upload", function () {

beforeAll(() => jasmine.addMatchers({ toEqualStanza: jasmine.toEqualStanza }));

describe("When not supported", function () {
describe("A file upload toolbar button", function () {

Expand Down Expand Up @@ -124,20 +126,20 @@ describe("XEP-0363: HTTP File Upload", function () {
_converse.api.connection.get()._dataRecv(mock.createRequest(stanza));

await u.waitUntil(() => sent_stanza, 1000);
expect(Strophe.serialize(sent_stanza)).toBe(
`<message `+
`from="${muc_jid}/${nick}" `+
`id="${sent_stanza.getAttribute("id")}" `+
`to="[email protected]" `+
`type="groupchat" `+
`xmlns="jabber:client">`+
`<body>${message}</body>`+
`<active xmlns="http://jabber.org/protocol/chatstates"/>`+
`<x xmlns="jabber:x:oob">`+
`<url>${message}</url>`+
`</x>`+
`<origin-id id="${sent_stanza.querySelector('origin-id').getAttribute("id")}" xmlns="urn:xmpp:sid:0"/>`+
`</message>`);
expect(sent_stanza).toEqualStanza(stx`
<message
from="[email protected]/orchard"
id="${sent_stanza.getAttribute("id")}"
to="[email protected]"
type="groupchat"
xmlns="jabber:client">
<body>${message}</body>
<active xmlns="http://jabber.org/protocol/chatstates"/>
<x xmlns="jabber:x:oob">
<url>${message}</url>
</x>
<origin-id id="${sent_stanza.querySelector('origin-id').getAttribute("id")}" xmlns="urn:xmpp:sid:0"/>
</message>`);
const img_link_el = await u.waitUntil(() => view.querySelector('converse-chat-message-body .chat-image__link'), 1000);
// Check that the image renders
expect(img_link_el.outerHTML.replace(/<!-.*?->/g, '').trim()).toEqual(
Expand Down
78 changes: 43 additions & 35 deletions src/plugins/muc-views/tests/mentions.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,13 @@ describe("An incoming groupchat message", function () {
it("properly renders mentions that contain the pipe character",
mock.initConverse([], {}, async function (_converse) {

const { api } = _converse;
const { jid: own_jid } = api.connection.get();
const muc_jid = '[email protected]';
const nick = 'romeo';
const muc = await mock.openAndEnterChatRoom(_converse, muc_jid, nick);
const view = _converse.chatboxviews.get(muc_jid);
_converse.api.connection.get()._dataRecv(mock.createRequest(
api.connection.get()._dataRecv(mock.createRequest(
stx`<presence
to="[email protected]/resource"
from="[email protected]/ThUnD3r|Gr33n"
Expand Down Expand Up @@ -116,7 +118,7 @@ describe("An incoming groupchat message", function () {
const sent_stanzas = _converse.api.connection.get().sent_stanzas;
const msg = await u.waitUntil(() => sent_stanzas.filter(s => s.nodeName.toLowerCase() === 'message').pop());
expect(msg).toEqualStanza(
stx`<message from="${muc_jid}/${nick}"
stx`<message from="${own_jid}"
id="${msg.getAttribute("id")}"
to="[email protected]" type="groupchat"
xmlns="jabber:client">
Expand Down Expand Up @@ -336,6 +338,8 @@ describe("A sent groupchat message", function () {
it("properly encodes the URIs in sent out references",
mock.initConverse([], {}, async function (_converse) {

const { api } = _converse;
const { jid: own_jid } = api.connection.get();
const nick = 'tom';
const muc_jid = '[email protected]';
await mock.openAndEnterChatRoom(_converse, muc_jid, nick);
Expand Down Expand Up @@ -364,22 +368,24 @@ describe("A sent groupchat message", function () {
await u.waitUntil(() => view.querySelectorAll('.chat-msg__text').length);
const sent_stanzas = _converse.api.connection.get().sent_stanzas;
const msg = await u.waitUntil(() => sent_stanzas.filter(s => s.nodeName.toLowerCase() === 'message').pop());
expect(Strophe.serialize(msg))
.toBe(`<message from="${muc_jid}/${nick}" id="${msg.getAttribute("id")}" `+
`to="[email protected]" 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:[email protected]/Link%20Mauve" xmlns="urn:xmpp:reference:0"/>`+
`<origin-id id="${msg.querySelector('origin-id').getAttribute("id")}" xmlns="urn:xmpp:sid:0"/>`+
`</message>`);
expect(msg).toEqualStanza(stx`
<message from="${own_jid}" id="${msg.getAttribute("id")}"
to="[email protected]" 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:[email protected]/Link%20Mauve" xmlns="urn:xmpp:reference:0"/>
<origin-id id="${msg.querySelector('origin-id').getAttribute("id")}" xmlns="urn:xmpp:sid:0"/>
</message>`);
}));

it("can get corrected and given new references",
mock.initConverse([], {}, async function (_converse) {

const nick = 'tom';
const muc_jid = '[email protected]';
const { api } = _converse;
const { jid: own_jid } = api.connection.get();

// Making the MUC non-anonymous so that real JIDs are included
const features = [
Expand Down Expand Up @@ -432,17 +438,17 @@ describe("A sent groupchat message", function () {

const sent_stanzas = _converse.api.connection.get().sent_stanzas;
const msg = await u.waitUntil(() => sent_stanzas.filter(s => s.nodeName.toLowerCase() === 'message').pop());
expect(Strophe.serialize(msg))
.toBe(`<message from="${muc_jid}/${nick}" id="${msg.getAttribute("id")}" `+
`to="[email protected]" 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:[email protected]" xmlns="urn:xmpp:reference:0"/>`+
`<reference begin="11" end="17" type="mention" uri="xmpp:[email protected]" xmlns="urn:xmpp:reference:0"/>`+
`<reference begin="18" end="26" type="mention" uri="xmpp:[email protected]" xmlns="urn:xmpp:reference:0"/>`+
`<origin-id id="${msg.querySelector('origin-id').getAttribute("id")}" xmlns="urn:xmpp:sid:0"/>`+
`</message>`);
expect(msg).toEqualStanza(stx`
<message from="${own_jid}" id="${msg.getAttribute("id")}"
to="[email protected]" 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:[email protected]" xmlns="urn:xmpp:reference:0"/>
<reference begin="11" end="17" type="mention" uri="xmpp:[email protected]" xmlns="urn:xmpp:reference:0"/>
<reference begin="18" end="26" type="mention" uri="xmpp:[email protected]" xmlns="urn:xmpp:reference:0"/>
<origin-id id="${msg.querySelector('origin-id').getAttribute("id")}" xmlns="urn:xmpp:sid:0"/>
</message>`);

const action = await u.waitUntil(() => view.querySelector('.chat-msg .chat-msg__action'));
action.style.opacity = 1;
Expand All @@ -459,23 +465,25 @@ describe("A sent groupchat message", function () {
'hello z3r0 gibson sw0rdf1sh, how are you?', 500);

const correction = sent_stanzas.filter(s => s.nodeName.toLowerCase() === 'message').pop();
expect(Strophe.serialize(correction))
.toBe(`<message from="${muc_jid}/${nick}" id="${correction.getAttribute("id")}" `+
`to="[email protected]" 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:[email protected]" xmlns="urn:xmpp:reference:0"/>`+
`<reference begin="11" end="17" type="mention" uri="xmpp:[email protected]" xmlns="urn:xmpp:reference:0"/>`+
`<reference begin="18" end="27" type="mention" uri="xmpp:[email protected]" xmlns="urn:xmpp:reference:0"/>`+
`<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"/>`+
`</message>`);
expect(correction).toEqualStanza(stx`
<message from="${own_jid}" id="${correction.getAttribute("id")}"
to="[email protected]" 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:[email protected]" xmlns="urn:xmpp:reference:0"/>
<reference begin="11" end="17" type="mention" uri="xmpp:[email protected]" xmlns="urn:xmpp:reference:0"/>
<reference begin="18" end="27" type="mention" uri="xmpp:[email protected]" xmlns="urn:xmpp:reference:0"/>
<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"/>
</message>`);
}));

it("includes a XEP-0372 references to that person",
mock.initConverse([], { auto_register_muc_nickname: false }, async function (_converse) {

const { api } = _converse;
const { jid: own_jid } = api.connection.get();
const nick = 'romeo';
const muc_jid = '[email protected]';
const muc = await mock.openAndEnterChatRoom(_converse, muc_jid, nick);
Expand Down Expand Up @@ -509,7 +517,7 @@ describe("A sent groupchat message", function () {

const msg = _converse.api.connection.get().send.calls.all()[0].args[0];
expect(msg).toEqualStanza(
stx`<message from="${muc_jid}/${nick}"
stx`<message from="${own_jid}"
id="${msg.getAttribute("id")}"
to="[email protected]"
type="groupchat"
Expand Down
36 changes: 19 additions & 17 deletions src/plugins/muc-views/tests/unfurls.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const { Strophe, u, stx } = converse.env;

describe("A Groupchat Message", function () {

beforeAll(() => jasmine.addMatchers({ toEqualStanza: jasmine.toEqualStanza }));

it("will render an unfurl based on OGP data", mock.initConverse(['chatBoxesFetched'], {}, async function (_converse) {
const nick = 'romeo';
const muc_jid = '[email protected]';
Expand Down Expand Up @@ -404,6 +406,9 @@ describe("A Groupchat Message", function () {

it("will not render an unfurl that has been removed in a subsequent correction",
mock.initConverse(['chatBoxesFetched'], { auto_register_muc_nickname: false }, async function (_converse) {

const { api } = _converse;
const { jid: own_jid } = api.connection.get();
const nick = 'romeo';
const muc_jid = '[email protected]';
await mock.openAndEnterChatRoom(_converse, muc_jid, nick);
Expand All @@ -426,17 +431,15 @@ describe("A Groupchat Message", function () {
message_form.onKeyDown(enter_event);

await u.waitUntil(() => view.querySelectorAll('.chat-msg').length === 1);
expect(view.querySelector('.chat-msg__text').textContent)
.toBe(unfurl_url);
expect(view.querySelector('.chat-msg__text').textContent).toBe(unfurl_url);

let msg = _converse.api.connection.get().send.calls.all()[1].args[0];
expect(Strophe.serialize(msg))
.toBe(
`<message from="${muc_jid}/${nick}" id="${msg.getAttribute('id')}" to="${muc_jid}" type="groupchat" xmlns="jabber:client">`+
`<body>${unfurl_url}</body>`+
`<active xmlns="http://jabber.org/protocol/chatstates"/>`+
`<origin-id id="${msg.querySelector('origin-id')?.getAttribute('id')}" xmlns="urn:xmpp:sid:0"/>`+
`</message>`);
expect(msg).toEqualStanza(stx`
<message from="${own_jid}" id="${msg.getAttribute('id')}" to="${muc_jid}" type="groupchat" xmlns="jabber:client">
<body>${unfurl_url}</body>
<active xmlns="http://jabber.org/protocol/chatstates"/>
<origin-id id="${msg.querySelector('origin-id')?.getAttribute('id')}" xmlns="urn:xmpp:sid:0"/>
</message>`);

const el = await u.waitUntil(() => view.querySelector('.chat-msg__text'));
expect(el.textContent).toBe(unfurl_url);
Expand Down Expand Up @@ -478,13 +481,12 @@ describe("A Groupchat Message", function () {
const getSentMessages = () => _converse.api.connection.get().send.calls.all().map(c => c.args[0]).filter(s => s.nodeName === 'message');
await u.waitUntil(() => getSentMessages().length == 2);
msg = getSentMessages().pop();
expect(Strophe.serialize(msg))
.toBe(
`<message from="${muc_jid}/${nick}" id="${msg.getAttribute('id')}" to="${muc_jid}" type="groupchat" xmlns="jabber:client">`+
`<body>never mind</body>`+
`<active xmlns="http://jabber.org/protocol/chatstates"/>`+
`<replace id="${msg.querySelector('replace')?.getAttribute('id')}" xmlns="urn:xmpp:message-correct:0"/>`+
`<origin-id id="${msg.querySelector('origin-id')?.getAttribute('id')}" xmlns="urn:xmpp:sid:0"/>`+
`</message>`);
expect(msg).toEqualStanza(stx`
<message from="${own_jid}" id="${msg.getAttribute('id')}" to="${muc_jid}" type="groupchat" xmlns="jabber:client">
<body>never mind</body>
<active xmlns="http://jabber.org/protocol/chatstates"/>
<replace id="${msg.querySelector('replace')?.getAttribute('id')}" xmlns="urn:xmpp:message-correct:0"/>
<origin-id id="${msg.querySelector('origin-id')?.getAttribute('id')}" xmlns="urn:xmpp:sid:0"/>
</message>`);
}));
});
Loading

0 comments on commit 4fc23a6

Please sign in to comment.