Move message and conversation storage to IndexedDB
Getting up and running with IndexedDB was pretty easy, thanks to backbone. The tricky part was making reads and writes asynchronous. In that process I did some refactoring on Whisper.Threads, which has been renamed Conversations for consistency with the view names. This change also adds the unlimitedStorage permission.
This commit is contained in:
parent
5638b20046
commit
ced295a630
24 changed files with 1663 additions and 324 deletions
76
test/models/messages_test.js
Normal file
76
test/models/messages_test.js
Normal file
|
@ -0,0 +1,76 @@
|
|||
/* vim: ts=4:sw=4:expandtab
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
function clear(done) {
|
||||
var messages = new Whisper.MessageCollection();
|
||||
return messages.fetch().then(function() {
|
||||
messages.destroyAll();
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
var attributes = { type: 'outgoing',
|
||||
body: 'hi',
|
||||
conversationId: 'foo',
|
||||
attachments: [],
|
||||
timestamp: new Date().getTime() };
|
||||
|
||||
describe('MessageCollection', function() {
|
||||
before(clear);
|
||||
after(clear);
|
||||
|
||||
it('adds without saving', function() {
|
||||
var messages = new Whisper.MessageCollection();
|
||||
var message = messages.add(attributes);
|
||||
assert.notEqual(messages.length, 0);
|
||||
|
||||
var messages = new Whisper.MessageCollection();
|
||||
assert.strictEqual(messages.length, 0);
|
||||
});
|
||||
|
||||
it('saves asynchronously', function(done) {
|
||||
new Whisper.MessageCollection().add(attributes).save().then(done);
|
||||
});
|
||||
|
||||
it('fetches persistent messages', function(done) {
|
||||
var messages = new Whisper.MessageCollection();
|
||||
assert.strictEqual(messages.length, 0);
|
||||
messages.fetch().then(function() {
|
||||
assert.notEqual(messages.length, 0);
|
||||
var m = messages.at(0).attributes;
|
||||
_.each(attributes, function(val, key) {
|
||||
assert.deepEqual(m[key], val);
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('destroys persistent messages', function(done) {
|
||||
var messages = new Whisper.MessageCollection();
|
||||
messages.fetch().then(function() {
|
||||
messages.destroyAll().then(function() {
|
||||
var messages = new Whisper.MessageCollection();
|
||||
messages.fetch().then(function() {
|
||||
assert.strictEqual(messages.length, 0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
})();
|
Loading…
Add table
Add a link
Reference in a new issue