diff --git a/cockatrice/src/interface/widgets/tabs/visual_deck_storage/tab_deck_storage_visual.cpp b/cockatrice/src/interface/widgets/tabs/visual_deck_storage/tab_deck_storage_visual.cpp index 5ea0fa89a..d42740cb0 100644 --- a/cockatrice/src/interface/widgets/tabs/visual_deck_storage/tab_deck_storage_visual.cpp +++ b/cockatrice/src/interface/widgets/tabs/visual_deck_storage/tab_deck_storage_visual.cpp @@ -103,6 +103,10 @@ void TabDeckStorageVisual::enterShareMode(const QStringList &preselectFiles) void TabDeckStorageVisual::exitShareMode() { + // Abandon any in-flight request: otherwise the timer keeps running and a late + // response reports the share as created after the user already backed out. + shareTimeoutTimer->stop(); + shareInFlightSeq = 0; visualDeckStorageWidget->setShareSelectable(false); visualDeckStorageWidget->clearShareSelection(); shareBar->setVisible(false); @@ -165,8 +169,17 @@ void TabDeckStorageVisual::actShareSelected() } shareBar->setCreateEnabled(false); + const int seq = ++shareRequestSeq; + shareInFlightSeq = seq; PendingCommand *pend = client->prepareSessionCommand(cmd); - connect(pend, &PendingCommand::finished, this, &TabDeckStorageVisual::shareFinished); + connect(pend, &PendingCommand::finished, this, + [this, seq](const Response &response, const CommandContainer &commandContainer) { + if (shareInFlightSeq != seq) { + return; // the user cancelled or a newer request superseded this one + } + shareInFlightSeq = 0; + shareFinished(response, commandContainer); + }); client->sendCommand(pend); shareTimeoutTimer->start(); } @@ -207,6 +220,10 @@ void TabDeckStorageVisual::showShareNotice(const QString &message, bool warning) void TabDeckStorageVisual::onShareTimeout() { + if (shareInFlightSeq == 0) { + return; // share mode was left while the request was still outstanding + } + shareInFlightSeq = 0; shareBar->setCreateEnabled(true); showShareNotice(tr("The server did not respond in time. Try again."), true); } diff --git a/cockatrice/src/interface/widgets/tabs/visual_deck_storage/tab_deck_storage_visual.h b/cockatrice/src/interface/widgets/tabs/visual_deck_storage/tab_deck_storage_visual.h index 549f7bf07..1878ae9e8 100644 --- a/cockatrice/src/interface/widgets/tabs/visual_deck_storage/tab_deck_storage_visual.h +++ b/cockatrice/src/interface/widgets/tabs/visual_deck_storage/tab_deck_storage_visual.h @@ -77,6 +77,8 @@ private: ShareBarWidget *shareBar; AbstractClient *client; QTimer *shareTimeoutTimer; + int shareRequestSeq = 0; + int shareInFlightSeq = 0; bool shareDeckAvailable = false; };