diff --git a/cockatrice/src/interface/widgets/tabs/tab_message.cpp b/cockatrice/src/interface/widgets/tabs/tab_message.cpp index 76bf1c5ca..d482d3dd7 100644 --- a/cockatrice/src/interface/widgets/tabs/tab_message.cpp +++ b/cockatrice/src/interface/widgets/tabs/tab_message.cpp @@ -123,13 +123,9 @@ void TabMessage::sendMessage() sayEdit->clear(); } -void TabMessage::sendInviteMessage(const QString &text) +bool TabMessage::isUserOnline() const { - if (!userOnline) { - notifyUserOffline(); - return; - } - sendPrivateMessage(text); + return userOnline; } void TabMessage::messageSent(const Response &response, diff --git a/cockatrice/src/interface/widgets/tabs/tab_message.h b/cockatrice/src/interface/widgets/tabs/tab_message.h index 9ab685ab8..e9b987ce2 100644 --- a/cockatrice/src/interface/widgets/tabs/tab_message.h +++ b/cockatrice/src/interface/widgets/tabs/tab_message.h @@ -64,10 +64,10 @@ public: void processUserLeft(); void processUserJoined(const ServerInfo_User &_userInfo); - void sendInviteMessage(const QString &text); + [[nodiscard]] bool isUserOnline() const; + void sendPrivateMessage(const QString &text); private: - void sendPrivateMessage(const QString &text); bool shouldShowSystemPopup(const Event_UserMessage &event); void showSystemPopup(const Event_UserMessage &event); void notifyUserOffline(); diff --git a/cockatrice/src/interface/widgets/tabs/tab_room.cpp b/cockatrice/src/interface/widgets/tabs/tab_room.cpp index 398732cd6..6245b5301 100644 --- a/cockatrice/src/interface/widgets/tabs/tab_room.cpp +++ b/cockatrice/src/interface/widgets/tabs/tab_room.cpp @@ -68,9 +68,7 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor, userList = userListPanel->getUserList(); connect(userListPanel, &UserListPanelWidget::openMessageDialog, this, &TabRoom::openMessageDialog); - const std::function()> gameInviteLinkProvider = [this]() -> QList { - return tabSupervisor->getGameInviteLinksForRoom(roomId); - }; + const auto gameInviteLinkProvider = [this]() { return tabSupervisor->getGameInviteLinksForRoom(roomId); }; userList->setGameInviteLinkProvider(gameInviteLinkProvider); chatView = new ChatView(tabSupervisor, nullptr, true, this); diff --git a/cockatrice/src/interface/widgets/tabs/tab_supervisor.cpp b/cockatrice/src/interface/widgets/tabs/tab_supervisor.cpp index 01cf9fe4d..77b93802a 100644 --- a/cockatrice/src/interface/widgets/tabs/tab_supervisor.cpp +++ b/cockatrice/src/interface/widgets/tabs/tab_supervisor.cpp @@ -961,9 +961,7 @@ QList TabSupervisor::getGameInviteLinksForRoom(int roomId) con // The inviter may be in several games of the same room (hosting one and // spectating another, for example). Return every game so the caller can // let the user choose which one to invite to. - QMapIterator gameIterator(gameTabs); - while (gameIterator.hasNext()) { - TabGame *tab = gameIterator.next().value(); + for (TabGame *tab : gameTabs) { GameMetaInfo *metaInfo = tab->getGame()->getGameMetaInfo(); if (metaInfo->proto().room_id() != roomId) { continue; @@ -977,14 +975,15 @@ QList TabSupervisor::getGameInviteLinksForRoom(int roomId) con const int gameId = metaInfo->gameId(); const QString description = QString::fromStdString(metaInfo->proto().description()); - GameInviteOption option; - option.gameId = gameId; - option.label = - description.isEmpty() ? tr("Game #%1").arg(gameId) : tr("Game #%1 — %2").arg(gameId).arg(description); - option.url = makeGameJoinLink(client->serverName(), client->serverPort(), roomId, gameId, description); - option.description = description; - option.onlyBuddies = metaInfo->proto().only_buddies(); - option.creatorName = QString::fromStdString(metaInfo->proto().creator_info().name()); + GameInviteOption option{ + .gameId = gameId, + .label = + description.isEmpty() ? tr("Game #%1").arg(gameId) : tr("Game #%1 — %2").arg(gameId).arg(description), + .url = makeGameJoinLink(client->serverName(), client->serverPort(), roomId, gameId, description), + .description = description, + .onlyBuddies = metaInfo->proto().only_buddies(), + .creatorName = QString::fromStdString(metaInfo->proto().creator_info().name()), + }; options.append(option); } @@ -994,8 +993,8 @@ QList TabSupervisor::getGameInviteLinksForRoom(int roomId) con void TabSupervisor::sendInviteToUser(const QString &userName, const QString &inviteText) { TabMessage *tab = addMessageTab(userName, true); - if (tab) { - tab->sendInviteMessage(inviteText); + if (tab && tab->isUserOnline()) { + tab->sendPrivateMessage(inviteText); } }