mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 06:06:10 -04:00
fixed GUI update of avatars and status for distant chat. Updated backend for new model. Fixed a few bugs in serialisation
This commit is contained in:
parent
6951d730a5
commit
81ab43beb9
27 changed files with 515 additions and 289 deletions
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include "util/rsaes.h"
|
||||
#include "util/rsmemory.h"
|
||||
#include "util/rsprint.h"
|
||||
|
||||
#include <serialiser/rsmsgitems.h>
|
||||
|
||||
|
@ -90,6 +91,8 @@ bool DistantChatService::handleOutgoingItem(RsChatItem *item)
|
|||
return false;
|
||||
}
|
||||
|
||||
std::cerr << " sending: " << RsUtil::BinToHex(mem,size) << std::endl;
|
||||
|
||||
mGxsTunnels->sendData( RsGxsTunnelId(item->PeerId()),DISTANT_CHAT_GXS_TUNNEL_SERVICE_ID,mem,size);
|
||||
return true;
|
||||
}
|
||||
|
@ -108,18 +111,62 @@ void DistantChatService::handleRecvChatStatusItem(RsChatStatusItem *cs)
|
|||
void DistantChatService::notifyTunnelStatus(const RsGxsTunnelService::RsGxsTunnelId &tunnel_id, uint32_t tunnel_status)
|
||||
{
|
||||
std::cerr << "DistantChatService::notifyTunnelStatus(): got notification " << std::hex << tunnel_status << std::dec << " for tunnel " << tunnel_id << std::endl;
|
||||
#warning do something here
|
||||
|
||||
switch(tunnel_status)
|
||||
{
|
||||
default:
|
||||
case RsGxsTunnelService::RS_GXS_TUNNEL_STATUS_UNKNOWN: std::cerr << "(EE) don't know how to handle RS_GXS_TUNNEL_STATUS_UNKNOWN !" << std::endl;
|
||||
break ;
|
||||
|
||||
case RsGxsTunnelService::RS_GXS_TUNNEL_STATUS_CAN_TALK: RsServer::notify()->notifyChatStatus(ChatId(DistantChatPeerId(tunnel_id)),"Tunnel is secured. You can talk!") ;
|
||||
RsServer::notify()->notifyPeerStatusChanged(tunnel_id.toStdString(),RS_STATUS_ONLINE) ;
|
||||
break ;
|
||||
|
||||
case RsGxsTunnelService::RS_GXS_TUNNEL_STATUS_TUNNEL_DN: RsServer::notify()->notifyChatStatus(ChatId(DistantChatPeerId(tunnel_id)),"tunnel is down...") ;
|
||||
RsServer::notify()->notifyPeerStatusChanged(tunnel_id.toStdString(),RS_STATUS_OFFLINE) ;
|
||||
break ;
|
||||
|
||||
case RsGxsTunnelService::RS_GXS_TUNNEL_STATUS_REMOTELY_CLOSED: RsServer::notify()->notifyChatStatus(ChatId(DistantChatPeerId(tunnel_id)),"tunnel is down...") ;
|
||||
RsServer::notify()->notifyPeerStatusChanged(tunnel_id.toStdString(),RS_STATUS_OFFLINE) ;
|
||||
break ;
|
||||
}
|
||||
}
|
||||
|
||||
void DistantChatService::receiveData(const RsGxsTunnelService::RsGxsTunnelId &tunnel_id, unsigned char *data, uint32_t data_size)
|
||||
{
|
||||
std::cerr << "DistantChatService::receiveData(): got data of size " << data_size << " for tunnel " << tunnel_id << std::endl;
|
||||
#warning do something here
|
||||
std::cerr << " received: " << RsUtil::BinToHex(data,data_size) << std::endl;
|
||||
std::cerr << " deserialising..." << std::endl;
|
||||
|
||||
RsItem *item = RsChatSerialiser().deserialise(data,&data_size) ;
|
||||
|
||||
// always make the contact up to date. This is useful for server side, which doesn't know about the chat until it
|
||||
// receives the first item.
|
||||
{
|
||||
RS_STACK_MUTEX(mDistantChatMtx) ;
|
||||
|
||||
RsGxsTunnelService::GxsTunnelInfo tinfo;
|
||||
if(!mGxsTunnels->getTunnelInfo(tunnel_id,tinfo))
|
||||
return ;
|
||||
|
||||
DistantChatContact& contact(mDistantChatContacts[DistantChatPeerId(tunnel_id)]) ;
|
||||
|
||||
contact.to_id = tinfo.destination_gxs_id ;
|
||||
contact.from_id = tinfo.source_gxs_id ;
|
||||
}
|
||||
|
||||
if(item != NULL)
|
||||
{
|
||||
handleIncomingItem(item) ;
|
||||
RsServer::notify()->notifyListChange(NOTIFY_LIST_PRIVATE_INCOMING_CHAT, NOTIFY_TYPE_ADD);
|
||||
}
|
||||
else
|
||||
std::cerr << " (EE) item could not be deserialised!" << std::endl;
|
||||
}
|
||||
|
||||
void DistantChatService::markDistantChatAsClosed(const DistantChatPeerId& dcpid)
|
||||
{
|
||||
mGxsTunnels->closeExistingTunnel(RsGxsTunnelService::RsGxsTunnelId(dcpid)) ;
|
||||
mGxsTunnels->closeExistingTunnel(RsGxsTunnelService::RsGxsTunnelId(dcpid),DISTANT_CHAT_GXS_TUNNEL_SERVICE_ID) ;
|
||||
|
||||
RS_STACK_MUTEX(mDistantChatMtx) ;
|
||||
|
||||
|
@ -132,10 +179,10 @@ void DistantChatService::markDistantChatAsClosed(const DistantChatPeerId& dcpid)
|
|||
bool DistantChatService::initiateDistantChatConnexion(const RsGxsId& to_gxs_id, const RsGxsId& from_gxs_id, DistantChatPeerId& dcpid, uint32_t& error_code)
|
||||
{
|
||||
RsGxsTunnelId tunnel_id ;
|
||||
|
||||
if(!mGxsTunnels->requestSecuredTunnel(to_gxs_id,from_gxs_id,tunnel_id,error_code))
|
||||
|
||||
if(!mGxsTunnels->requestSecuredTunnel(to_gxs_id,from_gxs_id,tunnel_id,DISTANT_CHAT_GXS_TUNNEL_SERVICE_ID,error_code))
|
||||
return false ;
|
||||
|
||||
|
||||
dcpid = DistantChatPeerId(tunnel_id) ;
|
||||
|
||||
DistantChatContact& dc_contact(mDistantChatContacts[dcpid]) ;
|
||||
|
@ -145,6 +192,14 @@ bool DistantChatService::initiateDistantChatConnexion(const RsGxsId& to_gxs_id,
|
|||
|
||||
error_code = RS_DISTANT_CHAT_ERROR_NO_ERROR ;
|
||||
|
||||
// Make a self message to raise the chat window
|
||||
|
||||
RsChatMsgItem *item = new RsChatMsgItem;
|
||||
item->message = "[Starting distant chat. Please wait for secure tunnel to be established]" ;
|
||||
item->chatFlags = RS_CHAT_FLAG_PRIVATE ;
|
||||
item->PeerId(RsPeerId(tunnel_id)) ;
|
||||
handleRecvChatMsgItem(item) ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
|
@ -160,14 +215,26 @@ bool DistantChatService::getDistantChatStatus(const DistantChatPeerId& tunnel_id
|
|||
cinfo.to_id = tinfo.destination_gxs_id;
|
||||
cinfo.own_id = tinfo.source_gxs_id;
|
||||
cinfo.peer_id = tunnel_id;
|
||||
cinfo.status = tinfo.tunnel_status; // see the values in rsmsgs.h
|
||||
|
||||
switch(tinfo.tunnel_status)
|
||||
{
|
||||
case RsGxsTunnelService::RS_GXS_TUNNEL_STATUS_CAN_TALK : cinfo.status = RS_DISTANT_CHAT_STATUS_CAN_TALK;
|
||||
break ;
|
||||
case RsGxsTunnelService::RS_GXS_TUNNEL_STATUS_TUNNEL_DN: cinfo.status = RS_DISTANT_CHAT_STATUS_TUNNEL_DN ;
|
||||
break ;
|
||||
case RsGxsTunnelService::RS_GXS_TUNNEL_STATUS_REMOTELY_CLOSED: cinfo.status = RS_DISTANT_CHAT_STATUS_REMOTELY_CLOSED ;
|
||||
break ;
|
||||
default:
|
||||
case RsGxsTunnelService::RS_GXS_TUNNEL_STATUS_UNKNOWN: cinfo.status = RS_DISTANT_CHAT_STATUS_UNKNOWN;
|
||||
break ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool DistantChatService::closeDistantChatConnexion(const DistantChatPeerId &tunnel_id)
|
||||
{
|
||||
mGxsTunnels->closeExistingTunnel(RsGxsTunnelId(tunnel_id)) ;
|
||||
mGxsTunnels->closeExistingTunnel(RsGxsTunnelId(tunnel_id), DISTANT_CHAT_GXS_TUNNEL_SERVICE_ID) ;
|
||||
|
||||
// also remove contact. Or do we wait for the notification?
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
// So, public interface only uses DistandChatPeerId, but internally, this is converted into a RsGxsTunnelService::RsGxsTunnelId
|
||||
|
||||
|
||||
DistantChatService(RsGixs *pids) : mDistantChatMtx("distant chat")
|
||||
DistantChatService() : mDistantChatMtx("distant chat")
|
||||
{
|
||||
mGxsTunnels = NULL ;
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ public:
|
|||
|
||||
virtual bool getDistantChatStatus(const DistantChatPeerId &tunnel_id, DistantChatPeerInfo& cinfo) ;
|
||||
|
||||
// derived in p3ChatService
|
||||
// derived in p3ChatService, so as to pass down some info
|
||||
virtual void handleIncomingItem(RsItem *) = 0;
|
||||
virtual bool handleRecvChatMsgItem(RsChatMsgItem *ci)=0 ;
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ static const uint32_t MAX_AVATAR_JPEG_SIZE = 32767; // Maximum size
|
|||
// Images are 96x96, which makes approx. 27000 bytes uncompressed.
|
||||
|
||||
p3ChatService::p3ChatService(p3ServiceControl *sc,p3IdService *pids, p3LinkMgr *lm, p3HistoryMgr *historyMgr)
|
||||
:DistantChatService(pids),DistributedChatService(getServiceInfo().mServiceType,sc,historyMgr,pids), mChatMtx("p3ChatService"),mServiceCtrl(sc), mLinkMgr(lm) , mHistoryMgr(historyMgr)
|
||||
: DistributedChatService(getServiceInfo().mServiceType,sc,historyMgr,pids), mChatMtx("p3ChatService"),mServiceCtrl(sc), mLinkMgr(lm) , mHistoryMgr(historyMgr)
|
||||
{
|
||||
_serializer = new RsChatSerialiser() ;
|
||||
|
||||
|
@ -217,24 +217,25 @@ void p3ChatService::sendStatusString(const ChatId& id , const std::string& statu
|
|||
sendLobbyStatusString(id.toLobbyId(),status_string) ;
|
||||
else if(id.isBroadcast())
|
||||
sendGroupChatStatusString(status_string);
|
||||
else if(id.isPeerId() || id.isGxsId())
|
||||
{
|
||||
RsChatStatusItem *cs = new RsChatStatusItem ;
|
||||
else if(id.isPeerId() || id.isDistantChatId())
|
||||
{
|
||||
RsChatStatusItem *cs = new RsChatStatusItem ;
|
||||
|
||||
cs->status_string = status_string ;
|
||||
cs->flags = RS_CHAT_FLAG_PRIVATE ;
|
||||
RsPeerId vpid;
|
||||
if(id.isGxsId())
|
||||
vpid = RsPeerId(id.toGxsId());
|
||||
else
|
||||
vpid = id.toPeerId();
|
||||
cs->PeerId(vpid);
|
||||
cs->status_string = status_string ;
|
||||
cs->flags = RS_CHAT_FLAG_PRIVATE ;
|
||||
RsPeerId vpid;
|
||||
if(id.isDistantChatId())
|
||||
vpid = RsPeerId(id.toDistantChatId());
|
||||
else
|
||||
vpid = id.toPeerId();
|
||||
|
||||
cs->PeerId(vpid);
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "sending chat status packet:" << std::endl ;
|
||||
cs->print(std::cerr) ;
|
||||
std::cerr << "sending chat status packet:" << std::endl ;
|
||||
cs->print(std::cerr) ;
|
||||
#endif
|
||||
sendChatItem(cs);
|
||||
sendChatItem(cs);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -286,7 +287,6 @@ bool p3ChatService::isOnline(const RsPeerId& pid)
|
|||
{
|
||||
// check if the id is a tunnel id or a peer id.
|
||||
|
||||
uint32_t status ;
|
||||
DistantChatPeerInfo dcpinfo;
|
||||
|
||||
if(getDistantChatStatus(DistantChatPeerId(pid),dcpinfo))
|
||||
|
@ -304,7 +304,7 @@ bool p3ChatService::sendChat(ChatId destination, std::string msg)
|
|||
sendPublicChat(msg);
|
||||
return true;
|
||||
}
|
||||
else if(destination.isPeerId()==false && destination.isGxsId()==false)
|
||||
else if(destination.isPeerId()==false && destination.isDistantChatId()==false)
|
||||
{
|
||||
std::cerr << "p3ChatService::sendChat() Error: chat id type not handled. Is it empty?" << std::endl;
|
||||
return false;
|
||||
|
@ -316,8 +316,8 @@ bool p3ChatService::sendChat(ChatId destination, std::string msg)
|
|||
#endif
|
||||
|
||||
RsPeerId vpid;
|
||||
if(destination.isGxsId())
|
||||
vpid = RsPeerId(destination.toGxsId()); // convert to virtual peer id
|
||||
if(destination.isDistantChatId())
|
||||
vpid = RsPeerId(destination.toDistantChatId()); // convert to virtual peer id
|
||||
else
|
||||
vpid = destination.toPeerId();
|
||||
|
||||
|
@ -769,7 +769,6 @@ void p3ChatService::handleRecvChatStatusItem(RsChatStatusItem *cs)
|
|||
std::cerr << "Received status string \"" << cs->status_string << "\"" << std::endl ;
|
||||
#endif
|
||||
|
||||
uint32_t status;
|
||||
DistantChatPeerInfo dcpinfo;
|
||||
|
||||
if(cs->flags & RS_CHAT_FLAG_REQUEST_CUSTOM_STATE) // no state here just a request.
|
||||
|
@ -820,7 +819,6 @@ void p3ChatService::initChatMessage(RsChatMsgItem *c, ChatMessage &m)
|
|||
return;
|
||||
}
|
||||
|
||||
uint32_t status;
|
||||
DistantChatPeerInfo dcpinfo;
|
||||
if(DistantChatService::getDistantChatStatus(DistantChatPeerId(c->PeerId()), dcpinfo))
|
||||
m.chat_id = ChatId(DistantChatPeerId(c->PeerId()));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue