mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-22 19:14:52 +01:00
No need for event-emitter here
This commit is contained in:
parent
9a2a482096
commit
f36c996a86
@ -13,9 +13,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import {EventEmitter} from "../../../utils/EventEmitter";
|
||||
import {createEnum} from "../../../utils/enum";
|
||||
import {AbortError} from "../../../utils/error";
|
||||
import {Deferred} from "../../../utils/Deferred";
|
||||
import {REDACTION_TYPE} from "../common";
|
||||
import {getRelationFromContent, getRelationTarget, setRelationTarget} from "../timeline/relations.js";
|
||||
|
||||
@ -31,9 +31,8 @@ export const SendStatus = createEnum(
|
||||
|
||||
const unencryptedContentFields = [ "m.relates_to" ];
|
||||
|
||||
export class PendingEvent extends EventEmitter {
|
||||
export class PendingEvent {
|
||||
constructor({data, remove, emitUpdate, attachments}) {
|
||||
super();
|
||||
this._data = data;
|
||||
this._attachments = attachments;
|
||||
this._emitUpdate = emitUpdate;
|
||||
@ -42,6 +41,7 @@ export class PendingEvent extends EventEmitter {
|
||||
this._status = SendStatus.Waiting;
|
||||
this._sendRequest = null;
|
||||
this._attachmentsTotalBytes = 0;
|
||||
this._deferred = new Deferred()
|
||||
if (this._attachments) {
|
||||
this._attachmentsTotalBytes = Object.values(this._attachments).reduce((t, a) => t + a.size, 0);
|
||||
}
|
||||
@ -230,12 +230,16 @@ export class PendingEvent extends EventEmitter {
|
||||
this._sendRequest = null;
|
||||
// both /send and /redact have the same response format
|
||||
this._data.remoteId = response.event_id;
|
||||
this.emit("remote-id", this.remoteId);
|
||||
this._deferred.resolve(response.event_id);
|
||||
log.set("id", this._data.remoteId);
|
||||
this._status = SendStatus.Sent;
|
||||
this._emitUpdate("status");
|
||||
}
|
||||
|
||||
getRemoteId() {
|
||||
return this._deferred.promise;
|
||||
}
|
||||
|
||||
dispose() {
|
||||
if (this._attachments) {
|
||||
for (const attachment of Object.values(this._attachments)) {
|
||||
|
@ -126,7 +126,7 @@ export class RoomChannel extends Disposables implements IChannel {
|
||||
to: this.otherUserId,
|
||||
});
|
||||
const pendingEvent = await this.room.sendEvent("m.room.message", content, undefined, log);
|
||||
this.track(pendingEvent.disposableOn("remote-id", (id: string) => { this.id = id; }));
|
||||
this.id = await pendingEvent.getRemoteId();
|
||||
this.sentMessages.set(eventType, {content});
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user