From f3b8dbe01a43c5334a371edda833173468d99dc4 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Wed, 10 Jun 2020 08:31:43 +0200 Subject: Room: fix messageSent() being emitted too early Closes #406. --- lib/room.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'lib/room.cpp') diff --git a/lib/room.cpp b/lib/room.cpp index 23e07cae..22ec1c82 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -1565,18 +1565,17 @@ QString Room::Private::doSendEvent(const RoomEvent* pEvent) std::bind(&Room::Private::onEventSendingFailure, this, txnId, call)); Room::connect(call, &BaseJob::success, q, [this, call, txnId] { - emit q->messageSent(txnId, call->eventId()); auto it = q->findPendingEvent(txnId); - if (it == unsyncedEvents.end()) { + if (it != unsyncedEvents.end()) { + if (it->deliveryStatus() != EventStatus::ReachedServer) { + it->setReachedServer(call->eventId()); + emit q->pendingEventChanged(int(it - unsyncedEvents.begin())); + } + } else qCDebug(EVENTS) << "Pending event for transaction" << txnId << "already merged"; - return; - } - if (it->deliveryStatus() != EventStatus::ReachedServer) { - it->setReachedServer(call->eventId()); - emit q->pendingEventChanged(int(it - unsyncedEvents.begin())); - } + emit q->messageSent(txnId, call->eventId()); }); } else onEventSendingFailure(txnId); -- cgit v1.2.3