xmpp.chapril.org-conversejs/spec/transcripts.js
JC Brand 1fa203c990 Support for IndexedDB. updates #1105
Depend on latest backbone.browserStorage which has support for IndexedDB
via localforage.

Storage operations are now asynchronous and transactional.

Bugs fixed (mostly by waiting for operations to complete):

* Rooms are now fetched asynchronously, so wait before triggering `show`
  or when closing.
* Make sure chat create/update transactions complete before firing events
* Make sure chats and messages have been fetched before creating new ones.
* When doing a `fetch` with `wait: false` on a collection and then
  creating a model in that collection, then once the read
  operation finishes (after creating the model), the collection is emptied again.
* Patch and wait when saving.
  Otherwise we have previously set attributes overriding later ones.
* Make sure api.roomviews.close returns a promise

Test fixes:

* Chats are now asynchronously returned, so we need to use `await`
* Wait for the storage transaction to complete when creating and updating messages
* Wait for all chatboxes to close
    Otherwise we get sessionStorage inconsistencies due to the async nature of localforage.
* Wait for room views to close in spec/chatroom.js

In the process, remove the `closeAllChatBoxes` override in
converse-controlbox by letting the `close` method decide whether it
should be closed or not.
2019-10-30 13:02:23 +01:00

78 lines
2.5 KiB
JavaScript

(function (root, factory) {
define([
"jasmine",
"mock",
"test-utils",
"utils",
"transcripts"
], factory
);
} (this, function (jasmine, mock, test_utils, utils, transcripts) {
var Strophe = converse.env.Strophe;
var _ = converse.env._;
var IGNORED_TAGS = [
'stream:features',
'auth',
'challenge',
'success',
'stream:features',
'response'
];
function traverseElement (el, _stanza) {
if (typeof _stanza !== 'undefined') {
if (el.nodeType === 3) {
_stanza.t(el.nodeValue);
return _stanza;
} else {
_stanza = _stanza.c(el.nodeName.toLowerCase(), getAttributes(el));
}
} else {
_stanza = new Strophe.Builder(
el.nodeName.toLowerCase(),
getAttributes(el)
);
}
_.each(el.childNodes, _.partial(traverseElement, _, _stanza));
return _stanza.up();
}
function getAttributes (el) {
var attributes = {};
_.each(el.attributes, function (att) {
attributes[att.nodeName] = att.nodeValue;
});
return attributes;
}
return describe("Transcripts of chat logs", function () {
it("can be used to replay conversations",
mock.initConverse(
['rosterGroupsFetched'], {},
async function (done, _converse) {
_converse.allow_non_roster_messaging = true;
await test_utils.openAndEnterChatRoom(_converse, 'discuss@conference.conversejs.org', 'romeo');
spyOn(_converse, 'areDesktopNotificationsEnabled').and.returnValue(true);
_.each(transcripts, function (transcript) {
const text = transcript();
const xml = Strophe.xmlHtmlNode(text);
_.each(xml.firstElementChild.children, function (el) {
_.each(el.children, function (el) {
if (el.nodeType === 3) {
return; // Ignore text
}
if (_.includes(IGNORED_TAGS, el.nodeName.toLowerCase())) {
return;
}
const _stanza = traverseElement(el);
_converse.connection._dataRecv(test_utils.createRequest(_stanza));
});
});
});
done();
}));
});
}));