Improved mute feature, to update Blocklist, when the peer changes his name.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5159 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
notdefine 2012-05-11 20:53:27 +00:00
parent f6c6af8b59
commit 5a3863d216
3 changed files with 53 additions and 31 deletions

View File

@ -2455,10 +2455,6 @@ bool p3ChatService::setNickNameForChatLobby(const ChatLobbyId& lobby_id,const st
return false; return false;
} }
// // inform other user about name change
// sendLobbyStatusPeerChangedNickname(lobby_id);
it->second.nick_name = nick ; it->second.nick_name = nick ;
return true ; return true ;
} }

View File

@ -29,6 +29,7 @@
#include "gui/settings/RsharePeerSettings.h" #include "gui/settings/RsharePeerSettings.h"
#include "gui/MainWindow.h" #include "gui/MainWindow.h"
#include "gui/FriendsDialog.h" #include "gui/FriendsDialog.h"
#include <gui/common/html.h>
#include <retroshare/rsnotify.h> #include <retroshare/rsnotify.h>
@ -136,11 +137,6 @@ void ChatLobbyDialog::processSettings(bool load)
*/ */
void ChatLobbyDialog::setNickname(const QString &nickname) void ChatLobbyDialog::setNickname(const QString &nickname)
{ {
// std::string oldNickName;
// rsMsgs->getNickNameForChatLobby(lobbyId, oldNickName);
rsMsgs->setNickNameForChatLobby(lobbyId, nickname.toUtf8().constData()); rsMsgs->setNickNameForChatLobby(lobbyId, nickname.toUtf8().constData());
ui.chatWidget->setName(nickname); ui.chatWidget->setName(nickname);
} }
@ -160,7 +156,7 @@ void ChatLobbyDialog::changeNickname()
dialog.setTextValue(QString::fromUtf8(nickName.c_str())); dialog.setTextValue(QString::fromUtf8(nickName.c_str()));
if (dialog.exec() == QDialog::Accepted) { if (dialog.exec() == QDialog::Accepted) {
// Informate other peers of change the Nickname, to update their mute list // Informa other peers of change the Nickname, to update their mute list
rsMsgs->sendLobbyStatusPeerChangedNickname(lobbyId, dialog.textValue().toUtf8().constData()); rsMsgs->sendLobbyStatusPeerChangedNickname(lobbyId, dialog.textValue().toUtf8().constData());
setNickname(dialog.textValue()); setNickname(dialog.textValue());
} }
@ -185,7 +181,7 @@ void ChatLobbyDialog::addIncomingChatMsg(const ChatInfo& info)
// ui.chatWidget->addChatMsg(true, name.append(" ").append(rsid), sendTime, recvTime, message, ChatWidget::TYPE_NORMAL); // ui.chatWidget->addChatMsg(true, name.append(" ").append(rsid), sendTime, recvTime, message, ChatWidget::TYPE_NORMAL);
ui.chatWidget->addChatMsg(true, name, sendTime, recvTime, message, ChatWidget::TYPE_NORMAL); ui.chatWidget->addChatMsg(true, name, sendTime, recvTime, message, ChatWidget::TYPE_NORMAL);
} else { } else {
// ui.chatWidget->addChatMsg(true, name, sendTime, recvTime, message.append(" (TEST BLOCKED)"), ChatWidget::TYPE_NORMAL); // ui.chatWidget->addChatMsg(true, name, sendTime, recvTime, message.append(" (BLOCKED)"), ChatWidget::TYPE_NORMAL);
} }
// also update peer list. // also update peer list.
@ -228,8 +224,6 @@ void ChatLobbyDialog::updateParticipantsList()
widgetitem->setCheckState(Qt::Checked); widgetitem->setCheckState(Qt::Checked);
} }
widgetitem->setText(participant); widgetitem->setText(participant);
// widgetitem->setToolTip(it.rsid.c_str());
widgetitem->setToolTip(tr("Uncheck to mute participant")); widgetitem->setToolTip(tr("Uncheck to mute participant"));
ui.participantsList->addItem(widgetitem); ui.participantsList->addItem(widgetitem);
@ -253,13 +247,9 @@ void ChatLobbyDialog::changePartipationState(QListWidgetItem *item)
std::cerr << "check Partipation status for '" << nickname.toStdString() << std::endl; std::cerr << "check Partipation status for '" << nickname.toStdString() << std::endl;
if (item->checkState() == Qt::Unchecked) { if (item->checkState() == Qt::Unchecked) {
// Mute muteParticipant(nickname);
std::cerr << " Mute " << std::endl;
mutedParticipants->append(nickname);
} else { } else {
// Unmute unMuteParticipant(nickname);
std::cerr << " UnMute " << std::endl;
mutedParticipants->removeOne(nickname);
} }
mutedParticipants->removeDuplicates(); mutedParticipants->removeDuplicates();
@ -267,6 +257,40 @@ void ChatLobbyDialog::changePartipationState(QListWidgetItem *item)
updateParticipantsList(); updateParticipantsList();
} }
void ChatLobbyDialog::muteParticipant(const QString &nickname) {
std::cerr << " Mute " << std::endl;
mutedParticipants->append(nickname);
}
void ChatLobbyDialog::unMuteParticipant(const QString &nickname) {
std::cerr << " UnMute " << std::endl;
mutedParticipants->removeAll(nickname);
}
/**
* Is this nickName already known in the lobby
*/
bool ChatLobbyDialog::isNicknameInLobby(const QString &nickname) {
std::list<ChatLobbyInfo> linfos;
rsMsgs->getChatLobbyList(linfos);
std::list<ChatLobbyInfo>::const_iterator it(linfos.begin());
// Set it to the current ChatLobby
for (; it!=linfos.end() && (*it).lobby_id != lobbyId; ++it);
if (it != linfos.end()) {
for (std::map<std::string,time_t>::const_iterator it2((*it).nick_names.begin()); it2 != (*it).nick_names.end(); ++it2) {
QString participant = QString::fromUtf8( (it2->first).c_str() );
if (participant==nickname) {
return true;
}
}
}
return false;
}
/** /**
* Should Messages from this Nickname be muted? * Should Messages from this Nickname be muted?
* *
@ -278,17 +302,10 @@ void ChatLobbyDialog::changePartipationState(QListWidgetItem *item)
* *
* @param QString nickname to check * @param QString nickname to check
*/ */
bool ChatLobbyDialog::isParticipantMuted(QString &participant) bool ChatLobbyDialog::isParticipantMuted(const QString &participant)
{ {
// @todo genauer match nicht nur into // nickname in Mute list
QStringList result=mutedParticipants->filter(participant); return mutedParticipants->contains(participant);
// nickname not in Mute list
if (result.isEmpty()) {
return false;
}
return true;
} }
void ChatLobbyDialog::displayLobbyEvent(int event_type, const QString& nickname, const QString& str) void ChatLobbyDialog::displayLobbyEvent(int event_type, const QString& nickname, const QString& str)
@ -305,6 +322,12 @@ void ChatLobbyDialog::displayLobbyEvent(int event_type, const QString& nickname,
break; break;
case RS_CHAT_LOBBY_EVENT_PEER_CHANGE_NICKNAME: case RS_CHAT_LOBBY_EVENT_PEER_CHANGE_NICKNAME:
ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 changed his name to: %2").arg(nickname, str), ChatWidget::TYPE_SYSTEM); ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 changed his name to: %2").arg(nickname, str), ChatWidget::TYPE_SYSTEM);
// TODO if a user was muted and changed his name, update mute list, but only, when the muted peer, dont change his name to a other peer in your chat lobby
if (isParticipantMuted(nickname) && !isNicknameInLobby(str)) {
muteParticipant(str);
}
break; break;
case RS_CHAT_LOBBY_EVENT_KEEP_ALIVE: case RS_CHAT_LOBBY_EVENT_KEEP_ALIVE:
//std::cerr << "Received keep alive packet from " << nickname.toStdString() << " in lobby " << getPeerId() << std::endl; //std::cerr << "Received keep alive packet from " << nickname.toStdString() << " in lobby " << getPeerId() << std::endl;

View File

@ -63,7 +63,10 @@ protected slots:
private: private:
void updateParticipantsList(); void updateParticipantsList();
bool isParticipantMuted(QString &participant); void muteParticipant(const QString &nickname);
void unMuteParticipant(const QString &nickname);
bool isParticipantMuted(const QString &participant);
bool isNicknameInLobby(const QString &nickname);
ChatLobbyId lobbyId; ChatLobbyId lobbyId;
time_t lastUpdateListTime; time_t lastUpdateListTime;