From ed0ea3aa01107811bdffe66fa91051c38b823772 Mon Sep 17 00:00:00 2001 From: chelovechishko Date: Sun, 8 May 2022 20:38:35 +0900 Subject: [PATCH] gui: chat: add power to vote distant participant If identity got deleted, then banned one should start this distant conversation, if i am not mistaken. --- retroshare-gui/src/gui/chat/ChatLobbyDialog.h | 8 +-- .../src/gui/chat/PopupChatWindow.cpp | 57 +++++++++++++++++++ retroshare-gui/src/gui/chat/PopupChatWindow.h | 6 ++ 3 files changed, 67 insertions(+), 4 deletions(-) diff --git a/retroshare-gui/src/gui/chat/ChatLobbyDialog.h b/retroshare-gui/src/gui/chat/ChatLobbyDialog.h index 429a5bfb4..065abacee 100644 --- a/retroshare-gui/src/gui/chat/ChatLobbyDialog.h +++ b/retroshare-gui/src/gui/chat/ChatLobbyDialog.h @@ -27,8 +27,8 @@ #include "ChatDialog.h" #include "PopupChatWindow.h" -Q_DECLARE_METATYPE(RsGxsId) -Q_DECLARE_METATYPE(QList) +// Q_DECLARE_METATYPE(RsGxsId) +// Q_DECLARE_METATYPE(QList) class GxsIdChooser ; class QToolButton; @@ -101,7 +101,7 @@ private: void muteParticipant(const RsGxsId& id); void unMuteParticipant(const RsGxsId& id); bool isNicknameInLobby(const RsGxsId& id); - + ChatLobbyId lobbyId; QString _lobby_name ; time_t lastUpdateListTime; @@ -117,7 +117,7 @@ private: /** Qt Designer generated object */ Ui::ChatLobbyDialog ui; - + /** Ignored Users in Chatlobby by nickname until we had implemented Peer Ids in ver 0.6 */ std::set mutedParticipants; diff --git a/retroshare-gui/src/gui/chat/PopupChatWindow.cpp b/retroshare-gui/src/gui/chat/PopupChatWindow.cpp index f9324d5fc..1f15345b1 100644 --- a/retroshare-gui/src/gui/chat/PopupChatWindow.cpp +++ b/retroshare-gui/src/gui/chat/PopupChatWindow.cpp @@ -34,6 +34,7 @@ #include "util/misc.h" #include "rshare.h" +#include #include #include @@ -100,6 +101,17 @@ PopupChatWindow::PopupChatWindow(bool tabbed, QWidget *parent, Qt::WindowFlags f connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint))); + voteNegative = new QAction(FilesDefs::getIconFromQtResourcePath(":/icons/png/thumbs-down.png"), + tr("Ban this person (Sets negative opinion)"), this); + voteNeutral = new QAction(FilesDefs::getIconFromQtResourcePath(":/icons/png/thumbs-neutral.png"), + tr("Give neutral opinion"), this); + votePositive = new QAction(FilesDefs::getIconFromQtResourcePath(":/icons/png/thumbs-up.png"), + tr("Give positive opinion"), this); + + connect(votePositive, SIGNAL(triggered()), this, SLOT(voteParticipant())); + connect(voteNeutral, SIGNAL(triggered()), this, SLOT(voteParticipant())); + connect(voteNegative, SIGNAL(triggered()), this, SLOT(voteParticipant())); + connect(ui.tabWidget, SIGNAL(tabChanged(ChatDialog*)), this, SLOT(tabChanged(ChatDialog*))); connect(ui.tabWidget, SIGNAL(tabClosed(ChatDialog*)), this, SLOT(tabClosed(ChatDialog*))); @@ -116,6 +128,37 @@ void PopupChatWindow::showContextMenu(QPoint) QMenu contextMnu(this); contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(":/images/highlight.png"),tr("Choose window color..."),this,SLOT(setStyle())); + ChatId ch_id = getCurrentDialog()->getChatId(); + if (ch_id.isDistantChatId()) { + DistantChatPeerId dc_id = ch_id.toDistantChatId(); + DistantChatPeerInfo dc_info; + if(rsMsgs->getDistantChatStatus(dc_id, dc_info)) { + RsGxsId gxs_id = dc_info.to_id; + if(!gxs_id.isNull() && !rsIdentity->isOwnId(gxs_id)) { + contextMnu.addAction(votePositive); + contextMnu.addAction(voteNeutral); + contextMnu.addAction(voteNegative); + + votePositive->setEnabled(false); + voteNeutral ->setEnabled(false); + voteNegative->setEnabled(false); + + RsOpinion rs_rep; + rsReputations->getOwnOpinion(gxs_id, rs_rep); + if (rsReputations->getOwnOpinion(gxs_id, rs_rep)) { + votePositive->setEnabled(rs_rep != RsOpinion::POSITIVE); + voteNeutral->setEnabled( ( rs_rep == RsOpinion::POSITIVE ) + || ( rs_rep == RsOpinion::NEGATIVE ) ); + voteNegative->setEnabled(rs_rep != RsOpinion::NEGATIVE); + + votePositive->setData(QVariant::fromValue(gxs_id)); + voteNeutral ->setData(QVariant::fromValue(gxs_id)); + voteNegative->setData(QVariant::fromValue(gxs_id)); + } + } + } + } + if (Settings->getChatFlags() & RS_CHAT_TABBED_WINDOW) { if(tabbedWindow) @@ -457,3 +500,17 @@ void PopupChatWindow::blink(bool on) setWindowIcon(on ? mBlinkIcon : *mEmptyIcon); } } + +void PopupChatWindow::voteParticipant() +{ + QAction *act = dynamic_cast(sender()) ; + if (!act) { + return ; + } + + RsOpinion opinion = RsOpinion::NEUTRAL; + if (act == voteNeutral) opinion = RsOpinion::NEUTRAL; + if (act == votePositive) opinion = RsOpinion::POSITIVE; + if (act == voteNegative) opinion = RsOpinion::NEGATIVE; + rsReputations->setOwnOpinion(act->data().value(), opinion); +} diff --git a/retroshare-gui/src/gui/chat/PopupChatWindow.h b/retroshare-gui/src/gui/chat/PopupChatWindow.h index 86f8ebc80..968531ea1 100644 --- a/retroshare-gui/src/gui/chat/PopupChatWindow.h +++ b/retroshare-gui/src/gui/chat/PopupChatWindow.h @@ -27,6 +27,8 @@ #include "ui_PopupChatWindow.h" #include #include +Q_DECLARE_METATYPE(RsGxsId) +Q_DECLARE_METATYPE(QList) class ChatDialog; @@ -67,6 +69,7 @@ private slots: void setOnTop(); void blink(bool on); void showContextMenu(QPoint p); + void voteParticipant(); private: bool tabbedWindow; @@ -75,6 +78,9 @@ private: ChatDialog *chatDialog; QIcon mBlinkIcon; QIcon *mEmptyIcon; + QAction* votePositive; + QAction* voteNegative; + QAction* voteNeutral; ChatDialog *getCurrentDialog(); void saveSettings();