MessageReceiver cache: Don't convert to string for save
Because IndexedDB supports ArrayBuffer natively. FREEBIE
This commit is contained in:
parent
07ec2707ac
commit
84fd605ad3
2 changed files with 26 additions and 18 deletions
|
@ -38418,12 +38418,21 @@ MessageReceiver.prototype.extend({
|
||||||
},
|
},
|
||||||
queueCached: function(item) {
|
queueCached: function(item) {
|
||||||
try {
|
try {
|
||||||
var envelopePlaintext = this.stringToArrayBuffer(item.envelope);
|
var envelopePlaintext = item.envelope;
|
||||||
|
|
||||||
|
// Up until 0.42.6 we stored envelope and decrypted as strings in IndexedDB,
|
||||||
|
// so we need to be ready for them.
|
||||||
|
if (typeof envelopePlaintext === 'string') {
|
||||||
|
envelopePlaintext = this.stringToArrayBuffer(envelopePlaintext);
|
||||||
|
}
|
||||||
var envelope = textsecure.protobuf.Envelope.decode(envelopePlaintext);
|
var envelope = textsecure.protobuf.Envelope.decode(envelopePlaintext);
|
||||||
|
|
||||||
var decrypted = item.decrypted;
|
var decrypted = item.decrypted;
|
||||||
if (decrypted) {
|
if (decrypted) {
|
||||||
var payloadPlaintext = this.stringToArrayBuffer(decrypted);
|
var payloadPlaintext = decrypted;
|
||||||
|
if (typeof payloadPlaintext === 'string') {
|
||||||
|
payloadPlaintext = this.stringToArrayBuffer(payloadPlaintext);
|
||||||
|
}
|
||||||
this.queueDecryptedEnvelope(envelope, payloadPlaintext);
|
this.queueDecryptedEnvelope(envelope, payloadPlaintext);
|
||||||
} else {
|
} else {
|
||||||
this.queueEnvelope(envelope);
|
this.queueEnvelope(envelope);
|
||||||
|
@ -38436,9 +38445,6 @@ MessageReceiver.prototype.extend({
|
||||||
getEnvelopeId: function(envelope) {
|
getEnvelopeId: function(envelope) {
|
||||||
return envelope.source + '.' + envelope.sourceDevice + ' ' + envelope.timestamp.toNumber();
|
return envelope.source + '.' + envelope.sourceDevice + ' ' + envelope.timestamp.toNumber();
|
||||||
},
|
},
|
||||||
arrayBufferToString: function(arrayBuffer) {
|
|
||||||
return new dcodeIO.ByteBuffer.wrap(arrayBuffer).toString('binary');
|
|
||||||
},
|
|
||||||
stringToArrayBuffer: function(string) {
|
stringToArrayBuffer: function(string) {
|
||||||
return new dcodeIO.ByteBuffer.wrap(string, 'binary').toArrayBuffer();
|
return new dcodeIO.ByteBuffer.wrap(string, 'binary').toArrayBuffer();
|
||||||
},
|
},
|
||||||
|
@ -38469,10 +38475,9 @@ MessageReceiver.prototype.extend({
|
||||||
addToCache: function(envelope, plaintext) {
|
addToCache: function(envelope, plaintext) {
|
||||||
var id = this.getEnvelopeId(envelope);
|
var id = this.getEnvelopeId(envelope);
|
||||||
console.log('addToCache', id);
|
console.log('addToCache', id);
|
||||||
var string = this.arrayBufferToString(plaintext);
|
|
||||||
var data = {
|
var data = {
|
||||||
id: id,
|
id: id,
|
||||||
envelope: string,
|
envelope: plaintext,
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
attempts: 1
|
attempts: 1
|
||||||
};
|
};
|
||||||
|
@ -38481,9 +38486,8 @@ MessageReceiver.prototype.extend({
|
||||||
updateCache: function(envelope, plaintext) {
|
updateCache: function(envelope, plaintext) {
|
||||||
var id = this.getEnvelopeId(envelope);
|
var id = this.getEnvelopeId(envelope);
|
||||||
console.log('updateCache', id);
|
console.log('updateCache', id);
|
||||||
var string = this.arrayBufferToString(plaintext);
|
|
||||||
var data = {
|
var data = {
|
||||||
decrypted: string
|
decrypted: plaintext
|
||||||
};
|
};
|
||||||
return textsecure.storage.unprocessed.update(id, data);
|
return textsecure.storage.unprocessed.update(id, data);
|
||||||
},
|
},
|
||||||
|
|
|
@ -167,12 +167,21 @@ MessageReceiver.prototype.extend({
|
||||||
},
|
},
|
||||||
queueCached: function(item) {
|
queueCached: function(item) {
|
||||||
try {
|
try {
|
||||||
var envelopePlaintext = this.stringToArrayBuffer(item.envelope);
|
var envelopePlaintext = item.envelope;
|
||||||
|
|
||||||
|
// Up until 0.42.6 we stored envelope and decrypted as strings in IndexedDB,
|
||||||
|
// so we need to be ready for them.
|
||||||
|
if (typeof envelopePlaintext === 'string') {
|
||||||
|
envelopePlaintext = this.stringToArrayBuffer(envelopePlaintext);
|
||||||
|
}
|
||||||
var envelope = textsecure.protobuf.Envelope.decode(envelopePlaintext);
|
var envelope = textsecure.protobuf.Envelope.decode(envelopePlaintext);
|
||||||
|
|
||||||
var decrypted = item.decrypted;
|
var decrypted = item.decrypted;
|
||||||
if (decrypted) {
|
if (decrypted) {
|
||||||
var payloadPlaintext = this.stringToArrayBuffer(decrypted);
|
var payloadPlaintext = decrypted;
|
||||||
|
if (typeof payloadPlaintext === 'string') {
|
||||||
|
payloadPlaintext = this.stringToArrayBuffer(payloadPlaintext);
|
||||||
|
}
|
||||||
this.queueDecryptedEnvelope(envelope, payloadPlaintext);
|
this.queueDecryptedEnvelope(envelope, payloadPlaintext);
|
||||||
} else {
|
} else {
|
||||||
this.queueEnvelope(envelope);
|
this.queueEnvelope(envelope);
|
||||||
|
@ -185,9 +194,6 @@ MessageReceiver.prototype.extend({
|
||||||
getEnvelopeId: function(envelope) {
|
getEnvelopeId: function(envelope) {
|
||||||
return envelope.source + '.' + envelope.sourceDevice + ' ' + envelope.timestamp.toNumber();
|
return envelope.source + '.' + envelope.sourceDevice + ' ' + envelope.timestamp.toNumber();
|
||||||
},
|
},
|
||||||
arrayBufferToString: function(arrayBuffer) {
|
|
||||||
return new dcodeIO.ByteBuffer.wrap(arrayBuffer).toString('binary');
|
|
||||||
},
|
|
||||||
stringToArrayBuffer: function(string) {
|
stringToArrayBuffer: function(string) {
|
||||||
return new dcodeIO.ByteBuffer.wrap(string, 'binary').toArrayBuffer();
|
return new dcodeIO.ByteBuffer.wrap(string, 'binary').toArrayBuffer();
|
||||||
},
|
},
|
||||||
|
@ -218,10 +224,9 @@ MessageReceiver.prototype.extend({
|
||||||
addToCache: function(envelope, plaintext) {
|
addToCache: function(envelope, plaintext) {
|
||||||
var id = this.getEnvelopeId(envelope);
|
var id = this.getEnvelopeId(envelope);
|
||||||
console.log('addToCache', id);
|
console.log('addToCache', id);
|
||||||
var string = this.arrayBufferToString(plaintext);
|
|
||||||
var data = {
|
var data = {
|
||||||
id: id,
|
id: id,
|
||||||
envelope: string,
|
envelope: plaintext,
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
attempts: 1
|
attempts: 1
|
||||||
};
|
};
|
||||||
|
@ -230,9 +235,8 @@ MessageReceiver.prototype.extend({
|
||||||
updateCache: function(envelope, plaintext) {
|
updateCache: function(envelope, plaintext) {
|
||||||
var id = this.getEnvelopeId(envelope);
|
var id = this.getEnvelopeId(envelope);
|
||||||
console.log('updateCache', id);
|
console.log('updateCache', id);
|
||||||
var string = this.arrayBufferToString(plaintext);
|
|
||||||
var data = {
|
var data = {
|
||||||
decrypted: string
|
decrypted: plaintext
|
||||||
};
|
};
|
||||||
return textsecure.storage.unprocessed.update(id, data);
|
return textsecure.storage.unprocessed.update(id, data);
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue