diff --git a/libretroshare/src/retroshare/rsmsgs.h b/libretroshare/src/retroshare/rsmsgs.h index ce3e6e564..03e34834b 100644 --- a/libretroshare/src/retroshare/rsmsgs.h +++ b/libretroshare/src/retroshare/rsmsgs.h @@ -164,10 +164,10 @@ class ChatLobbyInvite std::string lobby_topic ; uint32_t lobby_privacy_level ; }; -class PublicChatLobbyRecord +class VisibleChatLobbyRecord { public: - PublicChatLobbyRecord() { total_number_of_peers = 0 ; } + VisibleChatLobbyRecord() { total_number_of_peers = 0 ; } ChatLobbyId lobby_id ; // unique id of the lobby std::string lobby_name ; // name to use for this lobby @@ -176,6 +176,7 @@ class PublicChatLobbyRecord uint32_t total_number_of_peers ; // total number of particpating peers. Might not be time_t last_report_time ; // last time the lobby was reported. + uint32_t lobby_privacy_level ; // see RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC / RS_CHAT_LOBBY_PRIVACY_LEVEL_PRIVATE }; class ChatLobbyInfo { @@ -261,11 +262,11 @@ virtual void getAvatarData(const std::string& pid,unsigned char *& data,int& siz 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 joinVisibleChatLobby(const ChatLobbyId& lobby_id) = 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& cl_info) = 0; -virtual void getListOfNearbyChatLobbies(std::vector& public_lobbies) = 0 ; +virtual void getListOfNearbyChatLobbies(std::vector& public_lobbies) = 0 ; virtual void invitePeerToLobby(const ChatLobbyId& lobby_id,const std::string& peer_id) = 0; virtual bool acceptLobbyInvite(const ChatLobbyId& id) = 0 ; virtual void denyLobbyInvite(const ChatLobbyId& id) = 0 ; diff --git a/libretroshare/src/rsserver/p3msgs.cc b/libretroshare/src/rsserver/p3msgs.cc index 6d9c9eeab..f95567a4a 100644 --- a/libretroshare/src/rsserver/p3msgs.cc +++ b/libretroshare/src/rsserver/p3msgs.cc @@ -303,12 +303,12 @@ bool p3Msgs::getNickNameForChatLobby(const ChatLobbyId& lobby_id,std::string& ni return mChatSrv->getNickNameForChatLobby(lobby_id,nick_name) ; } -bool p3Msgs::joinPublicChatLobby(const ChatLobbyId& lobby_id) +bool p3Msgs::joinVisibleChatLobby(const ChatLobbyId& lobby_id) { - return mChatSrv->joinPublicChatLobby(lobby_id) ; + return mChatSrv->joinVisibleChatLobby(lobby_id) ; } -void p3Msgs::getListOfNearbyChatLobbies(std::vector& public_lobbies) +void p3Msgs::getListOfNearbyChatLobbies(std::vector& public_lobbies) { mChatSrv->getListOfNearbyChatLobbies(public_lobbies) ; } diff --git a/libretroshare/src/rsserver/p3msgs.h b/libretroshare/src/rsserver/p3msgs.h index f6a114931..4da5b74ed 100644 --- a/libretroshare/src/rsserver/p3msgs.h +++ b/libretroshare/src/rsserver/p3msgs.h @@ -167,8 +167,8 @@ class p3Msgs: public RsMsgs /****************************************/ - virtual bool joinPublicChatLobby(const ChatLobbyId& id) ; - virtual void getListOfNearbyChatLobbies(std::vector& public_lobbies) ; + virtual bool joinVisibleChatLobby(const ChatLobbyId& id) ; + virtual void getListOfNearbyChatLobbies(std::vector& public_lobbies) ; virtual bool getVirtualPeerId(const ChatLobbyId& id,std::string& vpid) ; virtual bool isLobbyId(const std::string& virtual_peer_id,ChatLobbyId& lobby_id) ; virtual void getChatLobbyList(std::list >&) ; diff --git a/libretroshare/src/serialiser/rsmsgitems.cc b/libretroshare/src/serialiser/rsmsgitems.cc index 905838231..0338eff9b 100644 --- a/libretroshare/src/serialiser/rsmsgitems.cc +++ b/libretroshare/src/serialiser/rsmsgitems.cc @@ -56,6 +56,19 @@ std::ostream& RsChatMsgItem::print(std::ostream &out, uint16_t indent) printRsItemEnd(out, "RsChatMsgItem", indent); return out; } +std::ostream& RsChatLobbyListItem_deprecated2::print(std::ostream &out, uint16_t indent) +{ + printRsItemBase(out, "RsChatLobbyListItem_deprecated2", indent); + + for(uint32_t i=0;i lobby_names ; std::vector lobby_counts ; }; +class RsChatLobbyListItem_deprecated2: public RsChatItem +{ + public: + RsChatLobbyListItem_deprecated2() : RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_deprecated2) {} + RsChatLobbyListItem_deprecated2(void *data,uint32_t size) ; + virtual ~RsChatLobbyListItem_deprecated2() {} + + virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); + + virtual bool serialise(void *data,uint32_t& size) ; + virtual uint32_t serial_size() ; + + std::vector lobby_ids ; + std::vector lobby_names ; + std::vector lobby_topics ; + std::vector lobby_counts ; +}; class RsChatLobbyListItem: public RsChatItem { public: @@ -216,6 +234,7 @@ class RsChatLobbyListItem: public RsChatItem std::vector lobby_names ; std::vector lobby_topics ; std::vector lobby_counts ; + std::vector lobby_privacy_levels ; }; class RsChatLobbyUnsubscribeItem: public RsChatItem { diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index 06ec7cc7f..e9af41a1a 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -61,7 +61,7 @@ p3ChatService::p3ChatService(p3LinkMgr *lm, p3HistoryMgr *historyMgr) _default_nick_name = rsPeers->getPeerName(rsPeers->getOwnId()); _should_reset_lobby_counts = false ; - last_public_lobby_info_request_time = 0 ; + last_visible_lobby_info_request_time = 0 ; } int p3ChatService::tick() @@ -348,7 +348,7 @@ void p3ChatService::locked_printDebugInfo() const std::cerr << "Visible public lobbies: " << std::endl; - for( std::map::const_iterator it(_public_lobbies.begin()) ;it!=_public_lobbies.end();++it) + for( std::map::const_iterator it(_visible_lobbies.begin()) ;it!=_visible_lobbies.end();++it) { std::cerr << " " << std::hex << it->first << " name = " << std::dec << it->second.lobby_name << it->second.lobby_topic << std::endl; for(std::set::const_iterator it2(it->second.participating_friends.begin());it2!=it->second.participating_friends.end();++it2) @@ -654,7 +654,13 @@ void p3ChatService::handleRecvChatLobbyListRequest(RsChatLobbyListRequestItem *c RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ for(std::map::const_iterator it(_chat_lobbys.begin());it!=_chat_lobbys.end();++it) - if(it->second.lobby_privacy_level == RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC) + { + const ChatLobbyEntry& lobby(it->second) ; + + if(lobby.lobby_privacy_level == RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC + || (lobby.lobby_privacy_level == RS_CHAT_LOBBY_PRIVACY_LEVEL_PRIVATE + && (lobby.previously_known_peers.find(clr->PeerId()) != lobby.previously_known_peers.end() + ||lobby.participating_friends.find(clr->PeerId()) != lobby.participating_friends.end()) )) { #ifdef CHAT_DEBUG std::cerr << " Adding lobby " << std::hex << it->first << std::dec << " \"" << it->second.lobby_name << it->second.lobby_topic << "\" count=" << it->second.nick_names.size() << std::endl; @@ -662,13 +668,15 @@ void p3ChatService::handleRecvChatLobbyListRequest(RsChatLobbyListRequestItem *c item->lobby_ids.push_back(it->first) ; item->lobby_names.push_back(it->second.lobby_name) ; - item->lobby_topics.push_back(it->second.lobby_topic) ; + item->lobby_topics.push_back(it->second.lobby_topic) ; item->lobby_counts.push_back(it->second.nick_names.size()) ; + item->lobby_privacy_levels.push_back(it->second.lobby_privacy_level) ; } #ifdef CHAT_DEBUG else std::cerr << " Not adding private lobby " << std::hex << it->first << std::dec << std::endl ; #endif + } } item->PeerId(clr->PeerId()) ; @@ -678,15 +686,29 @@ void p3ChatService::handleRecvChatLobbyListRequest(RsChatLobbyListRequestItem *c #endif sendItem(item); - // *********** Also send an item in old format. To be removed. + // *********** Also send an item in old formats. To be removed. RsChatLobbyListItem_deprecated *itemd = new RsChatLobbyListItem_deprecated; - itemd->lobby_ids = item->lobby_ids ; - itemd->lobby_names = item->lobby_names ; - itemd->lobby_counts = item->lobby_counts ; + RsChatLobbyListItem_deprecated2 *itemd2 = new RsChatLobbyListItem_deprecated2; + + for(uint32_t i=0;ilobby_ids.size();++i) + if(item->lobby_privacy_levels[i] == RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC) + { + itemd->lobby_ids.push_back(item->lobby_ids[i]) ; + itemd->lobby_names.push_back(item->lobby_names[i]) ; + itemd->lobby_counts.push_back(item->lobby_counts[i]) ; + + itemd2->lobby_ids.push_back(item->lobby_ids[i]) ; + itemd2->lobby_names.push_back(item->lobby_names[i]) ; + itemd2->lobby_counts.push_back(item->lobby_counts[i]) ; + itemd2->lobby_topics.push_back(item->lobby_topics[i]) ; + } + itemd->PeerId(clr->PeerId()) ; + itemd2->PeerId(clr->PeerId()) ; sendItem(itemd) ; + sendItem(itemd2) ; // End of part to remove in future versions. ************* } @@ -699,7 +721,7 @@ void p3ChatService::handleRecvChatLobbyList(RsChatLobbyListItem_deprecated *item for(uint32_t i=0;ilobby_ids.size();++i) { - PublicChatLobbyRecord& rec(_public_lobbies[item->lobby_ids[i]]) ; + VisibleChatLobbyRecord& rec(_visible_lobbies[item->lobby_ids[i]]) ; rec.lobby_id = item->lobby_ids[i] ; rec.lobby_name = item->lobby_names[i] ; @@ -711,6 +733,36 @@ void p3ChatService::handleRecvChatLobbyList(RsChatLobbyListItem_deprecated *item rec.total_number_of_peers = std::max(rec.total_number_of_peers,item->lobby_counts[i]) ; rec.last_report_time = now ; + rec.lobby_privacy_level = RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC ; + } + } + + rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ; + _should_reset_lobby_counts = false ; +} +void p3ChatService::handleRecvChatLobbyList(RsChatLobbyListItem_deprecated2 *item) +{ + { + time_t now = time(NULL) ; + + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + + for(uint32_t i=0;ilobby_ids.size();++i) + { + VisibleChatLobbyRecord& rec(_visible_lobbies[item->lobby_ids[i]]) ; + + rec.lobby_id = item->lobby_ids[i] ; + rec.lobby_name = item->lobby_names[i] ; + rec.lobby_topic = item->lobby_topics[i] ; + rec.participating_friends.insert(item->PeerId()) ; + + if(_should_reset_lobby_counts) + rec.total_number_of_peers = item->lobby_counts[i] ; + else + rec.total_number_of_peers = std::max(rec.total_number_of_peers,item->lobby_counts[i]) ; + + rec.last_report_time = now ; + rec.lobby_privacy_level = RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC ; } } @@ -726,7 +778,7 @@ void p3ChatService::handleRecvChatLobbyList(RsChatLobbyListItem *item) for(uint32_t i=0;ilobby_ids.size();++i) { - PublicChatLobbyRecord& rec(_public_lobbies[item->lobby_ids[i]]) ; + VisibleChatLobbyRecord& rec(_visible_lobbies[item->lobby_ids[i]]) ; rec.lobby_id = item->lobby_ids[i] ; rec.lobby_name = item->lobby_names[i] ; @@ -739,13 +791,13 @@ void p3ChatService::handleRecvChatLobbyList(RsChatLobbyListItem *item) rec.total_number_of_peers = std::max(rec.total_number_of_peers,item->lobby_counts[i]) ; rec.last_report_time = now ; + rec.lobby_privacy_level = item->lobby_privacy_levels[i] ; } } rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ; _should_reset_lobby_counts = false ; } - void p3ChatService::handleRecvChatLobbyEventItem(RsChatLobbyEventItem *item) { #ifdef CHAT_DEBUG @@ -1007,20 +1059,20 @@ void p3ChatService::handleRecvChatStatusItem(RsChatStatusItem *cs) rsicontrol->getNotify().notifyChatStatus(cs->PeerId(),cs->status_string,false) ; } -void p3ChatService::getListOfNearbyChatLobbies(std::vector& public_lobbies) +void p3ChatService::getListOfNearbyChatLobbies(std::vector& visible_lobbies) { { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ - public_lobbies.clear() ; + visible_lobbies.clear() ; - for(std::map::const_iterator it(_public_lobbies.begin());it!=_public_lobbies.end();++it) - public_lobbies.push_back(it->second) ; + for(std::map::const_iterator it(_visible_lobbies.begin());it!=_visible_lobbies.end();++it) + visible_lobbies.push_back(it->second) ; } time_t now = time(NULL) ; - if(now > MIN_DELAY_BETWEEN_PUBLIC_LOBBY_REQ + last_public_lobby_info_request_time) + if(now > MIN_DELAY_BETWEEN_PUBLIC_LOBBY_REQ + last_visible_lobby_info_request_time) { std::list ids ; mLinkMgr->getOnlineList(ids); @@ -1035,7 +1087,7 @@ void p3ChatService::getListOfNearbyChatLobbies(std::vector::const_iterator it(_public_lobbies.find(lobby_id)) ; + std::map::const_iterator it(_visible_lobbies.find(lobby_id)) ; - if(it == _public_lobbies.end()) + if(it == _visible_lobbies.end()) { std::cerr << " lobby is not a known public chat lobby. Sorry!" << std::endl; return false ; @@ -2252,12 +2304,12 @@ bool p3ChatService::joinPublicChatLobby(const ChatLobbyId& lobby_id) time_t now = time(NULL) ; ChatLobbyEntry entry ; - entry.lobby_privacy_level = RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC ; + entry.lobby_privacy_level = it->second.lobby_privacy_level ;//RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC ; entry.participating_friends.clear() ; entry.nick_name = _default_nick_name ; entry.lobby_id = lobby_id ; entry.lobby_name = it->second.lobby_name ; - entry.lobby_topic = it->second.lobby_topic ; + entry.lobby_topic = it->second.lobby_topic ; entry.virtual_peer_id = makeVirtualPeerId(lobby_id) ; entry.connexion_challenge_count = 0 ; entry.last_activity = now ; @@ -2307,7 +2359,7 @@ ChatLobbyId p3ChatService::createChatLobby(const std::string& lobby_name,const s entry.nick_name = _default_nick_name ; // to be changed. For debug only!! entry.lobby_id = lobby_id ; entry.lobby_name = lobby_name ; - entry.lobby_topic = lobby_topic ; + entry.lobby_topic = lobby_topic ; entry.virtual_peer_id = makeVirtualPeerId(lobby_id) ; entry.connexion_challenge_count = 0 ; entry.last_activity = now ; @@ -2348,6 +2400,7 @@ void p3ChatService::handleFriendUnsubscribeLobby(RsChatLobbyUnsubscribeItem *ite #ifdef CHAT_DEBUG std::cerr << " removing peer id " << item->PeerId() << " from participant list of lobby " << std::hex << item->lobby_id << std::dec << std::endl; #endif + it->second.previously_known_peers.insert(*it2) ; it->second.participating_friends.erase(it2) ; break ; } @@ -2580,16 +2633,16 @@ void p3ChatService::cleanLobbyCaches() // 2 - clean deprecated public chat lobby records // - for(std::map::iterator it(_public_lobbies.begin());it!=_public_lobbies.end();) + for(std::map::iterator it(_visible_lobbies.begin());it!=_visible_lobbies.end();) if(it->second.last_report_time + MAX_KEEP_PUBLIC_LOBBY_RECORD < now) // this lobby record is too late. { #ifdef CHAT_DEBUG std::cerr << " removing old public lobby record 0x" << std::hex << it->first << ", time=" << std::dec << now - it->second.last_report_time << " secs ago" << std::endl; #endif - std::map::iterator tmp(it) ; + std::map::iterator tmp(it) ; ++tmp ; - _public_lobbies.erase(it) ; + _visible_lobbies.erase(it) ; it = tmp ; } else diff --git a/libretroshare/src/services/p3chatservice.h b/libretroshare/src/services/p3chatservice.h index 448adcb77..000eb79db 100644 --- a/libretroshare/src/services/p3chatservice.h +++ b/libretroshare/src/services/p3chatservice.h @@ -169,8 +169,8 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor void sendLobbyStatusString(const ChatLobbyId& id,const std::string& status_string) ; ChatLobbyId createChatLobby(const std::string& lobby_name,const std::string& lobby_topic, const std::list& invited_friends,uint32_t privacy_type) ; - void getListOfNearbyChatLobbies(std::vector& public_lobbies) ; - bool joinPublicChatLobby(const ChatLobbyId& id) ; + void getListOfNearbyChatLobbies(std::vector& public_lobbies) ; + bool joinVisibleChatLobby(const ChatLobbyId& id) ; protected: /************* from p3Config *******************/ @@ -212,6 +212,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor void handleRecvChatLobbyListRequest(RsChatLobbyListRequestItem *item) ; void handleRecvChatLobbyList(RsChatLobbyListItem *item) ; void handleRecvChatLobbyList(RsChatLobbyListItem_deprecated *item) ; + void handleRecvChatLobbyList(RsChatLobbyListItem_deprecated2 *item) ; void handleRecvChatLobbyEventItem(RsChatLobbyEventItem *item) ; /// Sends a request for an avatar to the peer of given id @@ -277,15 +278,16 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor int connexion_challenge_count ; time_t last_connexion_challenge_time ; time_t last_keep_alive_packet_time ; + std::set previously_known_peers ; }; std::map _chat_lobbys ; std::map _lobby_invites_queue ; - std::map _public_lobbies ; + std::map _visible_lobbies ; std::map _lobby_ids ; std::string _default_nick_name ; time_t last_lobby_challenge_time ; // prevents bruteforce attack - time_t last_public_lobby_info_request_time ; // allows to ask for updates + time_t last_visible_lobby_info_request_time ; // allows to ask for updates bool _should_reset_lobby_counts ; }; diff --git a/retroshare-gui/src/gui/ChatLobbyWidget.cpp b/retroshare-gui/src/gui/ChatLobbyWidget.cpp index a0fe248a7..23c522948 100644 --- a/retroshare-gui/src/gui/ChatLobbyWidget.cpp +++ b/retroshare-gui/src/gui/ChatLobbyWidget.cpp @@ -153,68 +153,80 @@ void ChatLobbyWidget::updateDisplay() #ifdef CHAT_LOBBY_GUI_DEBUG std::cerr << "updating chat lobby display!" << std::endl; #endif - std::vector publicLobbies; - rsMsgs->getListOfNearbyChatLobbies(publicLobbies); + std::vector visibleLobbies; + rsMsgs->getListOfNearbyChatLobbies(visibleLobbies); std::list lobbies; rsMsgs->getChatLobbyList(lobbies); #ifdef CHAT_LOBBY_GUI_DEBUG - std::cerr << "got " << publicLobbies.size() << " public lobbies, and " << lobbies.size() << " private lobbies." << std::endl; + std::cerr << "got " << visibleLobbies.size() << " visible lobbies, and " << lobbies.size() << " private lobbies." << std::endl; #endif // now, do a nice display of lobbies std::string vpid; uint32_t i; - uint32_t size = publicLobbies.size(); + uint32_t size = visibleLobbies.size(); std::list::const_iterator lobbyIt; // remove not existing public lobbies - int childCount = publicLobbyItem->childCount(); - int childIndex = 0; - while (childIndex < childCount) { - QTreeWidgetItem *itemLoop = publicLobbyItem->child(childIndex); - if (itemLoop->type() == TYPE_LOBBY) { - // check for public lobby - for (i = 0; i < size; ++i) { - if (itemLoop->data(COLUMN_DATA, ROLE_ID).toULongLong() == publicLobbies[i].lobby_id) { - break; - } - } - if (i >= size) { - // check for private lobby with public level - for (lobbyIt = lobbies.begin(); lobbyIt != lobbies.end(); ++lobbyIt) { - if (lobbyIt->lobby_privacy_level == RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC && - itemLoop->data(COLUMN_DATA, ROLE_ID).toULongLong() == lobbyIt->lobby_id) { + for(int p=0;p<2;++p) + { + QTreeWidgetItem *lobby_item = (p==0)?publicLobbyItem:privateLobbyItem ; + + int childCnt = lobby_item->childCount(); + int childIndex = 0; + + while (childIndex < childCnt) { + QTreeWidgetItem *itemLoop = lobby_item->child(childIndex); + if (itemLoop->type() == TYPE_LOBBY) + { + // check for visible lobby + for (i = 0; i < size; ++i) + if (itemLoop->data(COLUMN_DATA, ROLE_ID).toULongLong() == visibleLobbies[i].lobby_id) break; + + if (i >= size) + { + // Check for participating lobby with public level + // + for (lobbyIt = lobbies.begin(); lobbyIt != lobbies.end(); ++lobbyIt) + if(itemLoop->data(COLUMN_DATA, ROLE_ID).toULongLong() == lobbyIt->lobby_id) + break; + + if (lobbyIt == lobbies.end()) + { + delete(lobby_item->takeChild(lobby_item->indexOfChild(itemLoop))); + childCnt = lobby_item->childCount(); + continue; } } - - if (lobbyIt == lobbies.end()) { - delete(publicLobbyItem->takeChild(publicLobbyItem->indexOfChild(itemLoop))); - childCount = publicLobbyItem->childCount(); - continue; - } } + childIndex++; } - childIndex++; } - for (i = 0; i < size; ++i) { - const PublicChatLobbyRecord &lobby = publicLobbies[i]; + // Now add visible lobbies + // + for (i = 0; i < size; ++i) + { + const VisibleChatLobbyRecord &lobby = visibleLobbies[i]; #ifdef CHAT_LOBBY_GUI_DEBUG - std::cerr << "adding " << lobby.lobby_name << "topic " << lobby.lobby_topic << " #" << std::hex << lobby.lobby_id << std::dec << " public " << lobby.total_number_of_peers << " peers." << std::endl; + std::cerr << "adding " << lobby.lobby_name << "topic " << lobby.lobby_topic << " #" << std::hex << lobby.lobby_id << std::dec << " public " << lobby.total_number_of_peers << " peers. Lobby type: " << lobby.lobby_privacy_level << std::endl; #endif QTreeWidgetItem *item = NULL; + QTreeWidgetItem *lobby_item = (visibleLobbies[i].lobby_privacy_level == RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC)?publicLobbyItem:privateLobbyItem ; - // search existing item - childCount = publicLobbyItem->childCount(); - for (childIndex = 0; childIndex < childCount; childIndex++) { - QTreeWidgetItem *itemLoop = publicLobbyItem->child(childIndex); + // Search existing item + // + int childCnt = lobby_item->childCount(); + for (int childIndex = 0; childIndex < childCnt; childIndex++) + { + QTreeWidgetItem *itemLoop = lobby_item->child(childIndex); if (itemLoop->type() == TYPE_LOBBY && itemLoop->data(COLUMN_DATA, ROLE_ID).toULongLong() == lobby.lobby_id) { item = itemLoop; break; @@ -223,10 +235,13 @@ void ChatLobbyWidget::updateDisplay() if (item == NULL) { item = new RSTreeWidgetItem(compareRole, TYPE_LOBBY); - publicLobbyItem->addChild(item); + lobby_item->addChild(item); } - item->setIcon(COLUMN_NAME, QIcon(IMAGE_PUBLIC)); + if(lobby_item == publicLobbyItem) + item->setIcon(COLUMN_NAME, QIcon(IMAGE_PUBLIC)); + else + item->setIcon(COLUMN_NAME, QIcon(IMAGE_PRIVATE)); bool subscribed = false; if (rsMsgs->getVirtualPeerId(lobby.lobby_id, vpid)) { @@ -236,29 +251,10 @@ void ChatLobbyWidget::updateDisplay() updateItem(item, lobby.lobby_id, lobby.lobby_name,lobby.lobby_topic, lobby.total_number_of_peers, subscribed); } - // remove not existing private lobbies - childCount = privateLobbyItem->childCount(); - childIndex = 0; - while (childIndex < childCount) { - QTreeWidgetItem *itemLoop = privateLobbyItem->child(childIndex); - if (itemLoop->type() == TYPE_LOBBY) { - for (lobbyIt = lobbies.begin(); lobbyIt != lobbies.end(); ++lobbyIt) { - if (lobbyIt->lobby_privacy_level == RS_CHAT_LOBBY_PRIVACY_LEVEL_PRIVATE && - itemLoop->data(COLUMN_DATA, ROLE_ID).toULongLong() == lobbyIt->lobby_id) { - break; - } - } - - if (lobbyIt == lobbies.end()) { - delete(privateLobbyItem->takeChild(privateLobbyItem->indexOfChild(itemLoop))); - childCount = privateLobbyItem->childCount(); - continue; - } - } - childIndex++; - } - - for (lobbyIt = lobbies.begin(); lobbyIt != lobbies.end(); ++lobbyIt) { + // Now add participating lobbies. + // + for (lobbyIt = lobbies.begin(); lobbyIt != lobbies.end(); ++lobbyIt) + { const ChatLobbyInfo &lobby = *lobbyIt; #ifdef CHAT_LOBBY_GUI_DEBUG @@ -275,8 +271,8 @@ void ChatLobbyWidget::updateDisplay() QTreeWidgetItem *item = NULL; // search existing item - childCount = itemParent->childCount(); - for (childIndex = 0; childIndex < childCount; childIndex++) { + int childCount = itemParent->childCount(); + for (int childIndex = 0; childIndex < childCount; childIndex++) { QTreeWidgetItem *itemLoop = itemParent->child(childIndex); if (itemLoop->type() == TYPE_LOBBY && itemLoop->data(COLUMN_DATA, ROLE_ID).toULongLong() == lobby.lobby_id) { item = itemLoop; @@ -318,7 +314,7 @@ static void subscribeLobby(QTreeWidgetItem *item) } ChatLobbyId id = item->data(COLUMN_DATA, ROLE_ID).toULongLong(); - if (rsMsgs->joinPublicChatLobby(id)) { + if (rsMsgs->joinVisibleChatLobby(id)) { std::string vpeer_id; if (rsMsgs->getVirtualPeerId(id, vpeer_id)) { ChatDialog::chatFriend(vpeer_id) ;