added selection of which identity we talk as when multiple GXS identities are available

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7691 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2014-11-18 15:55:31 +00:00
parent 5b3872a041
commit 06065ef623
6 changed files with 60 additions and 26 deletions

View file

@ -501,8 +501,6 @@ void DistantChatService::handleRecvDHPublicKey(RsChatDHPublicKeyItem *item)
// Looks for the DH params. If not there yet, create them. // Looks for the DH params. If not there yet, create them.
// //
bool should_send = false ;
int size = DH_size(it->second.dh) ; int size = DH_size(it->second.dh) ;
unsigned char *key_buff = new unsigned char[size] ; unsigned char *key_buff = new unsigned char[size] ;
@ -777,31 +775,39 @@ void DistantChatService::sendTurtleData(RsChatItem *item)
mTurtle->sendTurtleData(virtual_peer_id,gitem) ; mTurtle->sendTurtleData(virtual_peer_id,gitem) ;
} }
bool DistantChatService::initiateDistantChatConnexion(const RsGxsId& gxs_id,uint32_t& error_code) bool DistantChatService::initiateDistantChatConnexion(const RsGxsId& to_gxs_id,const RsGxsId& from_gxs_id,uint32_t& error_code)
{ {
TurtleFileHash hash = hashFromGxsId(gxs_id) ; TurtleFileHash hash = hashFromGxsId(to_gxs_id) ;
// should be a parameter. // should be a parameter.
std::list<RsGxsId> lst ; std::list<RsGxsId> lst ;
mIdService->getOwnIds(lst) ; mIdService->getOwnIds(lst) ;
if(lst.empty()) bool found = false ;
for(std::list<RsGxsId>::const_iterator it = lst.begin();it!=lst.end();++it)
if(*it == from_gxs_id)
{ {
std::cerr << " (EE) Cannot start distant chat, since no GXS id is available." << std::endl; found=true;
break ;
}
if(!found)
{
std::cerr << " (EE) Cannot start distant chat, since GXS id " << from_gxs_id << " is not available." << std::endl;
return false ; return false ;
} }
RsGxsId own_gxs_id = lst.front() ; RsGxsId own_gxs_id = from_gxs_id ;
// //
startClientDistantChatConnection(hash,gxs_id,own_gxs_id) ; startClientDistantChatConnection(hash,to_gxs_id,own_gxs_id) ;
error_code = RS_DISTANT_CHAT_ERROR_NO_ERROR ; error_code = RS_DISTANT_CHAT_ERROR_NO_ERROR ;
// spawn a status item so as to open the chat window. // spawn a status item so as to open the chat window.
RsChatMsgItem *item = new RsChatMsgItem; RsChatMsgItem *item = new RsChatMsgItem;
item->message = "Starting distant chat. Please wait for secure tunnel to be established." ; item->message = "[Starting distant chat. Please wait for secure tunnel to be established.]" ;
item->chatFlags = RS_CHAT_FLAG_PRIVATE ; item->chatFlags = RS_CHAT_FLAG_PRIVATE ;
item->PeerId(RsPeerId(gxs_id)) ; item->PeerId(RsPeerId(to_gxs_id)) ;
handleRecvChatMsgItem(item) ; handleRecvChatMsgItem(item) ;
return true ; return true ;

View file

@ -50,7 +50,7 @@ public:
// Creates the invite if the public key of the distant peer is available. // Creates the invite if the public key of the distant peer is available.
// Om success, stores the invite in the map above, so that we can respond to tunnel requests. // Om success, stores the invite in the map above, so that we can respond to tunnel requests.
// //
bool initiateDistantChatConnexion(const RsGxsId& gxs_id,uint32_t& error_code) ; bool initiateDistantChatConnexion(const RsGxsId& to_gxs_id,const RsGxsId &from_gxs_id, uint32_t &error_code) ;
bool closeDistantChatConnexion(const RsGxsId& pid) ; bool closeDistantChatConnexion(const RsGxsId& pid) ;
virtual bool getDistantChatStatus(const RsGxsId &gxs_id,uint32_t &status) ; virtual bool getDistantChatStatus(const RsGxsId &gxs_id,uint32_t &status) ;

View file

@ -425,7 +425,7 @@ virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::str
/* Distant chat */ /* Distant chat */
/****************************************/ /****************************************/
virtual bool initiateDistantChatConnexion(const RsGxsId& pid,uint32_t& error_code) = 0; virtual bool initiateDistantChatConnexion(const RsGxsId& to_pid,const RsGxsId& from_pid,uint32_t& error_code) = 0;
virtual bool getDistantChatStatus(const RsGxsId& gxs_id,uint32_t& status) = 0; virtual bool getDistantChatStatus(const RsGxsId& gxs_id,uint32_t& status) = 0;
virtual bool closeDistantChatConnexion(const RsGxsId& pid) = 0; virtual bool closeDistantChatConnexion(const RsGxsId& pid) = 0;

View file

@ -364,9 +364,9 @@ void p3Msgs::getPendingChatLobbyInvites(std::list<ChatLobbyInvite>& invites)
{ {
mChatSrv->getPendingChatLobbyInvites(invites) ; mChatSrv->getPendingChatLobbyInvites(invites) ;
} }
bool p3Msgs::initiateDistantChatConnexion(const RsGxsId& gxs_id,uint32_t& error_code) bool p3Msgs::initiateDistantChatConnexion(const RsGxsId& to_gxs_id,const RsGxsId& from_gxs_id,uint32_t& error_code)
{ {
return mChatSrv->initiateDistantChatConnexion(gxs_id,error_code) ; return mChatSrv->initiateDistantChatConnexion(to_gxs_id,from_gxs_id,error_code) ;
} }
bool p3Msgs::getDistantChatStatus(const RsGxsId &gxs_id,uint32_t &status) bool p3Msgs::getDistantChatStatus(const RsGxsId &gxs_id,uint32_t &status)
{ {

View file

@ -196,7 +196,7 @@ class p3Msgs: public RsMsgs
virtual bool getLobbyAutoSubscribe(const ChatLobbyId& lobby_id); virtual bool getLobbyAutoSubscribe(const ChatLobbyId& lobby_id);
virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::string& lobby_topic,const std::list<RsPeerId>& invited_friends,uint32_t privacy_type) ; virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::string& lobby_topic,const std::list<RsPeerId>& invited_friends,uint32_t privacy_type) ;
virtual bool initiateDistantChatConnexion(const RsGxsId& gxs_id,uint32_t& error_code) ; virtual bool initiateDistantChatConnexion(const RsGxsId& to_gxs_id,const RsGxsId& from_gxs_id,uint32_t& error_code) ;
virtual bool getDistantChatStatus(const RsGxsId& gxs_id,uint32_t& status) ; virtual bool getDistantChatStatus(const RsGxsId& gxs_id,uint32_t& status) ;
virtual bool closeDistantChatConnexion(const RsGxsId &pid) ; virtual bool closeDistantChatConnexion(const RsGxsId &pid) ;

View file

@ -902,7 +902,30 @@ void IdDialog::IdListCustomPopupMenu( QPoint )
contextMnu.addAction(ui.editIdentity); contextMnu.addAction(ui.editIdentity);
contextMnu.addAction(ui.removeIdentity); contextMnu.addAction(ui.removeIdentity);
contextMnu.addAction(ui.chatIdentity);
std::list<RsGxsId> own_identities ;
rsIdentity->getOwnIds(own_identities) ;
if(own_identities.size() == 1)
{
QAction * action = contextMnu.addAction(QIcon(),"Chat with this peer",this,SLOT(chatIdentity()));
action->setData(QString::fromStdString((own_identities.front()).toStdString())) ;
}
else
{
QMenu *mnu = contextMnu.addMenu("Chat with this peer as...") ;
for(std::list<RsGxsId>::const_iterator it=own_identities.begin();it!=own_identities.end();++it)
{
RsIdentityDetails idd ;
rsIdentity->getIdDetails(*it,idd) ;
QPixmap pixmap = QPixmap::fromImage(GxsIdDetails::makeDefaultIcon(*it)) ;
QAction * action = mnu->addAction(QIcon(pixmap),QString::fromStdString(idd.mNickname) + " (" + QString::fromStdString((*it).toStdString())+ ")",this,SLOT(chatIdentity()));
action->setData(QString::fromStdString((*it).toStdString())) ;
}
}
contextMnu.exec(QCursor::pos()); contextMnu.exec(QCursor::pos());
} }
@ -919,10 +942,15 @@ void IdDialog::chatIdentity()
std::string keyId = item->text(RSID_COL_KEYID).toStdString(); std::string keyId = item->text(RSID_COL_KEYID).toStdString();
QAction *action = qobject_cast<QAction *>(QObject::sender());
if (!action)
return ;
RsGxsId from_gxs_id(action->data().toString().toStdString());
uint32_t error_code ; uint32_t error_code ;
if(!rsMsgs->initiateDistantChatConnexion(RsGxsId(keyId), error_code)) if(!rsMsgs->initiateDistantChatConnexion(RsGxsId(keyId), from_gxs_id, error_code))
QMessageBox::information(NULL,"Distant cannot work","Distant chat refused with this peer. Reason: "+QString::number(error_code)) ; QMessageBox::information(NULL,"Distant chat cannot work","Distant chat refused with this peer. Error code: "+QString::number(error_code)) ;
} }