|
@@ -296,10 +296,11 @@ describe('A Groupchat Message XEP-0308 correction ', function () {
|
|
|
from="lounge@montague.lit/newguy"
|
|
|
to="_converse.connection.jid"
|
|
|
type="groupchat"
|
|
|
- id="${msg_id}">
|
|
|
+ id="${u.getUniqueId()}">
|
|
|
|
|
|
<body>But soft, what light through yonder chimney breaks?</body>
|
|
|
<occupant-id xmlns="urn:xmpp:occupant-id:0" id="2"></occupant-id>
|
|
|
+ <replace id="${msg_id}" xmlns="urn:xmpp:message-correct:0"></replace>
|
|
|
</message>`
|
|
|
);
|
|
|
|
|
@@ -309,7 +310,7 @@ describe('A Groupchat Message XEP-0308 correction ', function () {
|
|
|
expect(model.messages.at(0).get('edited')).toBeFalsy();
|
|
|
|
|
|
expect(model.messages.at(1).get('body')).toBe('But soft, what light through yonder chimney breaks?');
|
|
|
- expect(model.messages.at(1).get('edited')).toBeFalsy();
|
|
|
+ expect(model.messages.at(1).get('edited')).toBeTruthy();
|
|
|
|
|
|
await model.handleMessageStanza(
|
|
|
stx`
|
|
@@ -317,9 +318,10 @@ describe('A Groupchat Message XEP-0308 correction ', function () {
|
|
|
from="lounge@montague.lit/newguy"
|
|
|
to="_converse.connection.jid"
|
|
|
type="groupchat"
|
|
|
- id="${msg_id}">
|
|
|
+ id="${u.getUniqueId()}">
|
|
|
|
|
|
<body>But soft, what light through yonder hatch breaks?</body>
|
|
|
+ <replace id="${msg_id}" xmlns="urn:xmpp:message-correct:0"></replace>
|
|
|
</message>`
|
|
|
);
|
|
|
|
|
@@ -329,13 +331,91 @@ describe('A Groupchat Message XEP-0308 correction ', function () {
|
|
|
expect(model.messages.at(0).get('edited')).toBeFalsy();
|
|
|
|
|
|
expect(model.messages.at(1).get('body')).toBe('But soft, what light through yonder chimney breaks?');
|
|
|
- expect(model.messages.at(1).get('edited')).toBeFalsy();
|
|
|
+ expect(model.messages.at(1).get('edited')).toBeTruthy();
|
|
|
|
|
|
expect(model.messages.at(2).get('body')).toBe('But soft, what light through yonder hatch breaks?');
|
|
|
- expect(model.messages.at(2).get('edited')).toBeFalsy();
|
|
|
+ expect(model.messages.at(2).get('edited')).toBeTruthy();
|
|
|
|
|
|
const message_els = Array.from(view.querySelectorAll('.chat-msg'));
|
|
|
expect(message_els.reduce((acc, m) => acc && u.hasClass('chat-msg--followup', m), true)).toBe(false);
|
|
|
})
|
|
|
);
|
|
|
+
|
|
|
+ it(
|
|
|
+ "cannot be edited if it's from a different occupant id",
|
|
|
+ mock.initConverse([], {}, async function (_converse) {
|
|
|
+ const nick = 'romeo';
|
|
|
+ const muc_jid = 'lounge@montague.lit';
|
|
|
+ const features = [...mock.default_muc_features, Strophe.NS.OCCUPANTID];
|
|
|
+ const model = await mock.openAndEnterChatRoom(_converse, muc_jid, nick, features);
|
|
|
+
|
|
|
+ expect(model.get('occupant_id')).toBe(model.occupants.at(0).get('occupant_id'));
|
|
|
+
|
|
|
+ const msg_id = u.getUniqueId();
|
|
|
+ await model.handleMessageStanza(
|
|
|
+ stx`
|
|
|
+ <message
|
|
|
+ from="lounge@montague.lit/${nick}"
|
|
|
+ to="_converse.connection.jid"
|
|
|
+ type="groupchat"
|
|
|
+ id="${msg_id}">
|
|
|
+
|
|
|
+ <body>But soft, what light through yonder airlock breaks?</body>
|
|
|
+ <occupant-id xmlns="urn:xmpp:occupant-id:0" id="${model.get('occupant_id')}"></occupant-id>
|
|
|
+ </message>`
|
|
|
+ );
|
|
|
+
|
|
|
+ const view = _converse.chatboxviews.get(muc_jid);
|
|
|
+ await u.waitUntil(() => view.querySelectorAll('.chat-msg').length);
|
|
|
+ expect(model.messages.at(0).get('body')).toBe('But soft, what light through yonder airlock breaks?');
|
|
|
+
|
|
|
+ await model.handleMessageStanza(
|
|
|
+ stx`
|
|
|
+ <message
|
|
|
+ from="lounge@montague.lit/${nick}"
|
|
|
+ to="_converse.connection.jid"
|
|
|
+ type="groupchat"
|
|
|
+ id="${u.getUniqueId()}">
|
|
|
+
|
|
|
+ <body>But soft, what light through yonder chimney breaks?</body>
|
|
|
+ <occupant-id xmlns="urn:xmpp:occupant-id:0" id="${model.get('occupant_id')}"></occupant-id>
|
|
|
+ <replace id="${msg_id}" xmlns="urn:xmpp:message-correct:0"></replace>
|
|
|
+ </message>`
|
|
|
+ );
|
|
|
+
|
|
|
+ expect(model.messages.at(0).get('body')).toBe('But soft, what light through yonder chimney breaks?');
|
|
|
+ expect(model.messages.at(0).get('edited')).toBeTruthy();
|
|
|
+
|
|
|
+ await model.handleMessageStanza(
|
|
|
+ stx`
|
|
|
+ <message
|
|
|
+ from="lounge@montague.lit/${nick}"
|
|
|
+ to="_converse.connection.jid"
|
|
|
+ type="groupchat"
|
|
|
+ id="${u.getUniqueId()}">
|
|
|
+
|
|
|
+ <body>But soft, what light through yonder hatch breaks?</body>
|
|
|
+ <occupant-id xmlns="urn:xmpp:occupant-id:0" id="${u.getUniqueId()}"></occupant-id>
|
|
|
+ <replace id="${msg_id}" xmlns="urn:xmpp:message-correct:0"></replace>
|
|
|
+ </message>`
|
|
|
+ );
|
|
|
+
|
|
|
+ await u.waitUntil(() => view.querySelectorAll('.chat-msg').length === 2);
|
|
|
+ expect(model.messages.length).toBe(2);
|
|
|
+ expect(model.messages.at(0).get('body')).toBe('But soft, what light through yonder chimney breaks?');
|
|
|
+ expect(model.messages.at(0).get('edited')).toBeTruthy();
|
|
|
+ expect(model.messages.at(0).get('editable')).toBeTruthy();
|
|
|
+
|
|
|
+ expect(model.messages.at(1).get('body')).toBe('But soft, what light through yonder hatch breaks?');
|
|
|
+ expect(model.messages.at(1).get('edited')).toBeTruthy();
|
|
|
+ expect(model.messages.at(1).get('editable')).toBeFalsy();
|
|
|
+
|
|
|
+ const message_els = Array.from(view.querySelectorAll('.chat-msg'));
|
|
|
+ expect(message_els.reduce((acc, m) => acc && u.hasClass('chat-msg--followup', m), true)).toBe(false);
|
|
|
+
|
|
|
+ // We can edit our own message, but not the other
|
|
|
+ expect(message_els[0].querySelector('converse-dropdown .chat-msg__action-edit')).toBeDefined();
|
|
|
+ expect(message_els[1].querySelector('converse-dropdown .chat-msg__action-edit')).toBe(null);
|
|
|
+ })
|
|
|
+ );
|
|
|
});
|