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 {
constructor(data) {
constructor(data, attachment) {
this._data = data;
this.attachment = attachment;
}
get roomId() { return this._data.roomId; }

View File

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

View File

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