AxolotlStore stores groups in indexeddb

pull/749/head
lilia 10 years ago
parent 359b4a15a2
commit d0e262d7cb

@ -81,6 +81,7 @@
} }
}); });
var IdentityKey = Model.extend({ storeName: 'identityKeys' }); var IdentityKey = Model.extend({ storeName: 'identityKeys' });
var Group = Model.extend({ storeName: 'groups' });
function AxolotlStore() {} function AxolotlStore() {}
@ -280,13 +281,32 @@
}); });
}, },
getGroup: function(groupId) { getGroup: function(groupId) {
return Promise.resolve(textsecure.storage.get("group" + groupId)); if (groupId === null || groupId === undefined)
throw new Error("Tried to get group for undefined/null id");
return new Promise(function(resolve) {
var group = new Group({id: groupId});
group.fetch().always(function() {
resolve(group.get('data'));
});
});
}, },
putGroup: function(groupId, group) { putGroup: function(groupId, group) {
return Promise.resolve(textsecure.storage.put("group" + groupId, group)); if (groupId === null || groupId === undefined)
throw new Error("Tried to put group key for undefined/null id");
if (group === null || group === undefined)
throw new Error("Tried to put undefined/null group object");
var group = new Group({id: groupId, data: group});
return new Promise(function(resolve) {
group.save().always(resolve);
});
}, },
removeGroup: function(groupId) { removeGroup: function(groupId) {
return Promise.resolve(textsecure.storage.remove("group" + groupId)); if (groupId === null || groupId === undefined)
throw new Error("Tried to remove group key for undefined/null id");
return new Promise(function(resolve) {
var group = new Group({id: groupId});
group.destroy().always(resolve);
});
}, },
}; };

@ -34,6 +34,8 @@
conversations.createIndex("group", "members", { unique: false, multiEntry: true }); conversations.createIndex("group", "members", { unique: false, multiEntry: true });
conversations.createIndex("type", "type", { unique: false }); conversations.createIndex("type", "type", { unique: false });
var groups = transaction.db.createObjectStore('groups');
var sessions = transaction.db.createObjectStore('sessions'); var sessions = transaction.db.createObjectStore('sessions');
var identityKeys = transaction.db.createObjectStore('identityKeys'); var identityKeys = transaction.db.createObjectStore('identityKeys');

@ -126,7 +126,7 @@
}); });
it('adds conversation to message collection upon leaving group', function() { it('adds conversation to message collection upon leaving group', function() {
var convo = new Whisper.ConversationCollection().add({type: 'group'}); var convo = new Whisper.ConversationCollection().add({type: 'group', id: 'a random string'});
convo.leaveGroup(); convo.leaveGroup();
assert.notEqual(convo.messageCollection.length, 0); assert.notEqual(convo.messageCollection.length, 0);
}); });

Loading…
Cancel
Save