2015-07-10 15:07:53 +02:00
|
|
|
(function (root, factory) {
|
2018-06-03 16:40:20 +02:00
|
|
|
define(["jasmine", "mock", "test-utils"], factory);
|
|
|
|
} (this, function (jasmine, mock, test_utils) {
|
2015-07-10 15:07:53 +02:00
|
|
|
"use strict";
|
2018-12-06 12:06:26 +01:00
|
|
|
const _ = converse.env._;
|
|
|
|
const Backbone = converse.env.Backbone;
|
|
|
|
const Strophe = converse.env.Strophe;
|
|
|
|
const $iq = converse.env.$iq;
|
|
|
|
const $msg = converse.env.$msg;
|
2019-05-06 11:16:56 +02:00
|
|
|
const dayjs = converse.env.dayjs;
|
2019-02-12 14:21:45 +01:00
|
|
|
const u = converse.env.utils;
|
2015-07-10 17:26:54 +02:00
|
|
|
// See: https://xmpp.org/rfcs/rfc3921.html
|
2015-07-10 15:07:53 +02:00
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
describe("Message Archive Management", function () {
|
2015-07-10 15:07:53 +02:00
|
|
|
// Implement the protocol defined in https://xmpp.org/extensions/xep-0313.html#config
|
|
|
|
|
2019-03-07 15:44:58 +01:00
|
|
|
describe("An archived message", function () {
|
2018-01-09 23:05:23 +01:00
|
|
|
|
2019-03-07 15:44:58 +01:00
|
|
|
describe("when recieved", function () {
|
|
|
|
|
|
|
|
it("updates the is_archived value of an already cached version",
|
|
|
|
mock.initConverse(
|
|
|
|
null, ['discoInitialized'], {},
|
|
|
|
async function (done, _converse) {
|
|
|
|
|
|
|
|
await test_utils.openAndEnterChatRoom(_converse, 'trek-radio', 'conference.lightwitch.org', 'dummy');
|
|
|
|
|
|
|
|
const view = _converse.chatboxviews.get('trek-radio@conference.lightwitch.org');
|
|
|
|
let stanza = u.toStanza(
|
|
|
|
`<message xmlns="jabber:client" to="dummy@localhost/resource" type="groupchat" from="trek-radio@conference.lightwitch.org/some1">
|
|
|
|
<body>Hello</body>
|
|
|
|
<stanza-id xmlns="urn:xmpp:sid:0" id="45fbbf2a-1059-479d-9283-c8effaf05621" by="trek-radio@conference.lightwitch.org"/>
|
|
|
|
</message>`);
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
await test_utils.waitUntil(() => view.content.querySelectorAll('.chat-msg').length);
|
|
|
|
expect(view.model.messages.length).toBe(1);
|
|
|
|
expect(view.model.messages.at(0).get('is_archived')).toBe(false);
|
|
|
|
expect(view.model.messages.at(0).get('stanza_id trek-radio@conference.lightwitch.org')).toBe('45fbbf2a-1059-479d-9283-c8effaf05621');
|
|
|
|
|
|
|
|
stanza = u.toStanza(
|
|
|
|
`<message xmlns="jabber:client"
|
|
|
|
to="dummy@localhost/resource"
|
|
|
|
from="trek-radio@conference.lightwitch.org">
|
|
|
|
<result xmlns="urn:xmpp:mam:2" queryid="82d9db27-6cf8-4787-8c2c-5a560263d823" id="45fbbf2a-1059-479d-9283-c8effaf05621">
|
|
|
|
<forwarded xmlns="urn:xmpp:forward:0">
|
|
|
|
<delay xmlns="urn:xmpp:delay" stamp="2018-01-09T06:17:23Z"/>
|
|
|
|
<message from="trek-radio@conference.lightwitch.org/some1" type="groupchat">
|
|
|
|
<body>Hello</body>
|
|
|
|
</message>
|
|
|
|
</forwarded>
|
|
|
|
</result>
|
|
|
|
</message>`);
|
|
|
|
spyOn(view.model, 'findDuplicateFromArchiveID').and.callThrough();
|
|
|
|
spyOn(view.model, 'updateMessage').and.callThrough();
|
|
|
|
view.model.onMessage(stanza);
|
|
|
|
await test_utils.waitUntil(() => view.model.findDuplicateFromArchiveID.calls.count());
|
|
|
|
expect(view.model.findDuplicateFromArchiveID.calls.count()).toBe(1);
|
|
|
|
const result = await view.model.findDuplicateFromArchiveID.calls.all()[0].returnValue
|
|
|
|
expect(result instanceof _converse.Message).toBe(true);
|
|
|
|
expect(view.content.querySelectorAll('.chat-msg').length).toBe(1);
|
|
|
|
|
|
|
|
await test_utils.waitUntil(() => view.model.updateMessage.calls.count());
|
|
|
|
expect(view.model.messages.length).toBe(1);
|
|
|
|
expect(view.model.messages.at(0).get('is_archived')).toBe(true);
|
|
|
|
expect(view.model.messages.at(0).get('stanza_id trek-radio@conference.lightwitch.org')).toBe('45fbbf2a-1059-479d-9283-c8effaf05621');
|
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
|
|
|
it("isn't shown as duplicate by comparing its stanza id or archive id",
|
|
|
|
mock.initConverse(
|
|
|
|
null, ['discoInitialized'], {},
|
|
|
|
async function (done, _converse) {
|
|
|
|
|
|
|
|
await test_utils.openAndEnterChatRoom(_converse, 'trek-radio', 'conference.lightwitch.org', 'jcbrand');
|
|
|
|
const view = _converse.chatboxviews.get('trek-radio@conference.lightwitch.org');
|
|
|
|
let stanza = u.toStanza(
|
|
|
|
`<message xmlns="jabber:client" to="jcbrand@lightwitch.org/converse.js-73057452" type="groupchat" from="trek-radio@conference.lightwitch.org/comndrdukath#0805 (STO)">
|
|
|
|
<body>negan</body>
|
|
|
|
<stanza-id xmlns="urn:xmpp:sid:0" id="45fbbf2a-1059-479d-9283-c8effaf05621" by="trek-radio@conference.lightwitch.org"/>
|
|
|
|
</message>`);
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
await test_utils.waitUntil(() => view.content.querySelectorAll('.chat-msg').length);
|
|
|
|
// Not sure whether such a race-condition might pose a problem
|
|
|
|
// in "real-world" situations.
|
|
|
|
stanza = u.toStanza(
|
|
|
|
`<message xmlns="jabber:client"
|
|
|
|
to="jcbrand@lightwitch.org/converse.js-73057452"
|
|
|
|
from="trek-radio@conference.lightwitch.org">
|
|
|
|
<result xmlns="urn:xmpp:mam:2" queryid="82d9db27-6cf8-4787-8c2c-5a560263d823" id="45fbbf2a-1059-479d-9283-c8effaf05621">
|
|
|
|
<forwarded xmlns="urn:xmpp:forward:0">
|
|
|
|
<delay xmlns="urn:xmpp:delay" stamp="2018-01-09T06:17:23Z"/>
|
|
|
|
<message from="trek-radio@conference.lightwitch.org/comndrdukath#0805 (STO)" type="groupchat">
|
|
|
|
<body>negan</body>
|
|
|
|
</message>
|
|
|
|
</forwarded>
|
|
|
|
</result>
|
|
|
|
</message>`);
|
|
|
|
spyOn(view.model, 'findDuplicateFromArchiveID').and.callThrough();
|
|
|
|
view.model.onMessage(stanza);
|
|
|
|
await test_utils.waitUntil(() => view.model.findDuplicateFromArchiveID.calls.count());
|
|
|
|
expect(view.model.findDuplicateFromArchiveID.calls.count()).toBe(1);
|
|
|
|
const result = await view.model.findDuplicateFromArchiveID.calls.all()[0].returnValue
|
|
|
|
expect(result instanceof _converse.Message).toBe(true);
|
|
|
|
expect(view.content.querySelectorAll('.chat-msg').length).toBe(1);
|
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
|
|
|
it("isn't shown as duplicate by comparing only the archive id",
|
|
|
|
mock.initConverse(
|
|
|
|
null, ['discoInitialized'], {},
|
|
|
|
async function (done, _converse) {
|
|
|
|
|
|
|
|
await test_utils.openAndEnterChatRoom(_converse, 'discuss', 'conference.conversejs.org', 'dummy');
|
|
|
|
const view = _converse.chatboxviews.get('discuss@conference.conversejs.org');
|
|
|
|
let stanza = u.toStanza(
|
|
|
|
`<message xmlns="jabber:client" to="dummy@localhost/resource" from="discuss@conference.conversejs.org">
|
|
|
|
<result xmlns="urn:xmpp:mam:2" queryid="06fea9ca-97c9-48c4-8583-009ff54ea2e8" id="7a9fde91-4387-4bf8-b5d3-978dab8f6bf3">
|
|
|
|
<forwarded xmlns="urn:xmpp:forward:0">
|
|
|
|
<delay xmlns="urn:xmpp:delay" stamp="2018-12-05T04:53:12Z"/>
|
|
|
|
<message xmlns="jabber:client" to="discuss@conference.conversejs.org" type="groupchat" xml:lang="en" from="discuss@conference.conversejs.org/prezel">
|
|
|
|
<body>looks like omemo fails completely with "bundle is undefined" when there is a device in the devicelist that has no keys published</body>
|
|
|
|
<x xmlns="http://jabber.org/protocol/muc#user">
|
|
|
|
<item affiliation="none" jid="prezel@blubber.im" role="participant"/>
|
|
|
|
</x>
|
|
|
|
</message>
|
|
|
|
</forwarded>
|
|
|
|
</result>
|
|
|
|
</message>`);
|
|
|
|
view.model.onMessage(stanza);
|
|
|
|
await test_utils.waitUntil(() => view.content.querySelectorAll('.chat-msg').length);
|
|
|
|
expect(view.content.querySelectorAll('.chat-msg').length).toBe(1);
|
|
|
|
|
|
|
|
stanza = u.toStanza(
|
|
|
|
`<message xmlns="jabber:client" to="dummy@localhost/resource" from="discuss@conference.conversejs.org">
|
|
|
|
<result xmlns="urn:xmpp:mam:2" queryid="06fea9ca-97c9-48c4-8583-009ff54ea2e8" id="7a9fde91-4387-4bf8-b5d3-978dab8f6bf3">
|
|
|
|
<forwarded xmlns="urn:xmpp:forward:0">
|
|
|
|
<delay xmlns="urn:xmpp:delay" stamp="2018-12-05T04:53:12Z"/>
|
|
|
|
<message xmlns="jabber:client" to="discuss@conference.conversejs.org" type="groupchat" xml:lang="en" from="discuss@conference.conversejs.org/prezel">
|
|
|
|
<body>looks like omemo fails completely with "bundle is undefined" when there is a device in the devicelist that has no keys published</body>
|
|
|
|
<x xmlns="http://jabber.org/protocol/muc#user">
|
|
|
|
<item affiliation="none" jid="prezel@blubber.im" role="participant"/>
|
|
|
|
</x>
|
|
|
|
</message>
|
|
|
|
</forwarded>
|
|
|
|
</result>
|
|
|
|
</message>`);
|
|
|
|
|
|
|
|
spyOn(view.model, 'findDuplicateFromArchiveID').and.callThrough();
|
|
|
|
view.model.onMessage(stanza);
|
|
|
|
await test_utils.waitUntil(() => view.model.findDuplicateFromArchiveID.calls.count());
|
|
|
|
expect(view.model.findDuplicateFromArchiveID.calls.count()).toBe(1);
|
|
|
|
const result = await view.model.findDuplicateFromArchiveID.calls.all()[0].returnValue
|
|
|
|
expect(result instanceof _converse.Message).toBe(true);
|
|
|
|
expect(view.content.querySelectorAll('.chat-msg').length).toBe(1);
|
|
|
|
done();
|
|
|
|
}))
|
|
|
|
});
|
2018-01-09 23:05:23 +01:00
|
|
|
});
|
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
describe("The archive.query API", function () {
|
2015-07-10 17:26:54 +02:00
|
|
|
|
2017-07-21 12:41:16 +02:00
|
|
|
it("can be used to query for all archived messages",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2017-07-21 12:41:16 +02:00
|
|
|
null, ['discoInitialized'], {},
|
2019-05-03 19:47:49 +02:00
|
|
|
async function (done, _converse) {
|
2017-07-21 12:41:16 +02:00
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
const sendIQ = _converse.connection.sendIQ;
|
2019-05-03 19:47:49 +02:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, _converse.bare_jid, null, [Strophe.NS.MAM]);
|
|
|
|
let sent_stanza, IQ_id;
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
2015-07-10 17:26:54 +02:00
|
|
|
sent_stanza = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.api.archive.query();
|
2019-05-03 19:47:49 +02:00
|
|
|
await test_utils.waitUntil(() => sent_stanza);
|
2019-02-12 14:21:45 +01:00
|
|
|
const queryid = sent_stanza.nodeTree.querySelector('query').getAttribute('queryid');
|
2015-07-10 17:26:54 +02:00
|
|
|
expect(sent_stanza.toString()).toBe(
|
2018-10-02 17:01:39 +02:00
|
|
|
`<iq id="${IQ_id}" type="set" xmlns="jabber:client"><query queryid="${queryid}" xmlns="urn:xmpp:mam:2"/></iq>`);
|
2017-07-21 12:41:16 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2015-07-10 17:26:54 +02:00
|
|
|
|
2018-03-29 16:12:19 +02:00
|
|
|
it("can be used to query for all messages to/from a particular JID",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2018-12-06 12:06:26 +01:00
|
|
|
null, [], {},
|
|
|
|
async function (done, _converse) {
|
|
|
|
|
2019-05-03 19:47:49 +02:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, _converse.bare_jid, null, [Strophe.NS.MAM]);
|
2018-12-06 12:06:26 +01:00
|
|
|
let sent_stanza, IQ_id;
|
|
|
|
const sendIQ = _converse.connection.sendIQ;
|
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
|
|
|
sent_stanza = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
2015-07-10 17:26:54 +02:00
|
|
|
});
|
2018-12-06 12:06:26 +01:00
|
|
|
_converse.api.archive.query({'with':'juliet@capulet.lit'});
|
2019-05-03 19:47:49 +02:00
|
|
|
await test_utils.waitUntil(() => sent_stanza);
|
2018-12-06 12:06:26 +01:00
|
|
|
const queryid = sent_stanza.nodeTree.querySelector('query').getAttribute('queryid');
|
|
|
|
expect(sent_stanza.toString()).toBe(
|
|
|
|
`<iq id="${IQ_id}" type="set" xmlns="jabber:client">`+
|
|
|
|
`<query queryid="${queryid}" xmlns="urn:xmpp:mam:2">`+
|
|
|
|
`<x type="submit" xmlns="jabber:x:data">`+
|
|
|
|
`<field type="hidden" var="FORM_TYPE">`+
|
|
|
|
`<value>urn:xmpp:mam:2</value>`+
|
|
|
|
`</field>`+
|
|
|
|
`<field var="with">`+
|
|
|
|
`<value>juliet@capulet.lit</value>`+
|
|
|
|
`</field>`+
|
|
|
|
`</x>`+
|
|
|
|
`</query>`+
|
|
|
|
`</iq>`);
|
|
|
|
done();
|
2018-03-29 16:12:19 +02:00
|
|
|
}));
|
2015-07-10 17:26:54 +02:00
|
|
|
|
2018-03-29 16:12:19 +02:00
|
|
|
it("can be used to query for archived messages from a chat room",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2018-12-06 12:06:26 +01:00
|
|
|
null, [], {},
|
|
|
|
async function (done, _converse) {
|
|
|
|
|
2019-05-03 19:47:49 +02:00
|
|
|
await test_utils.openAndEnterChatRoom(_converse, 'coven', 'chat.shakespeare.lit', 'nicky', [Strophe.NS.MAM]);
|
2018-12-06 12:06:26 +01:00
|
|
|
let sent_stanza, IQ_id;
|
|
|
|
const sendIQ = _converse.connection.sendIQ;
|
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
|
|
|
sent_stanza = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
2015-07-10 17:26:54 +02:00
|
|
|
});
|
2019-05-03 19:47:49 +02:00
|
|
|
_converse.api.archive.query({'with': 'coven@chat.shakespeare.lit', 'groupchat': true});
|
|
|
|
await test_utils.waitUntil(() => sent_stanza);
|
2018-12-06 12:06:26 +01:00
|
|
|
const queryid = sent_stanza.nodeTree.querySelector('query').getAttribute('queryid');
|
|
|
|
expect(sent_stanza.toString()).toBe(
|
|
|
|
`<iq id="${IQ_id}" to="coven@chat.shakespeare.lit" type="set" xmlns="jabber:client">`+
|
|
|
|
`<query queryid="${queryid}" xmlns="urn:xmpp:mam:2">`+
|
|
|
|
`<x type="submit" xmlns="jabber:x:data">`+
|
|
|
|
`<field type="hidden" var="FORM_TYPE">`+
|
|
|
|
`<value>urn:xmpp:mam:2</value>`+
|
|
|
|
`</field>`+
|
|
|
|
`</x>`+
|
|
|
|
`</query>`+
|
|
|
|
`</iq>`);
|
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2015-07-10 17:26:54 +02:00
|
|
|
|
2018-03-29 16:12:19 +02:00
|
|
|
it("checks whether returned MAM messages from a MUC room are from the right JID",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2018-12-06 12:06:26 +01:00
|
|
|
null, [], {},
|
|
|
|
async function (done, _converse) {
|
2018-03-29 16:12:19 +02:00
|
|
|
|
2019-05-03 19:47:49 +02:00
|
|
|
await test_utils.openAndEnterChatRoom(_converse, 'coven', 'chat.shakespeare.lit', 'nicky', [Strophe.NS.MAM]);
|
2019-02-12 14:21:45 +01:00
|
|
|
let sent_stanza, IQ_id;
|
2018-10-25 07:32:44 +02:00
|
|
|
const sendIQ = _converse.connection.sendIQ;
|
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
|
|
|
sent_stanza = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
2019-05-03 19:47:49 +02:00
|
|
|
const promise = _converse.api.archive.query({'with': 'coven@chat.shakespear.lit', 'groupchat': true, 'max':'10'});
|
|
|
|
await test_utils.waitUntil(() => sent_stanza);
|
2019-02-12 14:21:45 +01:00
|
|
|
const queryid = sent_stanza.nodeTree.querySelector('query').getAttribute('queryid');
|
2015-07-10 17:26:54 +02:00
|
|
|
|
2018-10-25 07:32:44 +02:00
|
|
|
/* <message id='iasd207' from='coven@chat.shakespeare.lit' to='hag66@shakespeare.lit/pda'>
|
|
|
|
* <result xmlns='urn:xmpp:mam:2' queryid='g27' id='34482-21985-73620'>
|
|
|
|
* <forwarded xmlns='urn:xmpp:forward:0'>
|
|
|
|
* <delay xmlns='urn:xmpp:delay' stamp='2002-10-13T23:58:37Z'/>
|
|
|
|
* <message xmlns="jabber:client"
|
|
|
|
* from='coven@chat.shakespeare.lit/firstwitch'
|
|
|
|
* id='162BEBB1-F6DB-4D9A-9BD8-CFDCC801A0B2'
|
|
|
|
* type='groupchat'>
|
|
|
|
* <body>Thrice the brinded cat hath mew'd.</body>
|
|
|
|
* <x xmlns='http://jabber.org/protocol/muc#user'>
|
|
|
|
* <item affiliation='none'
|
|
|
|
* jid='witch1@shakespeare.lit'
|
|
|
|
* role='participant' />
|
|
|
|
* </x>
|
|
|
|
* </message>
|
|
|
|
* </forwarded>
|
|
|
|
* </result>
|
|
|
|
* </message>
|
|
|
|
*/
|
2019-02-12 14:21:45 +01:00
|
|
|
const msg1 = $msg({'id':'iasd207', 'from': 'other@chat.shakespear.lit', 'to': 'dummy@localhost'})
|
2018-10-25 07:32:44 +02:00
|
|
|
.c('result', {'xmlns': 'urn:xmpp:mam:2', 'queryid':queryid, 'id':'34482-21985-73620'})
|
|
|
|
.c('forwarded', {'xmlns':'urn:xmpp:forward:0'})
|
|
|
|
.c('delay', {'xmlns':'urn:xmpp:delay', 'stamp':'2010-07-10T23:08:25Z'}).up()
|
|
|
|
.c('message', {
|
|
|
|
'xmlns':'jabber:client',
|
|
|
|
'to':'dummy@localhost',
|
|
|
|
'id':'162BEBB1-F6DB-4D9A-9BD8-CFDCC801A0B2',
|
|
|
|
'from':'coven@chat.shakespeare.lit/firstwitch',
|
|
|
|
'type':'groupchat' })
|
|
|
|
.c('body').t("Thrice the brinded cat hath mew'd.");
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(msg1));
|
|
|
|
|
|
|
|
/* Send an <iq> stanza to indicate the end of the result set.
|
|
|
|
*
|
|
|
|
* <iq type='result' id='juliet1'>
|
|
|
|
* <fin xmlns='urn:xmpp:mam:2'>
|
|
|
|
* <set xmlns='http://jabber.org/protocol/rsm'>
|
|
|
|
* <first index='0'>28482-98726-73623</first>
|
|
|
|
* <last>09af3-cc343-b409f</last>
|
|
|
|
* <count>20</count>
|
|
|
|
* </set>
|
|
|
|
* </iq>
|
|
|
|
*/
|
|
|
|
const stanza = $iq({'type': 'result', 'id': IQ_id})
|
|
|
|
.c('fin', {'xmlns': 'urn:xmpp:mam:2'})
|
|
|
|
.c('set', {'xmlns': 'http://jabber.org/protocol/rsm'})
|
|
|
|
.c('first', {'index': '0'}).t('23452-4534-1').up()
|
|
|
|
.c('last').t('09af3-cc343-b409f').up()
|
|
|
|
.c('count').t('16');
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
|
2019-05-03 19:47:49 +02:00
|
|
|
const result = await promise;
|
|
|
|
expect(result.messages.length).toBe(0);
|
2018-10-25 07:32:44 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2015-07-10 17:26:54 +02:00
|
|
|
|
2018-03-29 16:12:19 +02:00
|
|
|
it("can be used to query for all messages in a certain timespan",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2018-12-06 12:06:26 +01:00
|
|
|
null, [], {},
|
|
|
|
async function (done, _converse) {
|
2018-03-29 16:12:19 +02:00
|
|
|
|
2019-05-03 19:47:49 +02:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, _converse.bare_jid, null, [Strophe.NS.MAM]);
|
2018-12-06 12:06:26 +01:00
|
|
|
let sent_stanza, IQ_id;
|
|
|
|
const sendIQ = _converse.connection.sendIQ;
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
2015-07-10 17:26:54 +02:00
|
|
|
sent_stanza = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
2018-12-06 12:06:26 +01:00
|
|
|
const start = '2010-06-07T00:00:00Z';
|
|
|
|
const end = '2010-07-07T13:23:54Z';
|
|
|
|
_converse.api.archive.query({
|
|
|
|
'start': start,
|
|
|
|
'end': end
|
2018-03-29 16:12:19 +02:00
|
|
|
});
|
2019-05-03 19:47:49 +02:00
|
|
|
await test_utils.waitUntil(() => sent_stanza);
|
2018-12-06 12:06:26 +01:00
|
|
|
const queryid = sent_stanza.nodeTree.querySelector('query').getAttribute('queryid');
|
|
|
|
expect(sent_stanza.toString()).toBe(
|
|
|
|
`<iq id="${IQ_id}" type="set" xmlns="jabber:client">`+
|
|
|
|
`<query queryid="${queryid}" xmlns="urn:xmpp:mam:2">`+
|
|
|
|
`<x type="submit" xmlns="jabber:x:data">`+
|
|
|
|
`<field type="hidden" var="FORM_TYPE">`+
|
|
|
|
`<value>urn:xmpp:mam:2</value>`+
|
|
|
|
`</field>`+
|
|
|
|
`<field var="start">`+
|
2019-05-06 11:16:56 +02:00
|
|
|
`<value>${dayjs(start).toISOString()}</value>`+
|
2018-12-06 12:06:26 +01:00
|
|
|
`</field>`+
|
|
|
|
`<field var="end">`+
|
2019-05-06 11:16:56 +02:00
|
|
|
`<value>${dayjs(end).toISOString()}</value>`+
|
2018-12-06 12:06:26 +01:00
|
|
|
`</field>`+
|
|
|
|
`</x>`+
|
|
|
|
`</query>`+
|
|
|
|
`</iq>`
|
|
|
|
);
|
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2015-07-10 17:26:54 +02:00
|
|
|
|
2018-03-29 16:12:19 +02:00
|
|
|
it("throws a TypeError if an invalid date is provided",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2018-10-25 07:32:44 +02:00
|
|
|
null, [], {},
|
|
|
|
async function (done, _converse) {
|
2018-03-29 16:12:19 +02:00
|
|
|
|
2019-05-03 19:47:49 +02:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, _converse.bare_jid, null, [Strophe.NS.MAM]);
|
|
|
|
try {
|
|
|
|
await _converse.api.archive.query({'start': 'not a real date'});
|
|
|
|
} catch (e) {
|
|
|
|
expect(() => {throw e}).toThrow(new TypeError('archive.query: invalid date provided for: start'));
|
2018-10-25 07:32:44 +02:00
|
|
|
}
|
|
|
|
done();
|
2018-03-29 16:12:19 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
it("can be used to query for all messages after a certain time",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2018-12-06 12:06:26 +01:00
|
|
|
null, [], {},
|
|
|
|
async function (done, _converse) {
|
|
|
|
|
2019-05-03 19:47:49 +02:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, _converse.bare_jid, null, [Strophe.NS.MAM]);
|
2018-12-06 12:06:26 +01:00
|
|
|
let sent_stanza, IQ_id;
|
|
|
|
const sendIQ = _converse.connection.sendIQ;
|
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
|
|
|
sent_stanza = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
|
|
|
if (!_converse.disco_entities.get(_converse.domain).features.findWhere({'var': Strophe.NS.MAM})) {
|
|
|
|
_converse.disco_entities.get(_converse.domain).features.create({'var': Strophe.NS.MAM});
|
|
|
|
}
|
|
|
|
const start = '2010-06-07T00:00:00Z';
|
|
|
|
_converse.api.archive.query({'start': start});
|
2019-05-03 19:47:49 +02:00
|
|
|
await test_utils.waitUntil(() => sent_stanza);
|
2018-12-06 12:06:26 +01:00
|
|
|
const queryid = sent_stanza.nodeTree.querySelector('query').getAttribute('queryid');
|
|
|
|
expect(sent_stanza.toString()).toBe(
|
|
|
|
`<iq id="${IQ_id}" type="set" xmlns="jabber:client">`+
|
|
|
|
`<query queryid="${queryid}" xmlns="urn:xmpp:mam:2">`+
|
|
|
|
`<x type="submit" xmlns="jabber:x:data">`+
|
|
|
|
`<field type="hidden" var="FORM_TYPE">`+
|
|
|
|
`<value>urn:xmpp:mam:2</value>`+
|
|
|
|
`</field>`+
|
|
|
|
`<field var="start">`+
|
2019-05-06 11:16:56 +02:00
|
|
|
`<value>${dayjs(start).toISOString()}</value>`+
|
2018-12-06 12:06:26 +01:00
|
|
|
`</field>`+
|
|
|
|
`</x>`+
|
|
|
|
`</query>`+
|
|
|
|
`</iq>`
|
|
|
|
);
|
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
|
|
|
it("can be used to query for a limited set of results",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2018-12-06 12:06:26 +01:00
|
|
|
null, [], {},
|
|
|
|
async function (done, _converse) {
|
|
|
|
|
2019-05-03 19:47:49 +02:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, _converse.bare_jid, null, [Strophe.NS.MAM]);
|
2018-12-06 12:06:26 +01:00
|
|
|
let sent_stanza, IQ_id;
|
|
|
|
const sendIQ = _converse.connection.sendIQ;
|
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
|
|
|
sent_stanza = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
|
|
|
const start = '2010-06-07T00:00:00Z';
|
|
|
|
_converse.api.archive.query({'start': start, 'max':10});
|
2019-05-03 19:47:49 +02:00
|
|
|
await test_utils.waitUntil(() => sent_stanza);
|
2018-12-06 12:06:26 +01:00
|
|
|
const queryid = sent_stanza.nodeTree.querySelector('query').getAttribute('queryid');
|
|
|
|
expect(sent_stanza.toString()).toBe(
|
|
|
|
`<iq id="${IQ_id}" type="set" xmlns="jabber:client">`+
|
|
|
|
`<query queryid="${queryid}" xmlns="urn:xmpp:mam:2">`+
|
|
|
|
`<x type="submit" xmlns="jabber:x:data">`+
|
2018-10-02 17:01:39 +02:00
|
|
|
`<field type="hidden" var="FORM_TYPE">`+
|
|
|
|
`<value>urn:xmpp:mam:2</value>`+
|
|
|
|
`</field>`+
|
|
|
|
`<field var="start">`+
|
2019-05-06 11:16:56 +02:00
|
|
|
`<value>${dayjs(start).toISOString()}</value>`+
|
2018-10-02 17:01:39 +02:00
|
|
|
`</field>`+
|
2018-12-06 12:06:26 +01:00
|
|
|
`</x>`+
|
|
|
|
`<set xmlns="http://jabber.org/protocol/rsm">`+
|
|
|
|
`<max>10</max>`+
|
|
|
|
`</set>`+
|
|
|
|
`</query>`+
|
|
|
|
`</iq>`
|
|
|
|
);
|
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2015-07-12 21:27:22 +02:00
|
|
|
|
2018-03-29 16:12:19 +02:00
|
|
|
it("can be used to page through results",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2018-12-06 12:06:26 +01:00
|
|
|
null, [], {},
|
|
|
|
async function (done, _converse) {
|
|
|
|
|
2019-05-03 19:47:49 +02:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, _converse.bare_jid, null, [Strophe.NS.MAM]);
|
2018-12-06 12:06:26 +01:00
|
|
|
let sent_stanza, IQ_id;
|
|
|
|
const sendIQ = _converse.connection.sendIQ;
|
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
|
|
|
sent_stanza = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
2015-07-12 22:00:32 +02:00
|
|
|
});
|
2018-12-06 12:06:26 +01:00
|
|
|
const start = '2010-06-07T00:00:00Z';
|
|
|
|
_converse.api.archive.query({
|
|
|
|
'start': start,
|
|
|
|
'after': '09af3-cc343-b409f',
|
|
|
|
'max':10
|
|
|
|
});
|
2019-05-03 19:47:49 +02:00
|
|
|
await test_utils.waitUntil(() => sent_stanza);
|
2018-12-06 12:06:26 +01:00
|
|
|
const queryid = sent_stanza.nodeTree.querySelector('query').getAttribute('queryid');
|
|
|
|
expect(sent_stanza.toString()).toBe(
|
|
|
|
`<iq id="${IQ_id}" type="set" xmlns="jabber:client">`+
|
|
|
|
`<query queryid="${queryid}" xmlns="urn:xmpp:mam:2">`+
|
|
|
|
`<x type="submit" xmlns="jabber:x:data">`+
|
|
|
|
`<field type="hidden" var="FORM_TYPE">`+
|
|
|
|
`<value>urn:xmpp:mam:2</value>`+
|
|
|
|
`</field>`+
|
|
|
|
`<field var="start">`+
|
2019-05-06 11:16:56 +02:00
|
|
|
`<value>${dayjs(start).toISOString()}</value>`+
|
2018-12-06 12:06:26 +01:00
|
|
|
`</field>`+
|
|
|
|
`</x>`+
|
|
|
|
`<set xmlns="http://jabber.org/protocol/rsm">`+
|
|
|
|
`<max>10</max>`+
|
|
|
|
`<after>09af3-cc343-b409f</after>`+
|
|
|
|
`</set>`+
|
|
|
|
`</query>`+
|
|
|
|
`</iq>`);
|
|
|
|
done();
|
2018-03-29 16:12:19 +02:00
|
|
|
}));
|
2015-07-12 22:00:32 +02:00
|
|
|
|
2018-03-29 16:12:19 +02:00
|
|
|
it("accepts \"before\" with an empty string as value to reverse the order",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2018-12-06 12:06:26 +01:00
|
|
|
null, [], {},
|
|
|
|
async function (done, _converse) {
|
|
|
|
|
2019-05-03 19:47:49 +02:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, _converse.bare_jid, null, [Strophe.NS.MAM]);
|
2018-12-06 12:06:26 +01:00
|
|
|
let sent_stanza, IQ_id;
|
|
|
|
const sendIQ = _converse.connection.sendIQ;
|
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
|
|
|
sent_stanza = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
2018-03-29 16:12:19 +02:00
|
|
|
});
|
2018-12-06 12:06:26 +01:00
|
|
|
_converse.api.archive.query({'before': '', 'max':10});
|
2019-05-03 19:47:49 +02:00
|
|
|
await test_utils.waitUntil(() => sent_stanza);
|
2018-12-06 12:06:26 +01:00
|
|
|
const queryid = sent_stanza.nodeTree.querySelector('query').getAttribute('queryid');
|
|
|
|
expect(sent_stanza.toString()).toBe(
|
|
|
|
`<iq id="${IQ_id}" type="set" xmlns="jabber:client">`+
|
|
|
|
`<query queryid="${queryid}" xmlns="urn:xmpp:mam:2">`+
|
|
|
|
`<x type="submit" xmlns="jabber:x:data">`+
|
|
|
|
`<field type="hidden" var="FORM_TYPE">`+
|
|
|
|
`<value>urn:xmpp:mam:2</value>`+
|
|
|
|
`</field>`+
|
|
|
|
`</x>`+
|
|
|
|
`<set xmlns="http://jabber.org/protocol/rsm">`+
|
|
|
|
`<max>10</max>`+
|
|
|
|
`<before></before>`+
|
|
|
|
`</set>`+
|
|
|
|
`</query>`+
|
|
|
|
`</iq>`);
|
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2015-07-12 22:00:32 +02:00
|
|
|
|
2018-03-29 16:12:19 +02:00
|
|
|
it("accepts a Strophe.RSM object for the query options",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2018-12-06 12:06:26 +01:00
|
|
|
null, [], {},
|
|
|
|
async function (done, _converse) {
|
|
|
|
|
2019-05-03 19:47:49 +02:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, _converse.bare_jid, null, [Strophe.NS.MAM]);
|
2018-12-06 12:06:26 +01:00
|
|
|
let sent_stanza, IQ_id;
|
|
|
|
const sendIQ = _converse.connection.sendIQ;
|
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
|
|
|
sent_stanza = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
2015-07-12 23:58:07 +02:00
|
|
|
});
|
2018-12-06 12:06:26 +01:00
|
|
|
// Normally the user wouldn't manually make a Strophe.RSM object
|
|
|
|
// and pass it in. However, in the callback method an RSM object is
|
|
|
|
// returned which can be reused for easy paging. This test is
|
|
|
|
// more for that usecase.
|
|
|
|
const rsm = new Strophe.RSM({'max': '10'});
|
|
|
|
rsm['with'] = 'romeo@montague.lit'; // eslint-disable-line dot-notation
|
|
|
|
rsm.start = '2010-06-07T00:00:00Z';
|
|
|
|
_converse.api.archive.query(rsm);
|
2019-05-03 19:47:49 +02:00
|
|
|
await test_utils.waitUntil(() => sent_stanza);
|
2018-12-06 12:06:26 +01:00
|
|
|
const queryid = sent_stanza.nodeTree.querySelector('query').getAttribute('queryid');
|
|
|
|
expect(sent_stanza.toString()).toBe(
|
|
|
|
`<iq id="${IQ_id}" type="set" xmlns="jabber:client">`+
|
|
|
|
`<query queryid="${queryid}" xmlns="urn:xmpp:mam:2">`+
|
|
|
|
`<x type="submit" xmlns="jabber:x:data">`+
|
|
|
|
`<field type="hidden" var="FORM_TYPE">`+
|
|
|
|
`<value>urn:xmpp:mam:2</value>`+
|
|
|
|
`</field>`+
|
|
|
|
`<field var="with">`+
|
|
|
|
`<value>romeo@montague.lit</value>`+
|
|
|
|
`</field>`+
|
|
|
|
`<field var="start">`+
|
2019-05-06 11:16:56 +02:00
|
|
|
`<value>${dayjs(rsm.start).toISOString()}</value>`+
|
2018-12-06 12:06:26 +01:00
|
|
|
`</field>`+
|
|
|
|
`</x>`+
|
|
|
|
`<set xmlns="http://jabber.org/protocol/rsm">`+
|
|
|
|
`<max>10</max>`+
|
|
|
|
`</set>`+
|
|
|
|
`</query>`+
|
|
|
|
`</iq>`);
|
|
|
|
done();
|
2018-03-29 16:12:19 +02:00
|
|
|
}));
|
2015-07-12 23:58:07 +02:00
|
|
|
|
2019-05-03 19:47:49 +02:00
|
|
|
it("returns an object which includes the messages and a Strophe.RSM object",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2018-10-25 07:32:44 +02:00
|
|
|
null, [], {},
|
|
|
|
async function (done, _converse) {
|
2015-07-12 23:58:07 +02:00
|
|
|
|
2019-05-03 19:47:49 +02:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, _converse.bare_jid, null, [Strophe.NS.MAM]);
|
2018-10-25 07:32:44 +02:00
|
|
|
let sent_stanza, IQ_id;
|
|
|
|
const sendIQ = _converse.connection.sendIQ;
|
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
|
|
|
sent_stanza = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
2018-03-29 16:12:19 +02:00
|
|
|
});
|
2019-05-03 19:47:49 +02:00
|
|
|
const promise = _converse.api.archive.query({'with': 'romeo@capulet.lit', 'max':'10'});
|
|
|
|
await test_utils.waitUntil(() => sent_stanza);
|
2018-10-25 07:32:44 +02:00
|
|
|
const queryid = sent_stanza.nodeTree.querySelector('query').getAttribute('queryid');
|
|
|
|
|
|
|
|
/* <message id='aeb213' to='juliet@capulet.lit/chamber'>
|
|
|
|
* <result xmlns='urn:xmpp:mam:2' queryid='f27' id='28482-98726-73623'>
|
|
|
|
* <forwarded xmlns='urn:xmpp:forward:0'>
|
|
|
|
* <delay xmlns='urn:xmpp:delay' stamp='2010-07-10T23:08:25Z'/>
|
|
|
|
* <message xmlns='jabber:client'
|
|
|
|
* to='juliet@capulet.lit/balcony'
|
|
|
|
* from='romeo@montague.lit/orchard'
|
|
|
|
* type='chat'>
|
|
|
|
* <body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>
|
|
|
|
* </message>
|
|
|
|
* </forwarded>
|
|
|
|
* </result>
|
|
|
|
* </message>
|
|
|
|
*/
|
2019-02-12 14:21:45 +01:00
|
|
|
const msg1 = $msg({'id':'aeb213', 'to':'juliet@capulet.lit/chamber'})
|
2018-10-25 07:32:44 +02:00
|
|
|
.c('result', {'xmlns': 'urn:xmpp:mam:2', 'queryid':queryid, 'id':'28482-98726-73623'})
|
|
|
|
.c('forwarded', {'xmlns':'urn:xmpp:forward:0'})
|
|
|
|
.c('delay', {'xmlns':'urn:xmpp:delay', 'stamp':'2010-07-10T23:08:25Z'}).up()
|
|
|
|
.c('message', {
|
|
|
|
'xmlns':'jabber:client',
|
|
|
|
'to':'juliet@capulet.lit/balcony',
|
|
|
|
'from':'romeo@montague.lit/orchard',
|
|
|
|
'type':'chat' })
|
|
|
|
.c('body').t("Call me but love, and I'll be new baptized;");
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(msg1));
|
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
const msg2 = $msg({'id':'aeb213', 'to':'juliet@capulet.lit/chamber'})
|
2018-10-25 07:32:44 +02:00
|
|
|
.c('result', {'xmlns': 'urn:xmpp:mam:2', 'queryid':queryid, 'id':'28482-98726-73624'})
|
|
|
|
.c('forwarded', {'xmlns':'urn:xmpp:forward:0'})
|
|
|
|
.c('delay', {'xmlns':'urn:xmpp:delay', 'stamp':'2010-07-10T23:08:25Z'}).up()
|
|
|
|
.c('message', {
|
|
|
|
'xmlns':'jabber:client',
|
|
|
|
'to':'juliet@capulet.lit/balcony',
|
|
|
|
'from':'romeo@montague.lit/orchard',
|
|
|
|
'type':'chat' })
|
|
|
|
.c('body').t("Henceforth I never will be Romeo.");
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(msg2));
|
|
|
|
|
|
|
|
/* Send an <iq> stanza to indicate the end of the result set.
|
|
|
|
*
|
|
|
|
* <iq type='result' id='juliet1'>
|
|
|
|
* <fin xmlns='urn:xmpp:mam:2'>
|
|
|
|
* <set xmlns='http://jabber.org/protocol/rsm'>
|
|
|
|
* <first index='0'>28482-98726-73623</first>
|
|
|
|
* <last>09af3-cc343-b409f</last>
|
|
|
|
* <count>20</count>
|
|
|
|
* </set>
|
|
|
|
* </iq>
|
|
|
|
*/
|
|
|
|
const stanza = $iq({'type': 'result', 'id': IQ_id})
|
|
|
|
.c('fin', {'xmlns': 'urn:xmpp:mam:2'})
|
|
|
|
.c('set', {'xmlns': 'http://jabber.org/protocol/rsm'})
|
|
|
|
.c('first', {'index': '0'}).t('23452-4534-1').up()
|
|
|
|
.c('last').t('09af3-cc343-b409f').up()
|
|
|
|
.c('count').t('16');
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
|
2019-05-03 19:47:49 +02:00
|
|
|
const result = await promise;
|
|
|
|
expect(result.messages.length).toBe(2);
|
|
|
|
expect(result.messages[0].outerHTML).toBe(msg1.nodeTree.outerHTML);
|
|
|
|
expect(result.messages[1].outerHTML).toBe(msg2.nodeTree.outerHTML);
|
|
|
|
expect(result.rsm['with']).toBe('romeo@capulet.lit'); // eslint-disable-line dot-notation
|
|
|
|
expect(result.rsm.max).toBe('10');
|
|
|
|
expect(result.rsm.count).toBe('16');
|
|
|
|
expect(result.rsm.first).toBe('23452-4534-1');
|
|
|
|
expect(result.rsm.last).toBe('09af3-cc343-b409f');
|
2018-10-25 07:32:44 +02:00
|
|
|
done()
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
});
|
2015-07-10 17:26:54 +02:00
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
describe("The default preference", function () {
|
2015-07-10 17:26:54 +02:00
|
|
|
|
2018-03-29 16:12:19 +02:00
|
|
|
it("is set once server support for MAM has been confirmed",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2018-10-25 07:32:44 +02:00
|
|
|
null, [], {},
|
|
|
|
async function (done, _converse) {
|
2015-07-10 15:07:53 +02:00
|
|
|
|
2018-10-25 07:32:44 +02:00
|
|
|
const entity = await _converse.api.disco.entities.get(_converse.domain);
|
|
|
|
let sent_stanza, IQ_id;
|
|
|
|
const sendIQ = _converse.connection.sendIQ;
|
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
|
|
|
sent_stanza = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
|
|
|
spyOn(_converse, 'onMAMPreferences').and.callThrough();
|
|
|
|
_converse.message_archiving = 'never';
|
2018-03-29 16:12:19 +02:00
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
const feature = new Backbone.Model({
|
2018-10-25 07:32:44 +02:00
|
|
|
'var': Strophe.NS.MAM
|
|
|
|
});
|
|
|
|
spyOn(feature, 'save').and.callFake(feature.set); // Save will complain about a url not being set
|
|
|
|
|
|
|
|
entity.onFeatureAdded(feature);
|
|
|
|
|
|
|
|
expect(_converse.connection.sendIQ).toHaveBeenCalled();
|
|
|
|
expect(sent_stanza.toLocaleString()).toBe(
|
|
|
|
`<iq id="${IQ_id}" type="get" xmlns="jabber:client">`+
|
|
|
|
`<prefs xmlns="urn:xmpp:mam:2"/>`+
|
|
|
|
`</iq>`);
|
|
|
|
|
|
|
|
/* Example 20. Server responds with current preferences
|
|
|
|
*
|
|
|
|
* <iq type='result' id='juliet2'>
|
|
|
|
* <prefs xmlns='urn:xmpp:mam:0' default='roster'>
|
|
|
|
* <always/>
|
|
|
|
* <never/>
|
|
|
|
* </prefs>
|
|
|
|
* </iq>
|
|
|
|
*/
|
|
|
|
let stanza = $iq({'type': 'result', 'id': IQ_id})
|
|
|
|
.c('prefs', {'xmlns': Strophe.NS.MAM, 'default':'roster'})
|
|
|
|
.c('always').c('jid').t('romeo@montague.lit').up().up()
|
|
|
|
.c('never').c('jid').t('montague@montague.lit');
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
|
|
|
|
await test_utils.waitUntil(() => _converse.onMAMPreferences.calls.count());
|
|
|
|
expect(_converse.onMAMPreferences).toHaveBeenCalled();
|
2018-03-29 16:12:19 +02:00
|
|
|
|
2018-10-25 07:32:44 +02:00
|
|
|
expect(sent_stanza.toString()).toBe(
|
|
|
|
`<iq id="${IQ_id}" type="set" xmlns="jabber:client">`+
|
|
|
|
`<prefs default="never" xmlns="urn:xmpp:mam:2">`+
|
|
|
|
`<always><jid>romeo@montague.lit</jid></always>`+
|
|
|
|
`<never><jid>montague@montague.lit</jid></never>`+
|
|
|
|
`</prefs>`+
|
|
|
|
`</iq>`
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(feature.get('preference')).toBe(undefined);
|
|
|
|
/* <iq type='result' id='juliet3'>
|
|
|
|
* <prefs xmlns='urn:xmpp:mam:0' default='always'>
|
|
|
|
* <always>
|
|
|
|
* <jid>romeo@montague.lit</jid>
|
|
|
|
* </always>
|
|
|
|
* <never>
|
|
|
|
* <jid>montague@montague.lit</jid>
|
|
|
|
* </never>
|
|
|
|
* </prefs>
|
|
|
|
* </iq>
|
|
|
|
*/
|
|
|
|
stanza = $iq({'type': 'result', 'id': IQ_id})
|
|
|
|
.c('prefs', {'xmlns': Strophe.NS.MAM, 'default':'always'})
|
2018-03-29 16:12:19 +02:00
|
|
|
.c('always').up()
|
2018-10-25 07:32:44 +02:00
|
|
|
.c('never');
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
await test_utils.waitUntil(() => feature.save.calls.count());
|
|
|
|
expect(feature.save).toHaveBeenCalled();
|
|
|
|
expect(feature.get('preferences')['default']).toBe('never'); // eslint-disable-line dot-notation
|
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|
2019-05-07 10:23:15 +02:00
|
|
|
|
|
|
|
describe("Chatboxes", function () {
|
|
|
|
describe("A Chatbox", function () {
|
|
|
|
|
|
|
|
it("will fetch archived messages once it's opened",
|
|
|
|
mock.initConverse(
|
|
|
|
null, ['discoInitialized'], {},
|
|
|
|
async function (done, _converse) {
|
|
|
|
|
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, _converse.bare_jid, null, [Strophe.NS.MAM]);
|
|
|
|
|
|
|
|
let sent_stanza, IQ_id;
|
|
|
|
const sendIQ = _converse.connection.sendIQ;
|
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
|
|
|
sent_stanza = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
|
|
|
const view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
await test_utils.waitUntil(() => sent_stanza);
|
|
|
|
const stanza_el = sent_stanza.root().nodeTree;
|
|
|
|
const queryid = stanza_el.querySelector('query').getAttribute('queryid');
|
|
|
|
expect(sent_stanza.toString()).toBe(
|
|
|
|
`<iq id="${stanza_el.getAttribute('id')}" type="set" xmlns="jabber:client">`+
|
|
|
|
`<query queryid="${queryid}" xmlns="urn:xmpp:mam:2">`+
|
|
|
|
`<x type="submit" xmlns="jabber:x:data">`+
|
|
|
|
`<field type="hidden" var="FORM_TYPE"><value>urn:xmpp:mam:2</value></field>`+
|
|
|
|
`<field var="with"><value>max.frankfurter@localhost</value></field>`+
|
|
|
|
`</x>`+
|
|
|
|
`<set xmlns="http://jabber.org/protocol/rsm"><max>50</max><before></before></set>`+
|
|
|
|
`</query>`+
|
|
|
|
`</iq>`
|
|
|
|
);
|
|
|
|
const msg1 = $msg({'id':'aeb213', 'to': contact_jid})
|
|
|
|
.c('result', {'xmlns': 'urn:xmpp:mam:2', 'queryid':queryid, 'id':'28482-98726-73623'})
|
|
|
|
.c('forwarded', {'xmlns':'urn:xmpp:forward:0'})
|
|
|
|
.c('delay', {'xmlns':'urn:xmpp:delay', 'stamp':'2010-07-10T23:08:25Z'}).up()
|
|
|
|
.c('message', {
|
|
|
|
'xmlns':'jabber:client',
|
|
|
|
'to': contact_jid,
|
|
|
|
'from': _converse.bare_jid,
|
|
|
|
'type':'chat' })
|
|
|
|
.c('body').t("Call me but love, and I'll be new baptized;");
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(msg1));
|
|
|
|
const msg2 = $msg({'id':'aeb213', 'to': contact_jid})
|
|
|
|
.c('result', {'xmlns': 'urn:xmpp:mam:2', 'queryid':queryid, 'id':'28482-98726-73624'})
|
|
|
|
.c('forwarded', {'xmlns':'urn:xmpp:forward:0'})
|
|
|
|
.c('delay', {'xmlns':'urn:xmpp:delay', 'stamp':'2010-07-10T23:08:25Z'}).up()
|
|
|
|
.c('message', {
|
|
|
|
'xmlns':'jabber:client',
|
|
|
|
'to': contact_jid,
|
|
|
|
'from': _converse.bare_jid,
|
|
|
|
'type':'chat' })
|
|
|
|
.c('body').t("Henceforth I never will be Romeo.");
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(msg2));
|
|
|
|
const stanza = $iq({'type': 'result', 'id': IQ_id})
|
|
|
|
.c('fin', {'xmlns': 'urn:xmpp:mam:2'})
|
|
|
|
.c('set', {'xmlns': 'http://jabber.org/protocol/rsm'})
|
|
|
|
.c('first', {'index': '0'}).t('23452-4534-1').up()
|
|
|
|
.c('last').t('09af3-cc343-b409f').up()
|
|
|
|
.c('count').t('16');
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
done();
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|
2015-07-10 15:07:53 +02:00
|
|
|
}));
|