Move to centralized message/cache data layer
Also, ensure that conversation.messageCollection has nothing in it unless it has an associated ConversationView.
This commit is contained in:
parent
34231168a7
commit
f39a96bc76
21 changed files with 1119 additions and 993 deletions
|
@ -553,7 +553,13 @@ describe('Backup', () => {
|
|||
const message = await upgradeMessageSchema(messageWithAttachments);
|
||||
console.log({ message });
|
||||
const messageModel = new Whisper.Message(message);
|
||||
await window.wrapDeferred(messageModel.save());
|
||||
const id = await window.Signal.Data.saveMessage(
|
||||
messageModel.attributes,
|
||||
{
|
||||
Message: Whisper.Message,
|
||||
}
|
||||
);
|
||||
messageModel.set({ id });
|
||||
|
||||
const conversation = {
|
||||
active_at: 1524185933350,
|
||||
|
|
|
@ -231,21 +231,20 @@ Whisper.Fixtures = function() {
|
|||
|
||||
conversationCollection.saveAll = function() {
|
||||
return Promise.all(
|
||||
this.map(function(convo) {
|
||||
return new Promise(function(resolve) {
|
||||
convo.save().then(resolve);
|
||||
}).then(function() {
|
||||
return Promise.all(
|
||||
convo.messageCollection.map(function(message) {
|
||||
return new Promise(function(resolve) {
|
||||
message.save().then(resolve);
|
||||
});
|
||||
})
|
||||
);
|
||||
});
|
||||
this.map(async (convo) => {
|
||||
await wrapDeferred(convo.save());
|
||||
|
||||
await Promise.all(
|
||||
convo.messageCollection.map(async (message) => {
|
||||
const id = await window.Signal.Data.saveMessage(message.attributes, {
|
||||
Message: Whisper.Message
|
||||
});
|
||||
message.set({ id });
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
function getImage1() {
|
||||
return (
|
||||
|
|
|
@ -83,17 +83,19 @@
|
|||
|
||||
describe('Conversation', function() {
|
||||
var attributes = { type: 'private', id: '+18085555555' };
|
||||
before(function(done) {
|
||||
before(async () => {
|
||||
var convo = new Whisper.ConversationCollection().add(attributes);
|
||||
convo.save().then(function() {
|
||||
var message = convo.messageCollection.add({
|
||||
body: 'hello world',
|
||||
conversationId: convo.id,
|
||||
type: 'outgoing',
|
||||
sent_at: Date.now(),
|
||||
received_at: Date.now(),
|
||||
});
|
||||
message.save().then(done);
|
||||
await wrapDeferred(convo.save());
|
||||
|
||||
var message = convo.messageCollection.add({
|
||||
body: 'hello world',
|
||||
conversationId: convo.id,
|
||||
type: 'outgoing',
|
||||
sent_at: Date.now(),
|
||||
received_at: Date.now(),
|
||||
});
|
||||
await window.Signal.Data.saveMessage(message.attributes, {
|
||||
Message: Whisper.Message,
|
||||
});
|
||||
});
|
||||
after(clearDatabase);
|
||||
|
|
|
@ -1,16 +1,6 @@
|
|||
(function() {
|
||||
'use strict';
|
||||
|
||||
function deleteAllMessages() {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var messages = new Whisper.MessageCollection();
|
||||
return messages.fetch().then(function() {
|
||||
messages.destroyAll();
|
||||
resolve();
|
||||
}, reject);
|
||||
});
|
||||
}
|
||||
|
||||
var attributes = {
|
||||
type: 'outgoing',
|
||||
body: 'hi',
|
||||
|
@ -28,12 +18,12 @@
|
|||
|
||||
describe('MessageCollection', function() {
|
||||
before(async function() {
|
||||
await deleteAllMessages();
|
||||
await clearDatabase();
|
||||
ConversationController.reset();
|
||||
await ConversationController.load();
|
||||
});
|
||||
after(function() {
|
||||
return deleteAllMessages();
|
||||
return clearDatabase();
|
||||
});
|
||||
|
||||
it('gets outgoing contact', function() {
|
||||
|
@ -60,39 +50,6 @@
|
|||
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should be ordered oldest to newest', function() {
|
||||
var messages = new Whisper.MessageCollection();
|
||||
// Timestamps
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue