2015-07-10 15:07:53 +02:00
|
|
|
(function (root, factory) {
|
2018-01-04 12:41:03 +01:00
|
|
|
define(["jquery", "jasmine", "mock", "converse-core", "test-utils"], factory);
|
2017-07-11 10:41:11 +02:00
|
|
|
} (this, function ($, jasmine, mock, converse, test_utils) {
|
2015-07-10 15:07:53 +02:00
|
|
|
"use strict";
|
2016-12-20 10:30:20 +01:00
|
|
|
var _ = converse.env._;
|
2017-07-19 09:10:17 +02:00
|
|
|
var Backbone = converse.env.Backbone;
|
2016-12-20 10:30:20 +01:00
|
|
|
var Strophe = converse.env.Strophe;
|
|
|
|
var $iq = converse.env.$iq;
|
|
|
|
var $msg = converse.env.$msg;
|
|
|
|
var moment = converse.env.moment;
|
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
|
|
|
|
|
2018-01-09 23:05:23 +01:00
|
|
|
describe("Archived Messages", function () {
|
|
|
|
|
|
|
|
it("aren't shown as duplicates",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['discoInitialized'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
|
|
|
test_utils.openAndEnterChatRoom(_converse, 'trek-radio', 'conference.lightwitch.org', 'jcbrand').then(function () {
|
|
|
|
var chatroomview = _converse.chatboxviews.get('trek-radio@conference.lightwitch.org');
|
|
|
|
var stanza = Strophe.xmlHtmlNode(
|
|
|
|
`<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>`).firstElementChild;
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
|
|
|
|
stanza = Strophe.xmlHtmlNode(
|
|
|
|
`<message xmlns="jabber:client" to="jcbrand@lightwitch.org/converse.js-73057452">
|
|
|
|
<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>`).firstElementChild;
|
|
|
|
chatroomview.onChatRoomMessage(stanza);
|
|
|
|
expect(chatroomview.content.querySelectorAll('.chat-message').length).toBe(1);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
}))
|
|
|
|
});
|
|
|
|
|
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",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['discoInitialized'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2015-07-10 17:26:54 +02:00
|
|
|
var sent_stanza, IQ_id;
|
2016-12-20 10:30:20 +01:00
|
|
|
var 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);
|
|
|
|
});
|
2017-07-21 12:41:16 +02:00
|
|
|
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});
|
2015-07-10 17:26:54 +02:00
|
|
|
}
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.api.archive.query();
|
2015-07-10 17:26:54 +02:00
|
|
|
var queryid = $(sent_stanza.toString()).find('query').attr('queryid');
|
|
|
|
expect(sent_stanza.toString()).toBe(
|
2017-06-23 22:53:11 +02:00
|
|
|
"<iq type='set' xmlns='jabber:client' id='"+IQ_id+"'><query xmlns='urn:xmpp:mam:2' queryid='"+queryid+"'/></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
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("can be used to query for all messages to/from a particular JID", mock.initConverse(function (_converse) {
|
2015-07-10 17:26:54 +02:00
|
|
|
var sent_stanza, IQ_id;
|
2016-12-20 10:30:20 +01:00
|
|
|
var 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);
|
|
|
|
});
|
2017-07-21 12:41:16 +02:00
|
|
|
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});
|
2015-07-10 17:26:54 +02:00
|
|
|
}
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.api.archive.query({'with':'juliet@capulet.lit'});
|
2015-07-10 17:26:54 +02:00
|
|
|
var queryid = $(sent_stanza.toString()).find('query').attr('queryid');
|
|
|
|
expect(sent_stanza.toString()).toBe(
|
|
|
|
"<iq type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
|
2017-06-23 22:53:11 +02:00
|
|
|
"<query xmlns='urn:xmpp:mam:2' queryid='"+queryid+"'>"+
|
2015-07-29 14:35:07 +02:00
|
|
|
"<x xmlns='jabber:x:data' type='submit'>"+
|
|
|
|
"<field var='FORM_TYPE' type='hidden'>"+
|
2017-06-23 22:53:11 +02:00
|
|
|
"<value>urn:xmpp:mam:2</value>"+
|
2015-07-10 17:26:54 +02:00
|
|
|
"</field>"+
|
|
|
|
"<field var='with'>"+
|
|
|
|
"<value>juliet@capulet.lit</value>"+
|
|
|
|
"</field>"+
|
|
|
|
"</x>"+
|
|
|
|
"</query>"+
|
|
|
|
"</iq>"
|
|
|
|
);
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2015-07-10 15:07:53 +02:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("can be used to query for all messages in a certain timespan", mock.initConverse(function (_converse) {
|
2015-07-10 17:26:54 +02:00
|
|
|
var sent_stanza, IQ_id;
|
2016-12-20 10:30:20 +01:00
|
|
|
var 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);
|
|
|
|
});
|
2017-07-21 12:41:16 +02:00
|
|
|
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});
|
2015-07-10 17:26:54 +02:00
|
|
|
}
|
2015-07-21 23:18:03 +02:00
|
|
|
var start = '2010-06-07T00:00:00Z';
|
|
|
|
var end = '2010-07-07T13:23:54Z';
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.api.archive.query({
|
2015-07-21 23:18:03 +02:00
|
|
|
'start': start,
|
|
|
|
'end': end
|
2015-07-10 17:26:54 +02:00
|
|
|
|
|
|
|
});
|
|
|
|
var queryid = $(sent_stanza.toString()).find('query').attr('queryid');
|
|
|
|
expect(sent_stanza.toString()).toBe(
|
|
|
|
"<iq type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
|
2017-06-23 22:53:11 +02:00
|
|
|
"<query xmlns='urn:xmpp:mam:2' queryid='"+queryid+"'>"+
|
2015-07-29 14:35:07 +02:00
|
|
|
"<x xmlns='jabber:x:data' type='submit'>"+
|
|
|
|
"<field var='FORM_TYPE' type='hidden'>"+
|
2017-06-23 22:53:11 +02:00
|
|
|
"<value>urn:xmpp:mam:2</value>"+
|
2015-07-10 17:26:54 +02:00
|
|
|
"</field>"+
|
|
|
|
"<field var='start'>"+
|
2015-07-21 23:18:03 +02:00
|
|
|
"<value>"+moment(start).format()+"</value>"+
|
2015-07-10 17:26:54 +02:00
|
|
|
"</field>"+
|
|
|
|
"<field var='end'>"+
|
2015-07-21 23:18:03 +02:00
|
|
|
"<value>"+moment(end).format()+"</value>"+
|
2015-07-10 17:26:54 +02:00
|
|
|
"</field>"+
|
|
|
|
"</x>"+
|
|
|
|
"</query>"+
|
|
|
|
"</iq>"
|
|
|
|
);
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2015-07-10 17:26:54 +02:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("throws a TypeError if an invalid date is provided", mock.initConverse(function (_converse) {
|
2017-07-21 12:41:16 +02:00
|
|
|
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});
|
2016-11-03 11:01:09 +01:00
|
|
|
}
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_.partial(_converse.api.archive.query, {'start': 'not a real date'})).toThrow(
|
2015-07-10 17:26:54 +02:00
|
|
|
new TypeError('archive.query: invalid date provided for: start')
|
|
|
|
);
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2015-07-10 17:26:54 +02:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("can be used to query for all messages after a certain time", mock.initConverse(function (_converse) {
|
2015-07-10 17:26:54 +02:00
|
|
|
var sent_stanza, IQ_id;
|
2016-12-20 10:30:20 +01:00
|
|
|
var 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);
|
|
|
|
});
|
2017-07-21 12:41:16 +02:00
|
|
|
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});
|
2015-07-10 17:26:54 +02:00
|
|
|
}
|
2015-07-21 23:18:03 +02:00
|
|
|
var start = '2010-06-07T00:00:00Z';
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.api.archive.query({'start': start});
|
2015-07-10 17:26:54 +02:00
|
|
|
var queryid = $(sent_stanza.toString()).find('query').attr('queryid');
|
|
|
|
expect(sent_stanza.toString()).toBe(
|
|
|
|
"<iq type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
|
2017-06-23 22:53:11 +02:00
|
|
|
"<query xmlns='urn:xmpp:mam:2' queryid='"+queryid+"'>"+
|
2015-07-29 14:35:07 +02:00
|
|
|
"<x xmlns='jabber:x:data' type='submit'>"+
|
|
|
|
"<field var='FORM_TYPE' type='hidden'>"+
|
2017-06-23 22:53:11 +02:00
|
|
|
"<value>urn:xmpp:mam:2</value>"+
|
2015-07-10 17:26:54 +02:00
|
|
|
"</field>"+
|
|
|
|
"<field var='start'>"+
|
2015-07-21 23:18:03 +02:00
|
|
|
"<value>"+moment(start).format()+"</value>"+
|
2015-07-10 17:26:54 +02:00
|
|
|
"</field>"+
|
|
|
|
"</x>"+
|
|
|
|
"</query>"+
|
|
|
|
"</iq>"
|
|
|
|
);
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2015-07-10 17:26:54 +02:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("can be used to query for a limited set of results", mock.initConverse(function (_converse) {
|
2015-07-10 17:26:54 +02:00
|
|
|
var sent_stanza, IQ_id;
|
2016-12-20 10:30:20 +01:00
|
|
|
var 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);
|
|
|
|
});
|
2017-07-21 12:41:16 +02:00
|
|
|
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});
|
2015-07-10 17:26:54 +02:00
|
|
|
}
|
2015-07-21 23:18:03 +02:00
|
|
|
var start = '2010-06-07T00:00:00Z';
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.api.archive.query({'start': start, 'max':10});
|
2015-07-10 17:26:54 +02:00
|
|
|
var queryid = $(sent_stanza.toString()).find('query').attr('queryid');
|
|
|
|
expect(sent_stanza.toString()).toBe(
|
|
|
|
"<iq type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
|
2017-06-23 22:53:11 +02:00
|
|
|
"<query xmlns='urn:xmpp:mam:2' queryid='"+queryid+"'>"+
|
2015-07-29 14:35:07 +02:00
|
|
|
"<x xmlns='jabber:x:data' type='submit'>"+
|
|
|
|
"<field var='FORM_TYPE' type='hidden'>"+
|
2017-06-23 22:53:11 +02:00
|
|
|
"<value>urn:xmpp:mam:2</value>"+
|
2015-07-10 17:26:54 +02:00
|
|
|
"</field>"+
|
|
|
|
"<field var='start'>"+
|
2015-07-21 23:18:03 +02:00
|
|
|
"<value>"+moment(start).format()+"</value>"+
|
2015-07-10 17:26:54 +02:00
|
|
|
"</field>"+
|
|
|
|
"</x>"+
|
|
|
|
"<set xmlns='http://jabber.org/protocol/rsm'>"+
|
|
|
|
"<max>10</max>"+
|
|
|
|
"</set>"+
|
|
|
|
"</query>"+
|
|
|
|
"</iq>"
|
|
|
|
);
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2015-07-10 17:26:54 +02:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("can be used to page through results", mock.initConverse(function (_converse) {
|
2015-07-10 17:26:54 +02:00
|
|
|
var sent_stanza, IQ_id;
|
2016-12-20 10:30:20 +01:00
|
|
|
var 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);
|
|
|
|
});
|
2017-07-21 12:41:16 +02:00
|
|
|
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});
|
2015-07-10 17:26:54 +02:00
|
|
|
}
|
2015-07-21 23:18:03 +02:00
|
|
|
var start = '2010-06-07T00:00:00Z';
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.api.archive.query({
|
2015-07-21 23:18:03 +02:00
|
|
|
'start': start,
|
2015-07-10 17:26:54 +02:00
|
|
|
'after': '09af3-cc343-b409f',
|
2015-07-11 12:03:20 +02:00
|
|
|
'max':10
|
2015-07-10 17:26:54 +02:00
|
|
|
});
|
|
|
|
var queryid = $(sent_stanza.toString()).find('query').attr('queryid');
|
|
|
|
expect(sent_stanza.toString()).toBe(
|
|
|
|
"<iq type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
|
2017-06-23 22:53:11 +02:00
|
|
|
"<query xmlns='urn:xmpp:mam:2' queryid='"+queryid+"'>"+
|
2015-07-29 14:35:07 +02:00
|
|
|
"<x xmlns='jabber:x:data' type='submit'>"+
|
|
|
|
"<field var='FORM_TYPE' type='hidden'>"+
|
2017-06-23 22:53:11 +02:00
|
|
|
"<value>urn:xmpp:mam:2</value>"+
|
2015-07-10 17:26:54 +02:00
|
|
|
"</field>"+
|
|
|
|
"<field var='start'>"+
|
2015-07-21 23:18:03 +02:00
|
|
|
"<value>"+moment(start).format()+"</value>"+
|
2015-07-10 17:26:54 +02:00
|
|
|
"</field>"+
|
|
|
|
"</x>"+
|
|
|
|
"<set xmlns='http://jabber.org/protocol/rsm'>"+
|
|
|
|
"<max>10</max>"+
|
|
|
|
"<after>09af3-cc343-b409f</after>"+
|
|
|
|
"</set>"+
|
|
|
|
"</query>"+
|
|
|
|
"</iq>"
|
|
|
|
);
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2015-07-10 17:26:54 +02:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("accepts \"before\" with an empty string as value to reverse the order", mock.initConverse(function (_converse) {
|
2015-07-12 21:27:22 +02:00
|
|
|
var sent_stanza, IQ_id;
|
2016-12-20 10:30:20 +01:00
|
|
|
var sendIQ = _converse.connection.sendIQ;
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
2015-07-12 21:27:22 +02:00
|
|
|
sent_stanza = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
2017-07-21 12:41:16 +02:00
|
|
|
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});
|
2015-07-12 21:27:22 +02:00
|
|
|
}
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.api.archive.query({'before': '', 'max':10});
|
2015-07-12 21:27:22 +02:00
|
|
|
var queryid = $(sent_stanza.toString()).find('query').attr('queryid');
|
|
|
|
expect(sent_stanza.toString()).toBe(
|
|
|
|
"<iq type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
|
2017-06-23 22:53:11 +02:00
|
|
|
"<query xmlns='urn:xmpp:mam:2' queryid='"+queryid+"'>"+
|
2015-07-29 14:35:07 +02:00
|
|
|
"<x xmlns='jabber:x:data' type='submit'>"+
|
|
|
|
"<field var='FORM_TYPE' type='hidden'>"+
|
2017-06-23 22:53:11 +02:00
|
|
|
"<value>urn:xmpp:mam:2</value>"+
|
2015-07-12 21:27:22 +02:00
|
|
|
"</field>"+
|
|
|
|
"</x>"+
|
|
|
|
"<set xmlns='http://jabber.org/protocol/rsm'>"+
|
|
|
|
"<max>10</max>"+
|
|
|
|
"<before></before>"+
|
|
|
|
"</set>"+
|
|
|
|
"</query>"+
|
|
|
|
"</iq>"
|
|
|
|
);
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2015-07-12 21:27:22 +02:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("accepts a Strophe.RSM object for the query options", mock.initConverse(function (_converse) {
|
2015-07-12 22:00:32 +02: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.
|
2017-07-21 12:41:16 +02:00
|
|
|
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});
|
2015-07-12 23:58:07 +02:00
|
|
|
}
|
2015-07-12 22:00:32 +02:00
|
|
|
var sent_stanza, IQ_id;
|
2016-12-20 10:30:20 +01:00
|
|
|
var sendIQ = _converse.connection.sendIQ;
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
2015-07-12 22:00:32 +02:00
|
|
|
sent_stanza = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
|
|
|
var rsm = new Strophe.RSM({'max': '10'});
|
2017-07-21 12:41:16 +02:00
|
|
|
rsm['with'] = 'romeo@montague.lit'; // eslint-disable-line dot-notation
|
2015-07-12 22:00:32 +02:00
|
|
|
rsm.start = '2010-06-07T00:00:00Z';
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.api.archive.query(rsm);
|
2015-07-12 22:00:32 +02:00
|
|
|
|
|
|
|
var queryid = $(sent_stanza.toString()).find('query').attr('queryid');
|
|
|
|
expect(sent_stanza.toString()).toBe(
|
|
|
|
"<iq type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
|
2017-06-23 22:53:11 +02:00
|
|
|
"<query xmlns='urn:xmpp:mam:2' queryid='"+queryid+"'>"+
|
2015-07-29 14:35:07 +02:00
|
|
|
"<x xmlns='jabber:x:data' type='submit'>"+
|
|
|
|
"<field var='FORM_TYPE' type='hidden'>"+
|
2017-06-23 22:53:11 +02:00
|
|
|
"<value>urn:xmpp:mam:2</value>"+
|
2015-07-12 22:00:32 +02:00
|
|
|
"</field>"+
|
|
|
|
"<field var='with'>"+
|
|
|
|
"<value>romeo@montague.lit</value>"+
|
|
|
|
"</field>"+
|
|
|
|
"<field var='start'>"+
|
2015-07-21 23:18:03 +02:00
|
|
|
"<value>"+moment(rsm.start).format()+"</value>"+
|
2015-07-12 22:00:32 +02:00
|
|
|
"</field>"+
|
|
|
|
"</x>"+
|
|
|
|
"<set xmlns='http://jabber.org/protocol/rsm'>"+
|
|
|
|
"<max>10</max>"+
|
|
|
|
"</set>"+
|
|
|
|
"</query>"+
|
|
|
|
"</iq>"
|
|
|
|
);
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2015-07-12 22:00:32 +02:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("accepts a callback function, which it passes the messages and a Strophe.RSM object", mock.initConverse(function (_converse) {
|
2017-07-21 12:41:16 +02:00
|
|
|
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});
|
2015-07-12 23:58:07 +02:00
|
|
|
}
|
|
|
|
var sent_stanza, IQ_id;
|
2016-12-20 10:30:20 +01:00
|
|
|
var sendIQ = _converse.connection.sendIQ;
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
2015-07-12 23:58:07 +02:00
|
|
|
sent_stanza = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
|
|
|
var callback = jasmine.createSpy('callback');
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.api.archive.query({'with': 'romeo@capulet.lit', 'max':'10'}, callback);
|
2015-07-12 23:58:07 +02:00
|
|
|
var queryid = $(sent_stanza.toString()).find('query').attr('queryid');
|
|
|
|
|
2017-06-23 22:53:11 +02:00
|
|
|
/* <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>
|
2015-07-13 23:16:21 +02:00
|
|
|
*/
|
|
|
|
var msg1 = $msg({'id':'aeb213', 'to':'juliet@capulet.lit/chamber'})
|
2017-06-23 22:53:11 +02:00
|
|
|
.c('result', {'xmlns': 'urn:xmpp:mam:2', 'queryid':queryid, 'id':'28482-98726-73623'})
|
2015-07-13 23:16:21 +02:00
|
|
|
.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;");
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(msg1));
|
2015-07-13 23:16:21 +02:00
|
|
|
|
|
|
|
var msg2 = $msg({'id':'aeb213', 'to':'juliet@capulet.lit/chamber'})
|
2017-06-23 22:53:11 +02:00
|
|
|
.c('result', {'xmlns': 'urn:xmpp:mam:2', 'queryid':queryid, 'id':'28482-98726-73624'})
|
2015-07-13 23:16:21 +02:00
|
|
|
.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.");
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(msg2));
|
2015-07-13 23:16:21 +02:00
|
|
|
|
2017-06-23 22:53:11 +02:00
|
|
|
/* Send an <iq> stanza to indicate the end of the result set.
|
2015-07-12 23:58:07 +02:00
|
|
|
*
|
2017-06-23 22:53:11 +02:00
|
|
|
* <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>
|
2015-07-12 23:58:07 +02:00
|
|
|
*/
|
2017-06-23 22:53:11 +02:00
|
|
|
var 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');
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2015-07-12 23:58:07 +02:00
|
|
|
|
|
|
|
expect(callback).toHaveBeenCalled();
|
2017-04-05 11:01:31 +02:00
|
|
|
var args = callback.calls.argsFor(0);
|
2015-07-13 23:16:21 +02:00
|
|
|
expect(args[0].length).toBe(2);
|
|
|
|
expect(args[0][0].outerHTML).toBe(msg1.nodeTree.outerHTML);
|
|
|
|
expect(args[0][1].outerHTML).toBe(msg2.nodeTree.outerHTML);
|
2017-07-21 12:41:16 +02:00
|
|
|
expect(args[1]['with']).toBe('romeo@capulet.lit'); // eslint-disable-line dot-notation
|
2015-07-12 23:58:07 +02:00
|
|
|
expect(args[1].max).toBe('10');
|
|
|
|
expect(args[1].count).toBe('16');
|
|
|
|
expect(args[1].first).toBe('23452-4534-1');
|
2017-06-23 22:53:11 +02:00
|
|
|
expect(args[1].last).toBe('09af3-cc343-b409f');
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2015-07-12 23:58:07 +02:00
|
|
|
|
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
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("is set once server support for MAM has been confirmed", mock.initConverse(function (_converse) {
|
2015-07-10 15:07:53 +02:00
|
|
|
var sent_stanza, IQ_id;
|
2016-12-20 10:30:20 +01:00
|
|
|
var 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 15:07:53 +02:00
|
|
|
sent_stanza = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse, 'onMAMPreferences').and.callThrough();
|
2017-02-12 20:01:07 +01:00
|
|
|
_converse.message_archiving = 'never';
|
2015-07-10 15:07:53 +02:00
|
|
|
|
2017-07-19 09:10:17 +02:00
|
|
|
var feature = new Backbone.Model({
|
2015-07-10 15:07:53 +02:00
|
|
|
'var': Strophe.NS.MAM
|
|
|
|
});
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(feature, 'save').and.callFake(feature.set); // Save will complain about a url not being set
|
2017-07-21 17:38:08 +02:00
|
|
|
_converse.disco_entities.get(_converse.domain).onFeatureAdded(feature);
|
2015-07-10 15:07:53 +02:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.connection.sendIQ).toHaveBeenCalled();
|
2015-07-10 15:07:53 +02:00
|
|
|
expect(sent_stanza.toLocaleString()).toBe(
|
|
|
|
"<iq type='get' xmlns='jabber:client' id='"+IQ_id+"'>"+
|
2017-06-23 22:53:11 +02:00
|
|
|
"<prefs xmlns='urn:xmpp:mam:2'/>"+
|
2015-07-10 15:07:53 +02:00
|
|
|
"</iq>"
|
|
|
|
);
|
|
|
|
|
2017-06-23 22:53:11 +02:00
|
|
|
/* Example 20. Server responds with current preferences
|
2015-07-10 15:07:53 +02:00
|
|
|
*
|
|
|
|
* <iq type='result' id='juliet2'>
|
|
|
|
* <prefs xmlns='urn:xmpp:mam:0' default='roster'>
|
|
|
|
* <always/>
|
|
|
|
* <never/>
|
|
|
|
* </prefs>
|
|
|
|
* </iq>
|
|
|
|
*/
|
|
|
|
var 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');
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2015-07-10 15:07:53 +02:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.onMAMPreferences).toHaveBeenCalled();
|
2015-07-10 15:07:53 +02:00
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
expect(_converse.connection.sendIQ.calls.count()).toBe(2);
|
2015-07-10 15:07:53 +02:00
|
|
|
expect(sent_stanza.toString()).toBe(
|
|
|
|
"<iq type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
|
2017-06-23 22:53:11 +02:00
|
|
|
"<prefs xmlns='urn:xmpp:mam:2' default='never'>"+
|
2015-07-10 15:07:53 +02:00
|
|
|
"<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'})
|
|
|
|
.c('always').up()
|
|
|
|
.c('never').up();
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2015-07-10 15:07:53 +02:00
|
|
|
expect(feature.save).toHaveBeenCalled();
|
2017-07-21 12:41:16 +02:00
|
|
|
expect(feature.get('preferences')['default']).toBe('never'); // eslint-disable-line dot-notation
|
2015-07-10 15:07:53 +02:00
|
|
|
|
|
|
|
// Restore
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.message_archiving = 'never';
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|
2015-07-10 15:07:53 +02:00
|
|
|
}));
|