Cockatrice/cockatrice/src/interface/widgets/tabs/tab_server.h
BruebachL 9acb9739b2
[Client] Fix spurious server room join error (#7259)
* [Client] Fix spurious server room join error

The server replies RespContextError when a join command is received for a
room that connection is already registered in. The client was sending such
duplicate joins in benign situations - double-clicking to join a room, or
clicking a room the selector was already auto-joining - and answered them
with a modal telling users to restart the client.

Joins for the same room are now deduplicated while one is in flight, and a
remaining RespContextError is healed by leaving and rejoining the room so
the tab appears without a client restart. Error dialogs are only shown for
user-initiated joins, so failed auto-joins no longer spam critical popups.

* [Client] Bound stale-membership room join heal to one attempt

The RespContextError heal (leave + rejoin) previously recurred
unconditionally, so a server that kept returning RespContextError for a
reason other than stale membership would loop forever. Track room ids
that already received a heal and surface the error dialog after one
attempt instead of retrying indefinitely.

* [Client] Scope room-join heal guard to one join attempt

* [Client] Hoist room-join heal guard lookup out of response switch

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
2026-09-19 09:56:09 +02:00

85 lines
2.2 KiB
C++

/**
* @file tab_server.h
* @ingroup ServerTabs
*/
//! \todo Document this file.
#ifndef TAB_SERVER_H
#define TAB_SERVER_H
#include "tab.h"
#include <QGroupBox>
#include <QHash>
#include <QSet>
#include <QTextBrowser>
#include <QTreeWidget>
class AbstractClient;
class QTextEdit;
class QLabel;
class UserListWidget;
class QPushButton;
class Event_ListRooms;
class Event_ServerMessage;
class Response;
class ServerInfo_Room;
class CommandContainer;
class RoomSelector : public QGroupBox
{
Q_OBJECT
private:
QTreeWidget *roomList;
QPushButton *joinButton;
AbstractClient *client;
QString getRoomPermissionDisplay(const ServerInfo_Room &room);
private slots:
void processListRoomsEvent(const Event_ListRooms &event);
void joinClicked();
signals:
void joinRoomRequest(int, bool setCurrent);
public:
explicit RoomSelector(AbstractClient *_client, QWidget *parent = nullptr);
void retranslateUi();
};
class TabServer : public Tab
{
Q_OBJECT
signals:
void roomJoined(const ServerInfo_Room &info, bool setCurrent);
void roomJoinFailed(int roomId);
private slots:
void processServerMessageEvent(const Event_ServerMessage &event);
void joinRoomFinished(const Response &resp,
const CommandContainer &commandContainer,
const QVariant &extraData,
int roomId);
private:
void leaveAndRejoinRoom(int roomId, bool setCurrent);
AbstractClient *client;
RoomSelector *roomSelector;
QTextBrowser *serverInfoBox;
bool shouldEmitUpdate = false;
/** Room ids with a join command in flight, mapped to whether the tab should be focused once it opens. */
QHash<int, bool> pendingRoomJoins;
/** Room ids for which a stale-membership heal (leave + rejoin) is currently in flight. Released as soon as the
* rejoin has been answered, so a heal is attempted at most once per join. */
QSet<int> healedRoomJoins;
public:
TabServer(TabSupervisor *_tabSupervisor, AbstractClient *_client);
void joinRoom(int id, bool setCurrent);
void retranslateUi() override;
[[nodiscard]] QString getTabText() const override
{
return tr("Server");
}
};
#endif