chatlobby id context menu - fix reputation change actions

This commit is contained in:
RetroPooh 2017-01-12 16:26:35 +03:00
parent 10ba3a6364
commit 8ae9eff928

View File

@ -110,9 +110,9 @@ ChatLobbyDialog::ChatLobbyDialog(const ChatLobbyId& lid, QWidget *parent, Qt::Wi
connect(muteAct, SIGNAL(triggered()), this, SLOT(changePartipationState()));
connect(distantChatAct, SIGNAL(triggered()), this, SLOT(distantChatParticipant()));
connect(sendMessageAct, SIGNAL(triggered()), this, SLOT(sendMessage()));
connect(votePositiveAct, SIGNAL(triggered()), this, SLOT(voteParticipant(1)));
connect(voteNeutralAct, SIGNAL(triggered()), this, SLOT(voteParticipant(0)));
connect(banAct, SIGNAL(triggered()), this, SLOT(voteParticipant(-1)));
connect(votePositiveAct, SIGNAL(triggered()), this, SLOT(voteParticipantPositive()));
connect(voteNeutralAct, SIGNAL(triggered()), this, SLOT(voteParticipantNeutral()));
connect(banAct, SIGNAL(triggered()), this, SLOT(voteParticipantNegative()));
connect(showinpeopleAct, SIGNAL(triggered()), this, SLOT(showInPeopleTab()));
connect(actionSortByName, SIGNAL(triggered()), this, SLOT(sortParcipants()));
@ -263,37 +263,70 @@ void ChatLobbyDialog::participantsTreeWidgetCustomPopupMenu(QPoint)
contextMnu.exec(QCursor::pos());
}
void ChatLobbyDialog::voteParticipantPositive()
{
QList<QTreeWidgetItem*> selectedItems = ui.participantsList->selectedItems();
if (selectedItems.isEmpty())
return;
QList<QTreeWidgetItem*>::iterator item;
for (item = selectedItems.begin(); item != selectedItems.end(); ++item)
{
RsGxsId nickname;
dynamic_cast<GxsIdRSTreeWidgetItem*>(*item)->getId(nickname) ;
RsGxsId gxs_id;
rsMsgs->getIdentityForChatLobby(lobbyId, gxs_id);
// This test avoids to mute/ban your own identity
if (gxs_id!=nickname)
{
rsReputations->setOwnOpinion(nickname, RsReputations::OPINION_POSITIVE);
std::cerr << "Giving positive opinion to GXS id " << nickname << std::endl;
dynamic_cast<GxsIdRSTreeWidgetItem*>(*item)->forceUpdate();
}
}
}
void ChatLobbyDialog::voteParticipantNeutral()
{
QList<QTreeWidgetItem*> selectedItems = ui.participantsList->selectedItems();
if (selectedItems.isEmpty())
return;
QList<QTreeWidgetItem*>::iterator item;
for (item = selectedItems.begin(); item != selectedItems.end(); ++item)
{
RsGxsId nickname;
dynamic_cast<GxsIdRSTreeWidgetItem*>(*item)->getId(nickname) ;
RsGxsId gxs_id;
rsMsgs->getIdentityForChatLobby(lobbyId, gxs_id);
// This test avoids to mute/ban your own identity
if (gxs_id!=nickname)
{
rsReputations->setOwnOpinion(nickname, RsReputations::OPINION_NEUTRAL);
std::cerr << "Giving neutral opinion to GXS id " << nickname << std::endl;
dynamic_cast<GxsIdRSTreeWidgetItem*>(*item)->forceUpdate();
}
}
}
/**
* @brief Called when the "ban" menu is selected. Sets a negative reputation on the selected user.
*/
void ChatLobbyDialog::voteParticipant(int vote)
void ChatLobbyDialog::voteParticipantNegative()
{
QList<QTreeWidgetItem*> selectedItems = ui.participantsList->selectedItems();
if (selectedItems.isEmpty()) {
if (selectedItems.isEmpty())
return;
}
QList<QTreeWidgetItem*>::iterator item;
for (item = selectedItems.begin(); item != selectedItems.end(); ++item) {
for (item = selectedItems.begin(); item != selectedItems.end(); ++item)
{
RsGxsId nickname;
dynamic_cast<GxsIdRSTreeWidgetItem*>(*item)->getId(nickname) ;
RsGxsId gxs_id;
rsMsgs->getIdentityForChatLobby(lobbyId, gxs_id);
// This test avoids to mute/ban your own identity
if (gxs_id!=nickname)
{
switch(vote)
{
case 1: rsReputations->setOwnOpinion(nickname, RsReputations::OPINION_POSITIVE);
case -1: rsReputations->setOwnOpinion(nickname, RsReputations::OPINION_NEGATIVE);
default: rsReputations->setOwnOpinion(nickname, RsReputations::OPINION_NEUTRAL);
}
std::cerr << "Giving " << vote << " opinion to GXS id " << nickname << std::endl;
rsReputations->setOwnOpinion(nickname, RsReputations::OPINION_NEGATIVE);
std::cerr << "Giving negative opinion to GXS id " << nickname << std::endl;
dynamic_cast<GxsIdRSTreeWidgetItem*>(*item)->forceUpdate();
}
}