From 56e71b51fa6ed33d7a03433651a8315c719d2f03 Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 19 Apr 2013 22:24:25 +0000 Subject: [PATCH] added notifications so that the distant chat window pops up git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-GenericTunneling@6319 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/services/p3chatservice.cc | 79 ++++++++++++------- libretroshare/src/services/p3chatservice.h | 1 + .../src/gui/chat/PopupDistantChatDialog.cpp | 1 + 3 files changed, 54 insertions(+), 27 deletions(-) diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index a6fddba57..165df106a 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -35,6 +35,7 @@ #include "turtle/p3turtle.h" #include "retroshare/rsiface.h" #include "retroshare/rspeers.h" +#include "retroshare/rsstatus.h" #include "pqi/pqibin.h" #include "pqi/pqinotify.h" #include "pqi/pqistore.h" @@ -398,6 +399,17 @@ bool p3ChatService::isLobbyId(const std::string& id,ChatLobbyId& lobby_id) return false ; } +bool p3ChatService::isOnline(const std::string& id) +{ + // check if the id is a tunnel id or a peer id. + + uint32_t res = getDistantChatStatus(id) ; + + if(!res) + return mLinkMgr->isOnline(id) ; + + return res == RS_DISTANT_CHAT_STATUS_TUNNEL_OK ; +} bool p3ChatService::sendPrivateChat(const std::string &id, const std::wstring &msg) { @@ -422,7 +434,8 @@ bool p3ChatService::sendPrivateChat(const std::string &id, const std::wstrin ci->recvTime = ci->sendTime; ci->message = msg; - if (!mLinkMgr->isOnline(id)) { + if(!isOnline(id)) + { /* peer is offline, add to outgoing list */ { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ @@ -2781,36 +2794,46 @@ bool p3ChatService::handleTunnelRequest(const std::string& hash,const std::strin void p3ChatService::addVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualPeerId& virtual_peer_id) { - RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ - - std::map::iterator it = _distant_chat_peers.find(hash) ; - - if(it == _distant_chat_peers.end()) { - std::cerr << "(EE) Cannot add virtual peer for hash " << hash << ": no chat invite found for that hash." << std::endl; - return ; + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + + std::map::iterator it = _distant_chat_peers.find(hash) ; + + if(it == _distant_chat_peers.end()) + { + std::cerr << "(EE) Cannot add virtual peer for hash " << hash << ": no chat invite found for that hash." << std::endl; + return ; + } + + time_t now = time(NULL) ; + it->second.last_contact = now ; + it->second.status = RS_DISTANT_CHAT_STATUS_TUNNEL_OK ; + + std::cerr << "(II) Adding virtual peer " << virtual_peer_id << " for chat hash " << hash << std::endl; } + rsicontrol->getNotify().notifyChatStatus(hash,"tunnel is up again!",true) ; + rsicontrol->getNotify().notifyPeerStatusChanged(hash,RS_STATUS_ONLINE) ; -// memcpy(_distant_chat_peers[virtual_peer_id].aes_key,it->second.aes_key,8) ; - - time_t now = time(NULL) ; - it->second.last_contact = now ; - it->second.status = RS_DISTANT_CHAT_STATUS_TUNNEL_OK ; + getPqiNotify()->AddPopupMessage(RS_POPUP_CHAT, hash, "Distant peer", "Conversation starts..."); } void p3ChatService::removeVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualPeerId& virtual_peer_id) { - RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ - - std::map::iterator it = _distant_chat_peers.find(hash) ; - - if(it == _distant_chat_peers.end()) { - std::cerr << "(EE) Cannot remove virtual peer " << virtual_peer_id << ": not found in chat list!!" << std::endl; - return ; - } + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ - it->second.status = RS_DISTANT_CHAT_STATUS_TUNNEL_DN ; + std::map::iterator it = _distant_chat_peers.find(hash) ; + + if(it == _distant_chat_peers.end()) + { + std::cerr << "(EE) Cannot remove virtual peer " << virtual_peer_id << ": not found in chat list!!" << std::endl; + return ; + } + + it->second.status = RS_DISTANT_CHAT_STATUS_TUNNEL_DN ; + } + rsicontrol->getNotify().notifyChatStatus(hash,"tunnel is down...",true) ; + rsicontrol->getNotify().notifyPeerStatusChanged(hash,RS_STATUS_OFFLINE) ; } void p3ChatService::receiveTurtleData( RsTurtleGenericTunnelItem *gitem,const std::string& hash, const std::string& virtual_peer_id,RsTurtleGenericTunnelItem::Direction direction) @@ -2878,7 +2901,7 @@ void p3ChatService::receiveTurtleData( RsTurtleGenericTunnelItem *gitem,const st // Setup the virtual peer to be the origin, and pass it on. // - citem->PeerId(virtual_peer_id) ; + citem->PeerId(hash) ; handleIncomingItem(citem) ; // Treats the item, and deletes it } @@ -3139,10 +3162,12 @@ uint32_t p3ChatService::getDistantChatStatus(const std::string& hash) { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ - if(_distant_chat_peers.find(hash) != _distant_chat_peers.end()) - return 1 ; - - return 0 ; + std::map::const_iterator it = _distant_chat_peers.find(hash) ; + + if(it == _distant_chat_peers.end()) + return RS_DISTANT_CHAT_STATUS_UNKNOWN ; + else + return it->second.status ; } diff --git a/libretroshare/src/services/p3chatservice.h b/libretroshare/src/services/p3chatservice.h index 64863a830..550a546c2 100644 --- a/libretroshare/src/services/p3chatservice.h +++ b/libretroshare/src/services/p3chatservice.h @@ -186,6 +186,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi virtual void saveDone(); virtual bool loadList(std::list& load) ; + bool isOnline(const std::string& id) ; private: RsMutex mChatMtx; diff --git a/retroshare-gui/src/gui/chat/PopupDistantChatDialog.cpp b/retroshare-gui/src/gui/chat/PopupDistantChatDialog.cpp index 68655998e..5f7149bf0 100644 --- a/retroshare-gui/src/gui/chat/PopupDistantChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/PopupDistantChatDialog.cpp @@ -41,6 +41,7 @@ PopupDistantChatDialog::PopupDistantChatDialog(QWidget *parent, Qt::WFlags flags void PopupDistantChatDialog::init(const std::string& hash,const QString & title) { _hash = hash ; + PopupChatDialog::init(hash,title) ; } void PopupDistantChatDialog::checkTunnel()