Added check for empty lobby nick name.

Moved notify of lobby nick name change from the gui to p3ChatService.
Added missing mutex locks for p3ChatService::_default_nick_name.
Recompile needed.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5184 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2012-05-23 22:33:45 +00:00
parent 917f9913df
commit 1855d19436
6 changed files with 71 additions and 42 deletions

View File

@ -251,7 +251,6 @@ virtual bool clearPrivateChatQueue(bool incoming, const std::string& id) = 0;
virtual void sendStatusString(const std::string& id,const std::string& status_string) = 0 ;
virtual void sendGroupChatStatusString(const std::string& status_string) = 0 ;
virtual void setCustomStateString(const std::string& status_string) = 0 ;
virtual std::string getCustomStateString() = 0 ;
virtual std::string getCustomStateString(const std::string& peer_id) = 0 ;
@ -263,11 +262,6 @@ virtual void setOwnAvatarData(const unsigned char *data,int size) = 0 ;
virtual void getOwnAvatarData(unsigned char *& data,int& size) = 0 ;
virtual bool joinPublicChatLobby(const ChatLobbyId& lobby_id) = 0 ;
virtual bool sendLobbyStatusPeerChangedNickname(const ChatLobbyId& lobby_id, const std::string& newnick) = 0 ;
virtual bool isLobbyId(const std::string& virtual_peer_id,ChatLobbyId& lobby_id) = 0;
virtual bool getVirtualPeerId(const ChatLobbyId& lobby_id,std::string& vpid) = 0;
virtual void getChatLobbyList(std::list<ChatLobbyInfo>& cl_info) = 0;

View File

@ -308,12 +308,6 @@ bool p3Msgs::joinPublicChatLobby(const ChatLobbyId& lobby_id)
return mChatSrv->joinPublicChatLobby(lobby_id) ;
}
bool p3Msgs::sendLobbyStatusPeerChangedNickname(const ChatLobbyId& lobby_id, const std::string& newnick)
{
return mChatSrv->sendLobbyStatusPeerChangedNickname(lobby_id, newnick) ;
}
void p3Msgs::getListOfNearbyChatLobbies(std::vector<PublicChatLobbyRecord>& public_lobbies)
{
mChatSrv->getListOfNearbyChatLobbies(public_lobbies) ;

View File

@ -142,7 +142,6 @@ class p3Msgs: public RsMsgs
*/
virtual bool getPrivateChatQueueIds(bool incoming, std::list<std::string> &ids);
/*!
* @param chats ref to list of received private chats is stored here
*/
@ -168,11 +167,7 @@ class p3Msgs: public RsMsgs
/****************************************/
virtual bool joinPublicChatLobby(const ChatLobbyId& id) ;
virtual bool sendLobbyStatusPeerChangedNickname(const ChatLobbyId& id, const std::string& newnick) ;
virtual void getListOfNearbyChatLobbies(std::vector<PublicChatLobbyRecord>& public_lobbies) ;
virtual bool getVirtualPeerId(const ChatLobbyId& id,std::string& vpid) ;
virtual bool isLobbyId(const std::string& virtual_peer_id,ChatLobbyId& lobby_id) ;

View File

@ -1557,7 +1557,8 @@ bool p3ChatService::loadList(std::list<RsItem*>& load)
#ifdef CHAT_DEBUG
std::cerr << "Loaded config default nick name for chat: " << kit->value << std::endl ;
#endif
_default_nick_name = kit->value ;
if (!kit->value.empty())
_default_nick_name = kit->value ;
}
// delete unknown items
@ -1775,13 +1776,9 @@ void p3ChatService::sendLobbyStatusString(const ChatLobbyId& lobby_id,const std:
*
* as example for updating their ChatLobby Blocklist for muted peers
* */
bool p3ChatService::sendLobbyStatusPeerChangedNickname(const ChatLobbyId& lobby_id, const std::string& newnick)
void p3ChatService::sendLobbyStatusPeerChangedNickname(const ChatLobbyId& lobby_id, const std::string& newnick)
{
std::string nick ;
getNickNameForChatLobby(lobby_id,nick) ;
sendLobbyStatusItem(lobby_id,RS_CHAT_LOBBY_EVENT_PEER_CHANGE_NICKNAME, newnick) ;
return true;
}
@ -1792,6 +1789,7 @@ void p3ChatService::sendLobbyStatusPeerLiving(const ChatLobbyId& lobby_id)
sendLobbyStatusItem(lobby_id,RS_CHAT_LOBBY_EVENT_PEER_LEFT,nick) ;
}
void p3ChatService::sendLobbyStatusNewPeer(const ChatLobbyId& lobby_id)
{
std::string nick ;
@ -1799,6 +1797,7 @@ void p3ChatService::sendLobbyStatusNewPeer(const ChatLobbyId& lobby_id)
sendLobbyStatusItem(lobby_id,RS_CHAT_LOBBY_EVENT_PEER_JOINED,nick) ;
}
void p3ChatService::sendLobbyStatusKeepAlive(const ChatLobbyId& lobby_id)
{
std::string nick ;
@ -2411,12 +2410,23 @@ void p3ChatService::unsubscribeChatLobby(const ChatLobbyId& id)
}
bool p3ChatService::setDefaultNickNameForChatLobby(const std::string& nick)
{
_default_nick_name = nick;
if (nick.empty())
{
std::cerr << "Ignore empty nickname for chat lobby " << std::endl;
return false;
}
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
_default_nick_name = nick;
}
IndicateConfigChanged() ;
return true ;
}
bool p3ChatService::getDefaultNickNameForChatLobby(std::string& nick)
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
nick = _default_nick_name ;
return true ;
}
@ -2441,21 +2451,55 @@ bool p3ChatService::getNickNameForChatLobby(const ChatLobbyId& lobby_id,std::str
bool p3ChatService::setNickNameForChatLobby(const ChatLobbyId& lobby_id,const std::string& nick)
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
#ifdef CHAT_DEBUG
std::cerr << "Changing nickname for chat lobby " << std::hex << lobby_id << std::dec << " to " << nick << std::endl;
#endif
std::map<ChatLobbyId,ChatLobbyEntry>::iterator it = _chat_lobbys.find(lobby_id) ;
if(it == _chat_lobbys.end())
if (nick.empty())
{
std::cerr << " (EE) lobby does not exist!!" << std::endl;
std::cerr << "Ignore empty nickname for chat lobby " << std::hex << lobby_id << std::dec << std::endl;
return false;
}
it->second.nick_name = nick ;
// first check for change and send status peer changed nick name
bool changed = false;
std::map<ChatLobbyId,ChatLobbyEntry>::iterator it;
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
#ifdef CHAT_DEBUG
std::cerr << "Changing nickname for chat lobby " << std::hex << lobby_id << std::dec << " to " << nick << std::endl;
#endif
it = _chat_lobbys.find(lobby_id) ;
if(it == _chat_lobbys.end())
{
std::cerr << " (EE) lobby does not exist!!" << std::endl;
return false;
}
if (it->second.nick_name != nick)
{
changed = true;
}
}
if (changed)
{
// Inform other peers of change the Nickname
sendLobbyStatusPeerChangedNickname(lobby_id, nick) ;
// set new nick name
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
it = _chat_lobbys.find(lobby_id) ;
if(it == _chat_lobbys.end())
{
std::cerr << " (EE) lobby does not exist!!" << std::endl;
return false;
}
it->second.nick_name = nick ;
}
return true ;
}

