Merge pull request #952 from PhenomRetroShare/Fix_LobbyAutoSubscribe

Fix Lobby auto-subscribe.
This commit is contained in:
csoler 2017-07-19 18:37:23 +02:00 committed by GitHub
commit d60bb781b8
3 changed files with 118 additions and 33 deletions

View File

@ -23,8 +23,9 @@
*
*/
#include <sstream>
#include <iomanip>
#include <math.h>
#include <sstream>
#include <unistd.h>
#include "util/rsprint.h"
@ -536,6 +537,7 @@ void DistributedChatService::handleRecvChatLobbyList(RsChatLobbyListItem *item)
std::cerr << " lobby is flagged as autosubscribed. Adding it to subscribe list." << std::endl;
#endif
ChatLobbyId clid = item->lobbies[i].id;
if(_chat_lobbys.find(clid) == _chat_lobbys.end())
chatLobbyToSubscribe.push_back(clid);
}
@ -556,7 +558,35 @@ void DistributedChatService::handleRecvChatLobbyList(RsChatLobbyListItem *item)
std::list<ChatLobbyId>::iterator it;
for (it = chatLobbyToSubscribe.begin(); it != chatLobbyToSubscribe.end(); ++it)
joinVisibleChatLobby(*it,_default_identity);
{
RsGxsId gxsId = _lobby_default_identity[*it];
if (gxsId.isNull())
gxsId = _default_identity;
//Check if gxsId can connect to this lobby
ChatLobbyFlags flags(0);
std::map<ChatLobbyId,VisibleChatLobbyRecord>::const_iterator vlIt = _visible_lobbies.find(*it) ;
if(vlIt != _visible_lobbies.end())
flags = vlIt->second.lobby_flags;
else
{
std::map<ChatLobbyId,ChatLobbyEntry>::const_iterator clIt = _chat_lobbys.find(*it) ;
if(clIt != _chat_lobbys.end())
flags = clIt->second.lobby_flags;
}
RsIdentityDetails idd ;
if(IS_PGP_SIGNED_LOBBY(flags)
&& (!rsIdentity->getIdDetails(gxsId,idd)
|| !(idd.mFlags & RS_IDENTITY_FLAGS_PGP_LINKED)) )
{
std::cerr << "(EE) Attempt to auto-subscribe to signed lobby with non signed Id. Remove it." << std::endl;
setLobbyAutoSubscribe(*it, false);
} else {
joinVisibleChatLobby(*it,gxsId);
}
}
for(std::list<ChatLobbyId>::const_iterator it = invitationNeeded.begin();it!=invitationNeeded.end();++it)
invitePeerToLobby(*it,item->PeerId(),false) ;
@ -1765,10 +1795,15 @@ bool DistributedChatService::setIdentityForChatLobby(const ChatLobbyId& lobby_id
void DistributedChatService::setLobbyAutoSubscribe(const ChatLobbyId& lobby_id, const bool autoSubscribe)
{
if(autoSubscribe)
if(autoSubscribe){
_known_lobbies_flags[lobby_id] |= RS_CHAT_LOBBY_FLAGS_AUTO_SUBSCRIBE;
else
RsGxsId gxsId;
if (getIdentityForChatLobby(lobby_id, gxsId))
_lobby_default_identity[lobby_id] = gxsId;
} else {
_known_lobbies_flags[lobby_id] &= ~RS_CHAT_LOBBY_FLAGS_AUTO_SUBSCRIBE ;
_lobby_default_identity.erase(lobby_id);
}
RsServer::notify()->notifyListChange(NOTIFY_LIST_CHAT_LOBBY_LIST, NOTIFY_TYPE_ADD) ;
triggerConfigSave();
@ -1899,23 +1934,46 @@ void DistributedChatService::addToSaveList(std::list<RsItem*>& list) const
list.push_back(clci) ;
}
/* Save Default Nick Name */
/* Save Default Nick Name */
{
RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ;
RsTlvKeyValue kv;
kv.key = "DEFAULT_IDENTITY";
kv.value = _default_identity.toStdString();
vitem->tlvkvs.pairs.push_back(kv);
list.push_back(vitem);
}
/* Save Default Nick Name by Lobby*/
for(std::map<ChatLobbyId,RsGxsId>::const_iterator it=_lobby_default_identity.begin(); it!=_lobby_default_identity.end(); ++it)
{
RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ;
ChatLobbyId cli = it->first;
RsGxsId gxsId = it->second;
std::stringstream stream;
stream << std::setfill ('0') << std::setw(sizeof(ChatLobbyId)*2)
<< std::hex << cli;
std::string strCli( stream.str() );
RsTlvKeyValue kv;
kv.key = "LOBBY_DEFAULT_IDENTITY:"+strCli;
kv.value = gxsId.toStdString();
vitem->tlvkvs.pairs.push_back(kv);
list.push_back(vitem);
}
}
bool DistributedChatService::processLoadListItem(const RsItem *item)
{
const RsConfigKeyValueSet *vitem = NULL;
const std::string strldID = "LOBBY_DEFAULT_IDENTITY:";
if(NULL != (vitem = dynamic_cast<const RsConfigKeyValueSet*>(item)))
for(std::list<RsTlvKeyValue>::const_iterator kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); ++kit)
{
if( kit->key == "DEFAULT_IDENTITY" )
{
#ifdef DEBUG_CHAT_LOBBIES
@ -1931,6 +1989,31 @@ bool DistributedChatService::processLoadListItem(const RsItem *item)
return true;
}
if( kit->key.compare(0, strldID.length(), strldID) == 0)
{
#ifdef DEBUG_CHAT_LOBBIES
std::cerr << "Loaded config lobby default nick name: " << kit->key << " " << kit->value << std::endl ;
#endif
std::string strCli = kit->key.substr(strldID.length());
std::stringstream stream;
stream << std::hex << strCli;
ChatLobbyId cli = 0;
stream >> cli;
if (!kit->value.empty() && (cli != 0))
{
RsGxsId gxsId(kit->value);
if (gxsId.isNull())
std::cerr << "ERROR: lobby default identity is malformed." << std::endl;
else
_lobby_default_identity[cli] = gxsId ;
}
return true;
}
}
const RsChatLobbyConfigItem *clci = NULL ;
if(NULL != (clci = dynamic_cast<const RsChatLobbyConfigItem*>(item)))

View File

@ -159,6 +159,7 @@ class DistributedChatService
time_t last_visible_lobby_info_request_time ; // allows to ask for updates
bool _should_reset_lobby_counts ;
RsGxsId _default_identity;
std::map<ChatLobbyId,RsGxsId> _lobby_default_identity;
uint32_t mServType ;
RsMutex mDistributedChatMtx ;

View File

@ -820,7 +820,8 @@ void ChatLobbyWidget::autoSubscribeLobby(QTreeWidgetItem *item)
ChatLobbyId id = item->data(COLUMN_DATA, ROLE_ID).toULongLong();
bool isAutoSubscribe = rsMsgs->getLobbyAutoSubscribe(id);
rsMsgs->setLobbyAutoSubscribe(id, !isAutoSubscribe);
if (!isAutoSubscribe) subscribeChatLobbyAtItem(item);
if (!isAutoSubscribe && !item->data(COLUMN_DATA, ROLE_SUBSCRIBED).toBool())
subscribeChatLobbyAtItem(item);
}
void ChatLobbyWidget::showBlankPage(ChatLobbyId id)