AxolotlStore stores groups in indexeddb

This commit is contained in:
lilia 2015-05-06 15:09:03 -07:00
parent 359b4a15a2
commit d0e262d7cb
3 changed files with 26 additions and 4 deletions

View File

@ -81,6 +81,7 @@
}
});
var IdentityKey = Model.extend({ storeName: 'identityKeys' });
var Group = Model.extend({ storeName: 'groups' });
function AxolotlStore() {}
@ -280,13 +281,32 @@
});
},
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) {
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) {
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);
});
},
};

View File

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

View File

@ -126,7 +126,7 @@
});
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();
assert.notEqual(convo.messageCollection.length, 0);
});