added leaving notification to chat lobby

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4743 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2011-12-28 22:33:37 +00:00
parent 4236ad59a5
commit b6f8e2a306
2 changed files with 42 additions and 29 deletions

View file

@ -1399,7 +1399,7 @@ bool p3ChatService::recvLobbyChat(RsChatLobbyMsgItem *item)
return true ;
}
bool p3ChatService::sendLobbyChat(const std::wstring& msg, const ChatLobbyId& lobby_id)
bool p3ChatService::sendLobbyChat(const std::wstring& msg, const ChatLobbyId& lobby_id,bool management)
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
@ -1429,6 +1429,10 @@ bool p3ChatService::sendLobbyChat(const std::wstring& msg, const ChatLobbyId& lo
lobby.msg_cache[item.msg_id] = time(NULL) ; // put the msg in cache!
item.lobby_id = lobby_id ;
if(management)
item.nick = "Lobby management" ;
else
item.nick = lobby.nick_name ;
// chat msg stuff
@ -1700,7 +1704,7 @@ bool p3ChatService::acceptLobbyInvite(const ChatLobbyId& lobby_id)
// Copy string to wstring.
std::copy(_default_nick_name.begin(), _default_nick_name.end(), wmsg.begin());
sendLobbyChat(wmsg + L" joined the lobby",lobby_id) ;
sendLobbyChat(wmsg + L" joined the lobby",lobby_id,true) ;
return true ;
}
@ -1793,6 +1797,14 @@ void p3ChatService::handleFriendUnsubscribeLobby(RsChatLobbyUnsubscribeItem *ite
}
void p3ChatService::unsubscribeChatLobby(const ChatLobbyId& id)
{
// send AKN item
std::string nick ;
getNickNameForChatLobby(id,nick) ;
std::wstring wmsg(nick.length(), L' '); // Make room for characters
std::copy(nick.begin(), nick.end(), wmsg.begin());
sendLobbyChat(wmsg + L" has left the lobby",id,true) ;
{
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
@ -1803,6 +1815,7 @@ void p3ChatService::unsubscribeChatLobby(const ChatLobbyId& id)
std::cerr << "Chat lobby " << id << " does not exist ! Can't unsubscribe!" << std::endl;
return ;
}
// send a lobby leaving packet to all friends
for(std::set<std::string>::const_iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2)
@ -1825,7 +1838,7 @@ void p3ChatService::unsubscribeChatLobby(const ChatLobbyId& id)
_lobby_ids.erase(it2) ;
break ;
}
}
// done!
}
bool p3ChatService::setDefaultNickNameForChatLobby(const std::string& nick)

View file

@ -214,7 +214,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor
/// receive and handle chat lobby item
bool recvLobbyChat(RsChatLobbyMsgItem*) ;
bool sendLobbyChat(const std::wstring&, const ChatLobbyId&) ;
bool sendLobbyChat(const std::wstring&, const ChatLobbyId&,bool management = false) ;
void handleRecvLobbyInvite(RsChatLobbyInviteItem*) ;
void checkAndRedirectMsgToLobby(RsChatMsgItem*) ;
void handleConnectionChallenge(RsChatLobbyConnectChallengeItem *item) ;