diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2019-08-03 18:03:47 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2019-08-03 18:03:47 +0900 |
commit | b9833c1ad21e1a57ff5d33ad94cb3b865159d06a (patch) | |
tree | 56efb8bbeee48f6737582b36d7ba06e8433fa6c8 /lib | |
parent | 66e116b7b1e848e80577a0229c8995db0a54932e (diff) | |
parent | 2681303c2aed1bf20e385c41f1382f5aade66e35 (diff) | |
download | libquotient-b9833c1ad21e1a57ff5d33ad94cb3b865159d06a.tar.gz libquotient-b9833c1ad21e1a57ff5d33ad94cb3b865159d06a.zip |
Merge branch 'kitsune-update-fake-state-test'
Diffstat (limited to 'lib')
-rw-r--r-- | lib/room.cpp | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/lib/room.cpp b/lib/room.cpp index b32d3492..52f86616 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -1469,8 +1469,10 @@ QString Room::Private::doSendEvent(const RoomEvent* pEvent) return; } - it->setReachedServer(call->eventId()); - emit q->pendingEventChanged(int(it - unsyncedEvents.begin())); + if (it->deliveryStatus() != EventStatus::ReachedServer) { + it->setReachedServer(call->eventId()); + emit q->pendingEventChanged(int(it - unsyncedEvents.begin())); + } }); } else onEventSendingFailure(txnId); @@ -1520,6 +1522,7 @@ QString Room::retryMessage(const QString& txnId) " events are likely to be in the timeline after retry"; } it->resetStatus(); + emit pendingEventChanged(int(it - d->unsyncedEvents.begin())); return d->doSendEvent(it->event()); } @@ -2170,10 +2173,11 @@ Room::Changes Room::Private::addNewMessageEvents(RoomEvents&& events) auto nextPendingPair = findFirstOf(it, events.end(), unsyncedEvents.begin(), unsyncedEvents.end(), isEchoEvent); - auto nextPending = nextPendingPair.first; + const auto& remoteEcho = nextPendingPair.first; + const auto& localEcho = nextPendingPair.second; - if (it != nextPending) { - RoomEventsRange eventsSpan { it, nextPending }; + if (it != remoteEcho) { + RoomEventsRange eventsSpan { it, remoteEcho }; emit q->aboutToAddNewMessages(eventsSpan); auto insertedSize = moveEventsToTimeline(eventsSpan, Newer); totalInserted += insertedSize; @@ -2182,13 +2186,16 @@ Room::Changes Room::Private::addNewMessageEvents(RoomEvents&& events) emit q->addedMessages(firstInserted->index(), timeline.back().index()); } - if (nextPending == events.end()) + if (remoteEcho == events.end()) break; - it = nextPending + 1; - auto* nextPendingEvt = nextPending->get(); - const auto pendingEvtIdx = - int(nextPendingPair.second - unsyncedEvents.begin()); + it = remoteEcho + 1; + auto* nextPendingEvt = remoteEcho->get(); + const auto pendingEvtIdx = int(localEcho - unsyncedEvents.begin()); + if (localEcho->deliveryStatus() != EventStatus::ReachedServer) { + localEcho->setReachedServer(nextPendingEvt->id()); + emit q->pendingEventChanged(pendingEvtIdx); + } emit q->pendingEventAboutToMerge(nextPendingEvt, pendingEvtIdx); qDebug(EVENTS) << "Merging pending event from transaction" << nextPendingEvt->transactionId() << "into" @@ -2197,13 +2204,12 @@ Room::Changes Room::Private::addNewMessageEvents(RoomEvents&& events) if (transfer.status != FileTransferInfo::None) fileTransfers.insert(nextPendingEvt->id(), transfer); // After emitting pendingEventAboutToMerge() above we cannot rely - // on the previously obtained nextPendingPair.second staying valid + // on the previously obtained localEcho staying valid // because a signal handler may send another message, thereby altering // unsyncedEvents (see #286). Fortunately, unsyncedEvents only grows at // its back so we can rely on the index staying valid at least. unsyncedEvents.erase(unsyncedEvents.begin() + pendingEvtIdx); - if (auto insertedSize = moveEventsToTimeline({ nextPending, it }, - Newer)) { + if (auto insertedSize = moveEventsToTimeline({ remoteEcho, it }, Newer)) { totalInserted += insertedSize; q->onAddNewTimelineEvents(timeline.cend() - insertedSize); } |