View File

@ -76,8 +76,6 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor
*/
bool sendPrivateChat(const std::string &id, const std::wstring &msg);
bool sendLobbyStatusPeerChangedNickname(const ChatLobbyId& lobby_id, const std::string& newnick) ;
/*!
* can be used to send 'immediate' status msgs, these status updates are meant for immediate use by peer (not saved by rs)
* e.g currently used to update user when a peer 'is typing' during a chat
@ -243,6 +241,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor
void sendLobbyStatusItem(const ChatLobbyId&, int type, const std::string& status_string) ;
void sendLobbyStatusPeerLiving(const ChatLobbyId& lobby_id) ;
void sendLobbyStatusPeerChangedNickname(const ChatLobbyId& lobby_id, const std::string& newnick) ;
void sendLobbyStatusNewPeer(const ChatLobbyId& lobby_id) ;
void sendLobbyStatusKeepAlive(const ChatLobbyId&) ;

View File

@ -138,7 +138,12 @@ void ChatLobbyDialog::processSettings(bool load)
void ChatLobbyDialog::setNickname(const QString &nickname)
{
rsMsgs->setNickNameForChatLobby(lobbyId, nickname.toUtf8().constData());
ui.chatWidget->setName(nickname);
// get new nick name
std::string newNickname;
if (rsMsgs->getNickNameForChatLobby(lobbyId, newNickname)) {
ui.chatWidget->setName(QString::fromUtf8(newNickname.c_str()));
}
}
/**
@ -155,9 +160,7 @@ void ChatLobbyDialog::changeNickname()
rsMsgs->getNickNameForChatLobby(lobbyId, nickName);
dialog.setTextValue(QString::fromUtf8(nickName.c_str()));
if (dialog.exec() == QDialog::Accepted) {
// Informa other peers of change the Nickname, to update their mute list
rsMsgs->sendLobbyStatusPeerChangedNickname(lobbyId, dialog.textValue().toUtf8().constData());
if (dialog.exec() == QDialog::Accepted && !dialog.textValue().isEmpty()) {
setNickname(dialog.textValue());
}
}