wait for attachment to be uploaded in send queue

also expose attachment from PendingEvent(Entry)
This commit is contained in:
Bruno Windels 2020-11-11 11:51:39 +01:00
parent 48cd4ac95d
commit af4f3f902f
3 changed files with 15 additions and 5 deletions

View file

@ -15,8 +15,9 @@ limitations under the License.
*/ */
export class PendingEvent { export class PendingEvent {
constructor(data) { constructor(data, attachment) {
this._data = data; this._data = data;
this.attachment = attachment;
} }
get roomId() { return this._data.roomId; } get roomId() { return this._data.roomId; }

View file

@ -51,6 +51,11 @@ export class SendQueue {
this._amountSent += 1; this._amountSent += 1;
continue; continue;
} }
if (pendingEvent.attachment) {
const {attachment} = pendingEvent;
await attachment.uploaded();
attachment.applyToContent(pendingEvent.content);
}
if (pendingEvent.needsEncryption) { if (pendingEvent.needsEncryption) {
const {type, content} = await this._roomEncryption.encrypt( const {type, content} = await this._roomEncryption.encrypt(
pendingEvent.eventType, pendingEvent.content, this._hsApi); pendingEvent.eventType, pendingEvent.content, this._hsApi);
@ -116,8 +121,8 @@ export class SendQueue {
} }
} }
async enqueueEvent(eventType, content) { async enqueueEvent(eventType, content, attachment) {
const pendingEvent = await this._createAndStoreEvent(eventType, content); const pendingEvent = await this._createAndStoreEvent(eventType, content, attachment);
this._pendingEvents.set(pendingEvent); this._pendingEvents.set(pendingEvent);
console.log("added to _pendingEvents set", this._pendingEvents.length); console.log("added to _pendingEvents set", this._pendingEvents.length);
if (!this._isSending && !this._offline) { if (!this._isSending && !this._offline) {
@ -150,7 +155,7 @@ export class SendQueue {
await txn.complete(); await txn.complete();
} }
async _createAndStoreEvent(eventType, content) { async _createAndStoreEvent(eventType, content, attachment) {
console.log("_createAndStoreEvent"); console.log("_createAndStoreEvent");
const txn = this._storage.readWriteTxn([this._storage.storeNames.pendingEvents]); const txn = this._storage.readWriteTxn([this._storage.storeNames.pendingEvents]);
let pendingEvent; let pendingEvent;
@ -167,7 +172,7 @@ export class SendQueue {
content, content,
txnId: makeTxnId(), txnId: makeTxnId(),
needsEncryption: !!this._roomEncryption needsEncryption: !!this._roomEncryption
}); }, attachment);
console.log("_createAndStoreEvent: adding to pendingEventsStore"); console.log("_createAndStoreEvent: adding to pendingEventsStore");
pendingEventsStore.add(pendingEvent.data); pendingEventsStore.add(pendingEvent.data);
} catch (err) { } catch (err) {

View file

@ -64,6 +64,10 @@ export class PendingEventEntry extends BaseEntry {
return this._pendingEvent.txnId; return this._pendingEvent.txnId;
} }
get attachment() {
return this._pendingEvent.attachment;
}
notifyUpdate() { notifyUpdate() {
} }