diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index ee39a70e4..0d7eb5eee 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -23,6 +23,8 @@ #include "NewsFeed.h" #include "ui_NewsFeed.h" +#include "pqi/authssl.h" + #include #include #include @@ -478,6 +480,13 @@ void NewsFeed::handleSecurityEvent(std::shared_ptr event) return; auto& e(*pe); + + // Check if denied by AuthSSL (backend) + if(AuthSSL::instance().isNotifyDenied(e.mPgpId)) + { + return; + } + RsFeedTypeFlags flags = (RsFeedTypeFlags)Settings->getNewsFeedFlags(); // 1 - treat the case of unknown PeerID diff --git a/retroshare-gui/src/gui/feeds/SecurityItem.cpp b/retroshare-gui/src/gui/feeds/SecurityItem.cpp index 6d6023d81..d6e3aebaf 100644 --- a/retroshare-gui/src/gui/feeds/SecurityItem.cpp +++ b/retroshare-gui/src/gui/feeds/SecurityItem.cpp @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include "SecurityItem.h" #include "FeedHolder.h" @@ -37,6 +39,7 @@ #include #include +#include "pqi/authssl.h" /***** * #define DEBUG_ITEM 1 @@ -54,6 +57,12 @@ SecurityItem::SecurityItem(FeedHolder *parent, uint32_t feedId, const RsPgpId &g chatButton->hide(); removeFriendButton->setEnabled(false); removeFriendButton->hide(); + banButton->hide(); + + QPalette pal = banButton->palette(); + pal.setColor(QPalette::ButtonText, Qt::red); + banButton->setPalette(pal); + peerDetailsButton->setEnabled(false); friendRequesttoolButton->hide(); requestLabel->hide(); @@ -68,6 +77,7 @@ SecurityItem::SecurityItem(FeedHolder *parent, uint32_t feedId, const RsPgpId &g //connect( quickmsgButton, SIGNAL( clicked( ) ), this, SLOT( sendMsg() ) ); connect( removeFriendButton, SIGNAL(clicked()), this, SLOT(removeFriend())); + connect( banButton, SIGNAL(clicked()), this, SLOT(banUser())); connect( peerDetailsButton, SIGNAL(clicked()), this, SLOT(peerDetails())); connect( friendRequesttoolButton, SIGNAL(clicked()), this, SLOT(friendRequest())); @@ -241,6 +251,7 @@ void SecurityItem::updateItem() removeFriendButton->setEnabled(false); removeFriendButton->hide(); + banButton->show(); peerDetailsButton->setEnabled(false); if(mType == RsFeedTypeFlags::RS_FEED_ITEM_SEC_BAD_CERTIFICATE) @@ -311,6 +322,7 @@ void SecurityItem::updateItem() requestLabel->hide(); removeFriendButton->setEnabled(true); removeFriendButton->show(); + banButton->hide(); } else { @@ -327,6 +339,7 @@ void SecurityItem::updateItem() } removeFriendButton->setEnabled(false); removeFriendButton->hide(); + banButton->show(); } //quickmsgButton->show(); @@ -380,6 +393,21 @@ void SecurityItem::removeFriend() rsPeers->removeFriend(mGpgId); } } + +void SecurityItem::banUser() +{ + // Confirmation dialog + QMessageBox::StandardButton reply; + reply = QMessageBox::question(this, tr("Ignore User"), tr("Are you sure you want to ignore this user? They will be added to the Ignored Users list and you will not receive further notifications from them. You can manage the list in Preferences -> Notify."), + QMessageBox::Yes|QMessageBox::No); + if (reply == QMessageBox::Yes) { + AuthSSL::instance().addNotifyDeny(mGpgId, mSslCn); + rsPeers->removeFriend(mGpgId); + // Remove this item from the feed as it is now handled + removeItem(); + } +} + void SecurityItem::friendRequest() { #ifdef DEBUG_ITEM diff --git a/retroshare-gui/src/gui/feeds/SecurityItem.h b/retroshare-gui/src/gui/feeds/SecurityItem.h index e2ba2b394..e01d60975 100644 --- a/retroshare-gui/src/gui/feeds/SecurityItem.h +++ b/retroshare-gui/src/gui/feeds/SecurityItem.h @@ -55,6 +55,7 @@ private slots: void friendRequest(); void removeFriend(); + void banUser(); void peerDetails(); void sendMsg(); void openChat(); diff --git a/retroshare-gui/src/gui/feeds/SecurityItem.ui b/retroshare-gui/src/gui/feeds/SecurityItem.ui index 585c18e00..eb5cb1268 100644 --- a/retroshare-gui/src/gui/feeds/SecurityItem.ui +++ b/retroshare-gui/src/gui/feeds/SecurityItem.ui @@ -283,6 +283,33 @@ + + + + Qt::NoFocus + + + Ignore User + + + + :/images/user/deny_user48.png:/images/user/deny_user48.png + + + + 24 + 24 + + + + Qt::ToolButtonTextBesideIcon + + + false + + + + diff --git a/retroshare-gui/src/gui/settings/NotifyPage.cpp b/retroshare-gui/src/gui/settings/NotifyPage.cpp index 29ac17cb1..95d5a5f95 100755 --- a/retroshare-gui/src/gui/settings/NotifyPage.cpp +++ b/retroshare-gui/src/gui/settings/NotifyPage.cpp @@ -33,6 +33,13 @@ #include "gui/NewsFeed.h" #include "util/misc.h" +#include "pqi/authssl.h" +//#include "gui/common/Rsdialogs.h" // For getting ID +//#include "gui/peers/PeersDialog.h" // Maybe for friend selection? +#include +#include +#include "gui/common/FriendSelectionDialog.h" + /** Constructor */ NotifyPage::NotifyPage(QWidget * parent, Qt::WindowFlags flags) : ConfigPage(parent, flags) @@ -47,6 +54,9 @@ NotifyPage::NotifyPage(QWidget * parent, Qt::WindowFlags flags) connect(ui.pushButtonDisableAll,SIGNAL(toggled(bool)), RsGUIEventManager::getInstance(), SLOT(SetDisableAll(bool))); connect(RsGUIEventManager::getInstance(),SIGNAL(disableAllChanged(bool)), ui.pushButtonDisableAll, SLOT(setChecked(bool))); + connect(ui.addIgnoredButton, SIGNAL(clicked()), this, SLOT(addIgnoredUser())); + connect(ui.removeIgnoredButton, SIGNAL(clicked()), this, SLOT(removeIgnoredUser())); + ui.notify_Blogs->hide(); QFont font = ui.notify_Peers->font(); // use font from existing checkbox @@ -394,6 +404,35 @@ void NotifyPage::load() notifyToggled() ; + loadIgnoredUsers(); +} + +void NotifyPage::loadIgnoredUsers() +{ + ui.ignoredTreeWidget->clear(); + QStringList headers; + headers << tr("Name") << tr("PGP Id"); + ui.ignoredTreeWidget->setHeaderLabels(headers); + + std::map ids; + AuthSSL::instance().getNotifyDenyList(ids); + for(const auto& pair : ids) { + QTreeWidgetItem* item = new QTreeWidgetItem(ui.ignoredTreeWidget); + + std::string displayName = pair.second; + if(displayName.empty()) { + RsPeerDetails details; + if(rsPeers && rsPeers->getGPGDetails(pair.first, details)) { + displayName = details.name; + // Optionally update the list in AuthSSL? + // AuthSSL::instance().addNotifyDeny(pair.first, displayName); + // Better not to modify state during load, just display it. + } + } + + item->setText(0, QString::fromStdString(displayName)); + item->setText(1, QString::fromStdString(pair.first.toStdString())); + } } void NotifyPage::notifyToggled() @@ -444,3 +483,46 @@ void NotifyPage::testToaster() } } } + +void NotifyPage::showEvent(QShowEvent *event) +{ + loadIgnoredUsers(); + ConfigPage::showEvent(event); +} + +void NotifyPage::addIgnoredUser() +{ + std::set ids = FriendSelectionDialog::selectFriends_PGP(this, tr("Ban Friend"), tr("Select a friend to ban"), FriendSelectionWidget::MODUS_SINGLE, FriendSelectionWidget::SHOW_GPG); + + if (ids.empty()) { + return; + } + + // Since MODUS_SINGLE, we should have at most one ID, but loop just in case or take first. + for(const RsPgpId& id : ids) { + if (id.isNull()) continue; + + // Try to get name from peers interface if possible, otherwise empty + std::string name; + RsPeerDetails details; + if(rsPeers && rsPeers->getGPGDetails(id, details)) name = details.name; + + AuthSSL::instance().addNotifyDeny(id, name); + if(rsPeers) { + rsPeers->removeFriend(id); + } + } + + // Refresh list + loadIgnoredUsers(); +} + +void NotifyPage::removeIgnoredUser() +{ + QTreeWidgetItem* item = ui.ignoredTreeWidget->currentItem(); + if(item) { + RsPgpId id(item->text(1).toStdString()); + AuthSSL::instance().removeNotifyDeny(id); + delete item; + } +} diff --git a/retroshare-gui/src/gui/settings/NotifyPage.h b/retroshare-gui/src/gui/settings/NotifyPage.h index 3e240c1da..b63268309 100755 --- a/retroshare-gui/src/gui/settings/NotifyPage.h +++ b/retroshare-gui/src/gui/settings/NotifyPage.h @@ -33,6 +33,8 @@ class UserNotify; class FeedNotify; class ToasterNotify; + + class UserNotifySetting { public: @@ -81,6 +83,12 @@ public: /** Loads the settings for this page */ virtual void load(); +protected: + void showEvent(QShowEvent *event) override; + +private: + void loadIgnoredUsers(); + virtual QPixmap iconPixmap() const { return FilesDefs::getPixmapFromQtResourcePath(":/icons/settings/notify.svg") ; } virtual QString pageName() const { return tr("Notify") ; } virtual QString helpText() const ; @@ -102,6 +110,9 @@ private slots: void updateToasterMargin(); void updateToasterPosition(); + + void addIgnoredUser(); + void removeIgnoredUser(); private: RsFeedTypeFlags getNewsFlags(); diff --git a/retroshare-gui/src/gui/settings/NotifyPage.ui b/retroshare-gui/src/gui/settings/NotifyPage.ui index d34c0fdf8..9e3f4cee1 100755 --- a/retroshare-gui/src/gui/settings/NotifyPage.ui +++ b/retroshare-gui/src/gui/settings/NotifyPage.ui @@ -481,6 +481,61 @@ + + + Ignored Users + + + + + + false + + + + Name + + + + + PGP Id + + + + + + + + + + Add + + + + + + + Remove + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + +