diff --git a/libretroshare/src/chat/distantchat.cc b/libretroshare/src/chat/distantchat.cc index c72c13e12..7169cf575 100644 --- a/libretroshare/src/chat/distantchat.cc +++ b/libretroshare/src/chat/distantchat.cc @@ -83,7 +83,7 @@ bool DistantChatService::handleRecvItem(RsChatItem *item) bool DistantChatService::handleOutgoingItem(RsChatItem *item) { for(std::map::const_iterator it=_distant_chat_peers.begin();it!=_distant_chat_peers.end();++it) - if( it->second.virtual_peer_id == item->PeerId()) + if( it->second.gxs_id == RsGxsId(item->PeerId())) { #ifdef CHAT_DEBUG std::cerr << "p3ChatService::sendPrivateChatItem(): sending to " << item->PeerId() << ": interpreted as a distant chat virtual peer id." << std::endl; @@ -98,7 +98,7 @@ bool DistantChatService::handleOutgoingItem(RsChatItem *item) void DistantChatService::handleRecvChatStatusItem(RsChatStatusItem *cs) { if(cs->flags & RS_CHAT_FLAG_CLOSING_DISTANT_CONNECTION) - markDistantChatAsClosed(cs->PeerId()) ; + markDistantChatAsClosed(RsGxsId(cs->PeerId())) ; } bool DistantChatService::getHashFromVirtualPeerId(const TurtleVirtualPeerId& vpid,TurtleFileHash& hash) @@ -173,28 +173,28 @@ void DistantChatService::addVirtualPeer(const TurtleFileHash& hash,const TurtleV } if(dir == RsTurtleGenericTunnelItem::DIRECTION_CLIENT) - { - RsStackMutex stack(mDistantChatMtx); /********** STACK LOCKED MTX ******/ + { + RsStackMutex stack(mDistantChatMtx); /********** STACK LOCKED MTX ******/ #ifdef DEBUG_DISTANT_CHAT - std::cerr << " Side is in direction to client." << std::endl; - std::cerr << " Initing encryption parameters from existing distant chat invites." << std::endl; + std::cerr << " Side is in direction to client." << std::endl; + std::cerr << " Initing encryption parameters from existing distant chat invites." << std::endl; #endif - RsGxsId own_gxs_id ; - std::list own_id_list ; - rsIdentity->getOwnIds(own_id_list) ; + RsGxsId own_gxs_id ; + std::list own_id_list ; + rsIdentity->getOwnIds(own_id_list) ; - for(std::list::const_iterator it(own_id_list.begin());it!=own_id_list.end();++it) - if(hashFromGxsId(*it) == hash) - { - own_gxs_id = *it ; - break ; - } - if(own_gxs_id.isNull()) - { - std::cerr << "DistantChatService::addVirtualPeer(): cannot find GXS id for hash " << hash << ". This is probably a bug" << std::endl; - return ; - } + for(std::list::const_iterator it(own_id_list.begin());it!=own_id_list.end();++it) + if(hashFromGxsId(*it) == hash) + { + own_gxs_id = *it ; + break ; + } + if(own_gxs_id.isNull()) + { + std::cerr << "DistantChatService::addVirtualPeer(): cannot find GXS id for hash " << hash << ". This is probably a bug" << std::endl; + return ; + } // make sure the DH session does not already exist. If so, remove it. std::map::iterator it = _distant_chat_peers.find(hash) ; @@ -208,17 +208,17 @@ void DistantChatService::addVirtualPeer(const TurtleFileHash& hash,const TurtleV } DistantChatPeerInfo info ; - info.last_contact = now ; - info.status = RS_DISTANT_CHAT_STATUS_TUNNEL_OK ; - info.virtual_peer_id = virtual_peer_id ; - info.gxs_id.clear() ; // unknown yet! - info.direction = dir ; - info.own_gxs_id = own_gxs_id ; - info.dh = NULL ; - memset(info.aes_key,0,DISTANT_CHAT_AES_KEY_SIZE) ; + info.last_contact = now ; + info.status = RS_DISTANT_CHAT_STATUS_TUNNEL_OK ; + info.virtual_peer_id = virtual_peer_id ; + info.gxs_id.clear() ; // unknown yet! + info.direction = dir ; + info.own_gxs_id = own_gxs_id ; + info.dh = NULL ; + memset(info.aes_key,0,DISTANT_CHAT_AES_KEY_SIZE) ; - _distant_chat_peers[hash] = info ; - } + _distant_chat_peers[hash] = info ; + } { // Start a new DH session for this tunnel @@ -290,7 +290,7 @@ static void printBinaryData(void *data,uint32_t size) #endif void DistantChatService::receiveTurtleData( RsTurtleGenericTunnelItem *gitem,const RsFileHash& hash, - const RsPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) + const RsPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) { #ifdef DEBUG_DISTANT_CHAT std::cerr << "DistantChatService::receiveTurtleData(): Received turtle data. " << std::endl; @@ -316,7 +316,8 @@ void DistantChatService::receiveTurtleData( RsTurtleGenericTunnelItem *gitem,con std::cerr << std::endl; #endif - uint8_t aes_key[DISTANT_CHAT_AES_KEY_SIZE] ; + uint8_t aes_key[DISTANT_CHAT_AES_KEY_SIZE] ; + RsGxsId gxs_id ; { RsStackMutex stack(mDistantChatMtx); /********** STACK LOCKED MTX ******/ @@ -329,7 +330,8 @@ void DistantChatService::receiveTurtleData( RsTurtleGenericTunnelItem *gitem,con } it->second.last_contact = time(NULL) ; memcpy(aes_key,it->second.aes_key,DISTANT_CHAT_AES_KEY_SIZE) ; - it->second.status = RS_DISTANT_CHAT_STATUS_CAN_TALK ; + it->second.status = RS_DISTANT_CHAT_STATUS_CAN_TALK ; + gxs_id = it->second.gxs_id ; } // Call the AES crypto module @@ -389,7 +391,18 @@ void DistantChatService::receiveTurtleData( RsTurtleGenericTunnelItem *gitem,con // Setup the virtual peer to be the origin, and pass it on. // - citem->PeerId(virtualPeerIdFromHash(hash)) ; +#ifdef DEBUG_DISTANT_CHAT + std::cerr << "(II) Setting peer id to " << decrypted_size << std::endl; +#endif + + // DH key items are sent even before we know who we speak to, so the virtual peer id is used in this + // case only. + + if(dynamic_cast(citem) != NULL) + citem->PeerId(virtual_peer_id) ; + else + citem->PeerId(RsPeerId(gxs_id)) ; + //RsServer::notify()->notifyPeerStatusChanged(hash,RS_STATUS_ONLINE) ; handleIncomingItem(citem) ; // Treats the item, and deletes it @@ -407,7 +420,7 @@ void DistantChatService::handleRecvDHPublicKey(RsChatDHPublicKeyItem *item) TurtleVirtualPeerId vpid = item->PeerId() ; TurtleFileHash hash ; - if(getHashFromVirtualPeerId(vpid,hash)) + if(getHashFromVirtualPeerId(vpid,hash)) { #ifdef DEBUG_DISTANT_CHAT std::cerr << " hash = " << hash << std::endl; @@ -525,9 +538,9 @@ void DistantChatService::handleRecvDHPublicKey(RsChatDHPublicKeyItem *item) RsChatStatusItem *cs = new RsChatStatusItem ; - cs->status_string = "Tunnel is secured with PFS session. You can talk!" ; + cs->status_string = "Tunnel is secured with PFS session. ACK received. You can talk!" ; cs->flags = RS_CHAT_FLAG_PRIVATE | RS_CHAT_FLAG_ACK_DISTANT_CONNECTION; - cs->PeerId(vpid); + cs->PeerId(RsPeerId(senders_id)); pendingDistantChatItems.push_back(cs) ; @@ -597,7 +610,7 @@ bool DistantChatService::locked_sendDHPublicKey(const DistantChatPeerInfo& pinfo dhitem->signature = signature ; dhitem->gxs_key = signature_key_public ; - dhitem->PeerId(pinfo.virtual_peer_id) ; + dhitem->PeerId(RsPeerId(pinfo.gxs_id)) ; #ifdef DEBUG_DISTANT_CHAT std::cerr << " Pushing DH session key item to pending distant messages..." << std::endl; @@ -668,15 +681,8 @@ void DistantChatService::sendTurtleData(RsChatItem *item) uint8_t aes_key[DISTANT_CHAT_AES_KEY_SIZE] ; - TurtleVirtualPeerId virtual_peer_id = item->PeerId(); - RsFileHash hash ; - - if(!getHashFromVirtualPeerId(item->PeerId(),hash)) - { - std::cerr << "Cannot get hash from virtual peer id " << item->PeerId() << ". Dropping the chat message." << std::endl; - delete[] buff ; - return ; - } + TurtleFileHash hash = hashFromGxsId(RsGxsId(item->PeerId())) ; + TurtleVirtualPeerId virtual_peer_id ; { RsStackMutex stack(mDistantChatMtx); /********** STACK LOCKED MTX ******/ @@ -684,12 +690,13 @@ void DistantChatService::sendTurtleData(RsChatItem *item) if(it == _distant_chat_peers.end()) { - std::cerr << "(EE) item is not going into a registered tunnel. Weird. peer id = " << item->PeerId() << std::endl; + std::cerr << "(EE) No distant chat info for peer id = " << item->PeerId() << ". Dropping the item!" << std::endl; delete[] buff ; return ; } it->second.last_contact = time(NULL) ; - memcpy(aes_key,it->second.aes_key,DISTANT_CHAT_AES_KEY_SIZE) ; + memcpy(aes_key,it->second.aes_key,DISTANT_CHAT_AES_KEY_SIZE) ; + virtual_peer_id = it->second.virtual_peer_id ; } #ifdef DEBUG_DISTANT_CHAT std::cerr << "DistantChatService::sendTurtleData(): tunnel found. Encrypting data." << std::endl; @@ -750,7 +757,6 @@ void DistantChatService::sendTurtleData(RsChatItem *item) bool DistantChatService::initiateDistantChatConnexion(const RsGxsId& gxs_id,uint32_t& error_code) { - //pid = DistantChatPeerId(gxs_id) ; // the two ids have the same size. Still, I prefer to have 2 different types. TurtleFileHash hash = hashFromGxsId(gxs_id) ; // should be a parameter. @@ -799,43 +805,42 @@ void DistantChatService::startClientDistantChatConnection(const RsFileHash& hash mTurtle->monitorTunnels(hash,this) ; } -DistantChatPeerId DistantChatService::virtualPeerIdFromHash(const TurtleFileHash& hash) -{ - RsStackMutex stack(mDistantChatMtx); /********** STACK LOCKED MTX ******/ - - std::map::const_iterator it = _distant_chat_peers.find(hash) ; - - if(it == _distant_chat_peers.end()) - { - std::cerr << " (EE) Cannot find hash " << hash << " in distant peers list. Virtual peer id cannot be returned." << std::endl; - return DistantChatPeerId() ; - } - else - return it->second.virtual_peer_id ; -} +// DistantChatPeerId DistantChatService::virtualPeerIdFromHash(const TurtleFileHash& hash) +// { +// RsStackMutex stack(mDistantChatMtx); /********** STACK LOCKED MTX ******/ +// +// std::map::const_iterator it = _distant_chat_peers.find(hash) ; +// +// if(it == _distant_chat_peers.end()) +// { +// std::cerr << " (EE) Cannot find hash " << hash << " in distant peers list. Virtual peer id cannot be returned." << std::endl; +// return DistantChatPeerId() ; +// } +// else +// return it->second.virtual_peer_id ; +// } TurtleFileHash DistantChatService::hashFromGxsId(const RsGxsId& gid) { - if(DistantChatPeerId::SIZE_IN_BYTES > Sha1CheckSum::SIZE_IN_BYTES) + if(RsGxsId::SIZE_IN_BYTES > Sha1CheckSum::SIZE_IN_BYTES) std::cerr << __PRETTY_FUNCTION__ << ": Serious inconsistency error." << std::endl; - assert(Sha1CheckSum::SIZE_IN_BYTES >= DistantChatPeerId::SIZE_IN_BYTES) ; - unsigned char tmp[Sha1CheckSum::SIZE_IN_BYTES] ; - memset(tmp,0,Sha1CheckSum::SIZE_IN_BYTES) ; - memcpy(tmp,gid.toByteArray(),DistantChatPeerId::SIZE_IN_BYTES) ; + assert(Sha1CheckSum::SIZE_IN_BYTES >= RsGxsId::SIZE_IN_BYTES) ; - return Sha1CheckSum(tmp); + unsigned char tmp[Sha1CheckSum::SIZE_IN_BYTES] ; + memset(tmp,0,Sha1CheckSum::SIZE_IN_BYTES) ; + memcpy(tmp,gid.toByteArray(),RsGxsId::SIZE_IN_BYTES) ; + + return Sha1CheckSum(tmp); } -bool DistantChatService::getDistantChatStatus(const DistantChatPeerId& pid,RsGxsId& gxs_id,uint32_t& status) +bool DistantChatService::getDistantChatStatus(const RsGxsId& gxs_id,uint32_t& status) { RsStackMutex stack(mDistantChatMtx); /********** STACK LOCKED MTX ******/ for(std::map::const_iterator it = _distant_chat_peers.begin() ; it != _distant_chat_peers.end();++it) - if(it->second.virtual_peer_id == pid) + if(it->second.gxs_id == gxs_id) { status = it->second.status ; - gxs_id = it->second.gxs_id ; - return true ; } @@ -843,7 +848,7 @@ bool DistantChatService::getDistantChatStatus(const DistantChatPeerId& pid,RsGxs return false ; } -bool DistantChatService::closeDistantChatConnexion(const DistantChatPeerId& pid) +bool DistantChatService::closeDistantChatConnexion(const RsGxsId& pid) { // two cases: // - client needs to stop asking for tunnels => remove the hash from the list of tunnelled files @@ -858,7 +863,7 @@ bool DistantChatService::closeDistantChatConnexion(const DistantChatPeerId& pid) RsStackMutex stack(mDistantChatMtx); /********** STACK LOCKED MTX ******/ for(std::map::const_iterator it = _distant_chat_peers.begin() ; it != _distant_chat_peers.end();++it) - if(it->second.virtual_peer_id == pid) + if(it->second.gxs_id == pid) { if(it->second.direction == RsTurtleGenericTunnelItem::DIRECTION_SERVER) is_client = true ; @@ -869,51 +874,51 @@ bool DistantChatService::closeDistantChatConnexion(const DistantChatPeerId& pid) if(virtual_peer_id.isNull()) { - std::cerr << "Cannot close chat associated to virtual peer id " << pid << ": not found." << std::endl; + std::cerr << "Cannot close chat associated to GXS Id " << pid << ": not found." << std::endl; return false ; } } if(is_client) - { - // send a status item saying that we're closing the connection + { + // send a status item saying that we're closing the connection - RsChatStatusItem *cs = new RsChatStatusItem ; + RsChatStatusItem *cs = new RsChatStatusItem ; - cs->status_string = "" ; - cs->flags = RS_CHAT_FLAG_PRIVATE | RS_CHAT_FLAG_CLOSING_DISTANT_CONNECTION; - cs->PeerId(virtual_peer_id); + cs->status_string = "" ; + cs->flags = RS_CHAT_FLAG_PRIVATE | RS_CHAT_FLAG_CLOSING_DISTANT_CONNECTION; + cs->PeerId(RsPeerId(pid)); - sendTurtleData(cs) ; // that needs to be done off-mutex! + sendTurtleData(cs) ; // that needs to be done off-mutex and before we close the tunnel. - RsStackMutex stack(mDistantChatMtx); /********** STACK LOCKED MTX ******/ + RsStackMutex stack(mDistantChatMtx); /********** STACK LOCKED MTX ******/ std::map::iterator it = _distant_chat_peers.find(hash) ; - if(it == _distant_chat_peers.end()) // server side. Nothing to do. - { - std::cerr << "Cannot close chat associated to hash " << hash << ": not found." << std::endl; - return false ; - } - // Client side: Stop tunnels - // - std::cerr << "This is client side. Stopping tunnel manageement for hash " << hash << std::endl; - mTurtle->stopMonitoringTunnels(hash) ; + if(it == _distant_chat_peers.end()) // server side. Nothing to do. + { + std::cerr << "Cannot close chat associated to hash " << hash << ": not found." << std::endl; + return false ; + } + // Client side: Stop tunnels + // + std::cerr << "This is client side. Stopping tunnel manageement for hash " << hash << std::endl; + mTurtle->stopMonitoringTunnels(hash) ; - // and remove hash from list of current peers. + // and remove hash from list of current peers. - DH_free(it->second.dh) ; - _distant_chat_peers.erase(it) ; - } + DH_free(it->second.dh) ; + _distant_chat_peers.erase(it) ; + } return true ; } -void DistantChatService::markDistantChatAsClosed(const TurtleVirtualPeerId& vpid) +void DistantChatService::markDistantChatAsClosed(const RsGxsId& pid) { RsStackMutex stack(mDistantChatMtx); /********** STACK LOCKED MTX ******/ for(std::map::iterator it = _distant_chat_peers.begin();it!=_distant_chat_peers.end();++it) - if(it->second.virtual_peer_id == vpid) + if(it->second.gxs_id == pid) it->second.status = RS_DISTANT_CHAT_STATUS_REMOTELY_CLOSED ; } diff --git a/libretroshare/src/chat/distantchat.h b/libretroshare/src/chat/distantchat.h index b5cf80208..212338435 100644 --- a/libretroshare/src/chat/distantchat.h +++ b/libretroshare/src/chat/distantchat.h @@ -51,8 +51,8 @@ class DistantChatService: public RsTurtleClientService // 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 closeDistantChatConnexion(const DistantChatPeerId& pid) ; - virtual bool getDistantChatStatus(const DistantChatPeerId& hash,RsGxsId& gxs_id,uint32_t& status) ; + bool closeDistantChatConnexion(const RsGxsId& pid) ; + virtual bool getDistantChatStatus(const RsGxsId &gxs_id,uint32_t &status) ; // derived in p3ChatService virtual void handleIncomingItem(RsItem *) = 0; @@ -95,7 +95,7 @@ class DistantChatService: public RsTurtleClientService virtual void receiveTurtleData(RsTurtleGenericTunnelItem *item,const RsFileHash& hash,const RsPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) ; void addVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&,RsTurtleGenericTunnelItem::Direction dir) ; void removeVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&) ; - void markDistantChatAsClosed(const TurtleVirtualPeerId& vpid) ; + void markDistantChatAsClosed(const RsGxsId &vpid) ; void startClientDistantChatConnection(const RsFileHash& hash,const RsGxsId& to_gxs_id,const RsGxsId& from_gxs_id) ; bool getHashFromVirtualPeerId(const TurtleVirtualPeerId& pid,RsFileHash& hash) ; TurtleFileHash hashFromGxsId(const RsGxsId& pid) ; diff --git a/libretroshare/src/chat/p3chatservice.cc b/libretroshare/src/chat/p3chatservice.cc index 65484f342..e3734b7e4 100644 --- a/libretroshare/src/chat/p3chatservice.cc +++ b/libretroshare/src/chat/p3chatservice.cc @@ -272,15 +272,13 @@ void p3ChatService::checkSizeAndSendMessage(RsChatMsgItem *msg) } -bool p3ChatService::isOnline(const DistantChatPeerId& pid) +bool p3ChatService::isOnline(const RsPeerId& pid) { // check if the id is a tunnel id or a peer id. uint32_t status ; - RsGxsId gxs_id ; - std::string hash ; - if(getDistantChatStatus(pid,gxs_id,status)) + if(getDistantChatStatus(RsGxsId(pid),status)) return status == RS_DISTANT_CHAT_STATUS_CAN_TALK ; else return mServiceCtrl->isPeerConnected(getServiceInfo().mServiceType, pid); diff --git a/libretroshare/src/retroshare/rsmsgs.h b/libretroshare/src/retroshare/rsmsgs.h index f156e5d4e..9336bca74 100644 --- a/libretroshare/src/retroshare/rsmsgs.h +++ b/libretroshare/src/retroshare/rsmsgs.h @@ -426,8 +426,8 @@ virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::str /****************************************/ virtual bool initiateDistantChatConnexion(const RsGxsId& pid,uint32_t& error_code) = 0; -virtual bool getDistantChatStatus(const DistantChatPeerId& pid,RsGxsId& gxs_id,uint32_t& status) = 0; -virtual bool closeDistantChatConnexion(const DistantChatPeerId& pid) = 0; +virtual bool getDistantChatStatus(const RsGxsId& gxs_id,uint32_t& status) = 0; +virtual bool closeDistantChatConnexion(const RsGxsId& pid) = 0; }; diff --git a/libretroshare/src/rsserver/p3msgs.cc b/libretroshare/src/rsserver/p3msgs.cc index 3be7d6d11..35fa08f7f 100644 --- a/libretroshare/src/rsserver/p3msgs.cc +++ b/libretroshare/src/rsserver/p3msgs.cc @@ -368,11 +368,11 @@ bool p3Msgs::initiateDistantChatConnexion(const RsGxsId& gxs_id,uint32_t& error_ { return mChatSrv->initiateDistantChatConnexion(gxs_id,error_code) ; } -bool p3Msgs::getDistantChatStatus(const DistantChatPeerId& pid,RsGxsId& gxs_id,uint32_t& status) +bool p3Msgs::getDistantChatStatus(const RsGxsId &gxs_id,uint32_t &status) { - return mChatSrv->getDistantChatStatus(pid,gxs_id,status) ; + return mChatSrv->getDistantChatStatus(gxs_id,status) ; } -bool p3Msgs::closeDistantChatConnexion(const DistantChatPeerId& pid) +bool p3Msgs::closeDistantChatConnexion(const RsGxsId& pid) { return mChatSrv->closeDistantChatConnexion(pid) ; } diff --git a/libretroshare/src/rsserver/p3msgs.h b/libretroshare/src/rsserver/p3msgs.h index 3c644ff7a..0cea676d4 100644 --- a/libretroshare/src/rsserver/p3msgs.h +++ b/libretroshare/src/rsserver/p3msgs.h @@ -197,8 +197,8 @@ class p3Msgs: public RsMsgs virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::string& lobby_topic,const std::list& invited_friends,uint32_t privacy_type) ; virtual bool initiateDistantChatConnexion(const RsGxsId& gxs_id,uint32_t& error_code) ; - virtual bool getDistantChatStatus(const DistantChatPeerId& pid,RsGxsId& gxs_id,uint32_t& status) ; - virtual bool closeDistantChatConnexion(const DistantChatPeerId& pid) ; + virtual bool getDistantChatStatus(const RsGxsId& gxs_id,uint32_t& status) ; + virtual bool closeDistantChatConnexion(const RsGxsId &pid) ; private: diff --git a/retroshare-gui/src/gui/chat/ChatDialog.cpp b/retroshare-gui/src/gui/chat/ChatDialog.cpp index 73d20600f..801b8ad9a 100644 --- a/retroshare-gui/src/gui/chat/ChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/ChatDialog.cpp @@ -98,10 +98,9 @@ void ChatDialog::init(const RsPeerId &peerId, const QString &title) } uint32_t distant_peer_status ; - RsGxsId distant_chat_gxs_id ; - if(rsMsgs->getDistantChatStatus(peerId,distant_chat_gxs_id,distant_peer_status)) - chatflags = RS_CHAT_OPEN | RS_CHAT_FOCUS; // use own flags + if(rsMsgs->getDistantChatStatus(RsGxsId(peerId),distant_peer_status)) + chatflags = RS_CHAT_OPEN | RS_CHAT_FOCUS; // use own flags if (chatflags & RS_CHAT_OPEN) { if (lobby_id) { @@ -118,8 +117,8 @@ void ChatDialog::init(const RsPeerId &peerId, const QString &title) } else if(distant_peer_status > 0) { cd = new PopupDistantChatDialog(); chatDialogs[peerId] = cd; - QString peer_name = cd->getPeerName(peerId) ; - cd->init(peerId, tr("Talking to ")+peer_name+" (GXS id="+QString::fromStdString(distant_chat_gxs_id.toStdString())+")") ; + QString peer_name = cd->getPeerName(peerId) ; + cd->init(peerId, tr("Talking to ")+peer_name+" (GXS id="+QString::fromStdString(peerId.toStdString())+")") ; } else { RsPeerDetails sslDetails; @@ -210,10 +209,9 @@ void ChatDialog::init(const RsPeerId &peerId, const QString &title) return; } - RsGxsId distant_chat_gxs_id ; uint32_t distant_peer_status ; - if(rsMsgs->getDistantChatStatus(peerId,distant_chat_gxs_id,distant_peer_status)) + if(rsMsgs->getDistantChatStatus(RsGxsId(peerId),distant_peer_status)) { getChat(peerId, forceFocus ? RS_CHAT_OPEN | RS_CHAT_FOCUS : RS_CHAT_OPEN ); // use own flags return ; diff --git a/retroshare-gui/src/gui/chat/PopupDistantChatDialog.cpp b/retroshare-gui/src/gui/chat/PopupDistantChatDialog.cpp index c0bbd6ddc..95d104b47 100644 --- a/retroshare-gui/src/gui/chat/PopupDistantChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/PopupDistantChatDialog.cpp @@ -58,9 +58,9 @@ PopupDistantChatDialog::PopupDistantChatDialog(QWidget *parent, Qt::WindowFlags updateDisplay() ; } -void PopupDistantChatDialog::init(const DistantChatPeerId& pid,const QString & title) +void PopupDistantChatDialog::init(const RsPeerId &pid,const QString & title) { - _pid = pid ; + _pid = RsGxsId(pid) ; PopupChatDialog::init(pid,title) ; } @@ -77,8 +77,7 @@ void PopupDistantChatDialog::updateDisplay() // uint32_t status= RS_DISTANT_CHAT_STATUS_UNKNOWN; - RsGxsId gxs_id ; - rsMsgs->getDistantChatStatus(_pid,gxs_id,status) ; + rsMsgs->getDistantChatStatus(_pid,status) ; switch(status) { @@ -118,9 +117,8 @@ void PopupDistantChatDialog::closeEvent(QCloseEvent *e) { //std::cerr << "Closing window => closing distant chat for hash " << _pid << std::endl; - uint32_t status= RS_DISTANT_CHAT_STATUS_UNKNOWN; - RsGxsId gxs_id ; - rsMsgs->getDistantChatStatus(_pid,gxs_id,status) ; + uint32_t status= RS_DISTANT_CHAT_STATUS_UNKNOWN; + rsMsgs->getDistantChatStatus(_pid,status) ; if(status != RS_DISTANT_CHAT_STATUS_REMOTELY_CLOSED) { @@ -140,21 +138,20 @@ void PopupDistantChatDialog::closeEvent(QCloseEvent *e) PopupChatDialog::closeEvent(e) ; } -QString PopupDistantChatDialog::getPeerName(const DistantChatPeerId &id) const +QString PopupDistantChatDialog::getPeerName(const RsGxsId& id) const { uint32_t status ; - RsGxsId gxs_id ; - if(rsMsgs->getDistantChatStatus(id,gxs_id,status)) + if(rsMsgs->getDistantChatStatus(id,status)) { RsIdentityDetails details ; - if(rsIdentity->getIdDetails(gxs_id,details)) + if(rsIdentity->getIdDetails(RsGxsId(id),details)) return QString::fromUtf8( details.mNickname.c_str() ) ; else - return QString::fromStdString(gxs_id.toStdString()) ; + return QString::fromStdString(id.toStdString()) ; } else - return ChatDialog::getPeerName(id) ; + return ChatDialog::getPeerName(RsPeerId(id)) ; } diff --git a/retroshare-gui/src/gui/chat/PopupDistantChatDialog.h b/retroshare-gui/src/gui/chat/PopupDistantChatDialog.h index 140412812..9db588356 100644 --- a/retroshare-gui/src/gui/chat/PopupDistantChatDialog.h +++ b/retroshare-gui/src/gui/chat/PopupDistantChatDialog.h @@ -37,17 +37,17 @@ class PopupDistantChatDialog: public PopupChatDialog /** Default destructor */ virtual ~PopupDistantChatDialog(); - virtual void init(const DistantChatPeerId &pid, const QString &title); + virtual void init(const RsPeerId &pid, const QString &title); virtual void closeEvent(QCloseEvent *e) ; - virtual QString getPeerName(const DistantChatPeerId& id) const ; + virtual QString getPeerName(const RsGxsId &id) const ; protected slots: void updateDisplay() ; // overloads RsAutoUpdatePage private: QTimer *_update_timer ; - DistantChatPeerId _pid ; + RsGxsId _pid ; QLabel *_status_label ; friend class ChatDialog;