From 9129f256fab8e1a29ef53d587dd3dc4ce8d1bc7e Mon Sep 17 00:00:00 2001 From: Diadlo Date: Mon, 24 Dec 2018 21:36:51 +0300 Subject: [PATCH] refactor: Rewrite widget exists check --- src/widget/contentdialog.cpp | 10 ++++++++++ src/widget/contentdialog.h | 3 +++ src/widget/contentdialogmanager.cpp | 14 ++++++++++++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/widget/contentdialog.cpp b/src/widget/contentdialog.cpp index 6d5b8bf93..ad793418b 100644 --- a/src/widget/contentdialog.cpp +++ b/src/widget/contentdialog.cpp @@ -611,6 +611,16 @@ void ContentDialog::activate(GenericChatroomWidget* widget) updateTitleAndStatusIcon(); } +bool ContentDialog::containsFriend(int friendId) const +{ + return friendWidgets.contains(friendId); +} + +bool ContentDialog::containsGroup(int groupId) const +{ + return groupWidgets.contains(groupId); +} + /** * @brief Update friend widget name and position. * @param friendId Friend Id. diff --git a/src/widget/contentdialog.h b/src/widget/contentdialog.h index 2ab91f3f9..16aaec3fe 100644 --- a/src/widget/contentdialog.h +++ b/src/widget/contentdialog.h @@ -77,6 +77,9 @@ public: void focusFriend(int friendId); void focusGroup(int groupId); + bool containsFriend(int friendId) const; + bool containsGroup(int groupId) const; + signals: void friendDialogShown(const Friend* f); void groupDialogShown(Group* g); diff --git a/src/widget/contentdialogmanager.cpp b/src/widget/contentdialogmanager.cpp index 02d0bb1a7..b50fd4698 100644 --- a/src/widget/contentdialogmanager.cpp +++ b/src/widget/contentdialogmanager.cpp @@ -43,12 +43,22 @@ ContentDialog* ContentDialogManager::current() bool ContentDialogManager::friendWidgetExists(int friendId) { - return existsWidget(friendId, friendList); + const auto dialog = friendDialogs.value(friendId, nullptr); + if (dialog == nullptr) { + return false; + } + + return dialog->containsFriend(friendId); } bool ContentDialogManager::groupWidgetExists(int groupId) { - return existsWidget(groupId, groupList); + const auto dialog = groupDialogs.value(groupId, nullptr); + if (dialog == nullptr) { + return false; + } + + return dialog->containsGroup(groupId); } FriendWidget* ContentDialogManager::addFriendToDialog(ContentDialog* dialog,