diff --git a/cockatrice/src/chatview/userlistProxy.h b/cockatrice/src/chatview/userlistProxy.h index 7f917136..14411982 100644 --- a/cockatrice/src/chatview/userlistProxy.h +++ b/cockatrice/src/chatview/userlistProxy.h @@ -9,8 +9,10 @@ class ServerInfo_User; */ class UserlistProxy { public: + virtual const bool isOwnUserRegistered() const = 0; virtual const QString getOwnUsername() const = 0; virtual bool isUserBuddy(const QString &userName) const = 0; + virtual bool isUserIgnored(const QString &userName) const = 0; virtual const ServerInfo_User* getOnlineUser(const QString &userName) const = 0; // Can return nullptr }; diff --git a/cockatrice/src/gameselector.cpp b/cockatrice/src/gameselector.cpp index b5f8ffc2..c73b224a 100644 --- a/cockatrice/src/gameselector.cpp +++ b/cockatrice/src/gameselector.cpp @@ -25,8 +25,7 @@ GameSelector::GameSelector(AbstractClient *_client, const TabSupervisor *_tabSup gameListModel = new GamesModel(_rooms, _gameTypes, this); if(showfilters) { - bool ownUserIsRegistered = (bool)(tabSupervisor->getUserInfo()->user_level() & ServerInfo_User::IsRegistered); - gameListProxyModel = new GamesProxyModel(this, ownUserIsRegistered); + gameListProxyModel = new GamesProxyModel(this, tabSupervisor->isOwnUserRegistered()); gameListProxyModel->setSourceModel(gameListModel); gameListProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); gameListView->setModel(gameListProxyModel); diff --git a/cockatrice/src/tab_supervisor.cpp b/cockatrice/src/tab_supervisor.cpp index ab49e3ba..63dc432e 100644 --- a/cockatrice/src/tab_supervisor.cpp +++ b/cockatrice/src/tab_supervisor.cpp @@ -605,6 +605,12 @@ void TabSupervisor::processNotifyUserEvent(const Event_NotifyUser &event) } } + +const bool TabSupervisor::isOwnUserRegistered() const +{ + return (bool) getUserInfo()->user_level() & ServerInfo_User::IsRegistered; +} + const QString TabSupervisor::getOwnUsername() const { return QString::fromStdString(userInfo->name()); @@ -619,6 +625,15 @@ bool TabSupervisor::isUserBuddy(const QString &userName) const return senderIsBuddy; } +bool TabSupervisor::isUserIgnored(const QString &userName) const +{ + if (!getUserListsTab()) return false; + if (!getUserListsTab()->getIgnoreList()) return false; + QMap buddyList = getUserListsTab()->getIgnoreList()->getUsers(); + bool senderIsBuddy = buddyList.contains(userName); + return senderIsBuddy; +} + const ServerInfo_User * TabSupervisor::getOnlineUser(const QString &userName) const { if (!getUserListsTab()) return nullptr; diff --git a/cockatrice/src/tab_supervisor.h b/cockatrice/src/tab_supervisor.h index 7f80aba9..cadc826c 100644 --- a/cockatrice/src/tab_supervisor.h +++ b/cockatrice/src/tab_supervisor.h @@ -79,8 +79,10 @@ public: const QMap &getRoomTabs() const { return roomTabs; } bool getAdminLocked() const; bool closeRequest(); + const bool isOwnUserRegistered() const; const QString getOwnUsername() const; bool isUserBuddy(const QString &userName) const; + bool isUserIgnored(const QString &userName) const; const ServerInfo_User* getOnlineUser(const QString &userName) const; signals: void setMenu(const QList &newMenuList = QList()); diff --git a/cockatrice/src/user_context_menu.cpp b/cockatrice/src/user_context_menu.cpp index aed3e59a..d839a551 100644 --- a/cockatrice/src/user_context_menu.cpp +++ b/cockatrice/src/user_context_menu.cpp @@ -245,7 +245,7 @@ void UserContextMenu::warnUser_dialogFinished() { WarningDialog *dlg = static_cast(sender()); - if (dlg->getName().isEmpty() || QString::fromStdString(tabSupervisor->getUserInfo()->name()).simplified().isEmpty()) + if (dlg->getName().isEmpty() || tabSupervisor->getOwnUsername().simplified().isEmpty()) return; Command_WarnUser cmd; @@ -267,13 +267,13 @@ void UserContextMenu::showContextMenu(const QPoint &pos, const QString &userName menu->addAction(aDetails); menu->addAction(aShowGames); menu->addAction(aChat); - if (userLevel.testFlag(ServerInfo_User::IsRegistered) && (tabSupervisor->getUserInfo()->user_level() & ServerInfo_User::IsRegistered)) { + if (userLevel.testFlag(ServerInfo_User::IsRegistered) && tabSupervisor->isOwnUserRegistered()) { menu->addSeparator(); - if (tabSupervisor->getUserListsTab()->getBuddyList()->getUsers().contains(userName)) + if (tabSupervisor->isUserBuddy(userName)) menu->addAction(aRemoveFromBuddyList); else menu->addAction(aAddToBuddyList); - if (tabSupervisor->getUserListsTab()->getIgnoreList()->getUsers().contains(userName)) + if (tabSupervisor->isUserIgnored(userName)) menu->addAction(aRemoveFromIgnoreList); else menu->addAction(aAddToIgnoreList); @@ -298,7 +298,7 @@ void UserContextMenu::showContextMenu(const QPoint &pos, const QString &userName menu->addAction(aPromoteToMod); } } - bool anotherUser = userName != QString::fromStdString(tabSupervisor->getUserInfo()->name()); + bool anotherUser = userName != tabSupervisor->getOwnUsername(); aDetails->setEnabled(true); aChat->setEnabled(anotherUser && online); aShowGames->setEnabled(online);