mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 14:16:16 -04:00
Expose libresapi for distant chat
Added macro to deprecate symbols usage in a crossplatform way. Deprecated Request::mMethod and related stuff that make implementation more complex without advantage. Added /chat/{initiate_distant_chat, distant_chat_status, close_distant_chat} to libresapi. Solved subtle bug in ChatId::ChatId(std::string str) that caused zeroed DistantChatPeerId being created.
This commit is contained in:
parent
f8de12d3d3
commit
9eef412b44
9 changed files with 179 additions and 82 deletions
|
@ -275,31 +275,30 @@ bool DistantChatService::initiateDistantChatConnexion(const RsGxsId& to_gxs_id,
|
|||
|
||||
bool DistantChatService::getDistantChatStatus(const DistantChatPeerId& tunnel_id, DistantChatPeerInfo& cinfo)
|
||||
{
|
||||
RsStackMutex stack(mDistantChatMtx); /********** STACK LOCKED MTX ******/
|
||||
RS_STACK_MUTEX(mDistantChatMtx);
|
||||
|
||||
RsGxsTunnelService::GxsTunnelInfo tinfo ;
|
||||
RsGxsTunnelService::GxsTunnelInfo tinfo;
|
||||
|
||||
if(!mGxsTunnels->getTunnelInfo(RsGxsTunnelId(tunnel_id),tinfo))
|
||||
return false;
|
||||
if(!mGxsTunnels->getTunnelInfo(RsGxsTunnelId(tunnel_id),tinfo)) return false;
|
||||
|
||||
cinfo.to_id = tinfo.destination_gxs_id;
|
||||
cinfo.own_id = tinfo.source_gxs_id;
|
||||
cinfo.peer_id = tunnel_id;
|
||||
cinfo.to_id = tinfo.destination_gxs_id;
|
||||
cinfo.own_id = tinfo.source_gxs_id;
|
||||
cinfo.peer_id = tunnel_id;
|
||||
|
||||
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 ;
|
||||
}
|
||||
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;
|
||||
case RsGxsTunnelService::RS_GXS_TUNNEL_STATUS_UNKNOWN:
|
||||
default:
|
||||
cinfo.status = RS_DISTANT_CHAT_STATUS_UNKNOWN; break;
|
||||
}
|
||||
|
||||
return true ;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DistantChatService::closeDistantChatConnexion(const DistantChatPeerId &tunnel_id)
|
||||
|
|
|
@ -292,14 +292,11 @@ void p3ChatService::checkSizeAndSendMessage(RsChatMsgItem *msg)
|
|||
|
||||
bool p3ChatService::isOnline(const RsPeerId& pid)
|
||||
{
|
||||
// check if the id is a tunnel id or a peer id.
|
||||
|
||||
DistantChatPeerInfo dcpinfo;
|
||||
|
||||
if(getDistantChatStatus(DistantChatPeerId(pid),dcpinfo))
|
||||
return dcpinfo.status == RS_DISTANT_CHAT_STATUS_CAN_TALK ;
|
||||
else
|
||||
return mServiceCtrl->isPeerConnected(getServiceInfo().mServiceType, pid);
|
||||
// check if the id is a tunnel id or a peer id.
|
||||
DistantChatPeerInfo dcpinfo;
|
||||
if(getDistantChatStatus(DistantChatPeerId(pid),dcpinfo))
|
||||
return dcpinfo.status == RS_DISTANT_CHAT_STATUS_CAN_TALK;
|
||||
else return mServiceCtrl->isPeerConnected(getServiceInfo().mServiceType, pid);
|
||||
}
|
||||
|
||||
bool p3ChatService::sendChat(ChatId destination, std::string msg)
|
||||
|
@ -318,8 +315,7 @@ bool p3ChatService::sendChat(ChatId destination, std::string msg)
|
|||
}
|
||||
// destination is peer or distant
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "p3ChatService::sendChat()";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "p3ChatService::sendChat()" << std::endl;
|
||||
#endif
|
||||
|
||||
RsPeerId vpid;
|
||||
|
@ -341,12 +337,12 @@ bool p3ChatService::sendChat(ChatId destination, std::string msg)
|
|||
message.online = true;
|
||||
|
||||
if(!isOnline(vpid))
|
||||
{
|
||||
/* peer is offline, add to outgoing list */
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
privateOutgoingList.push_back(ci);
|
||||
}
|
||||
{
|
||||
/* peer is offline, add to outgoing list */
|
||||
{
|
||||
RS_STACK_MUTEX(mChatMtx);
|
||||
privateOutgoingList.push_back(ci);
|
||||
}
|
||||
|
||||
message.online = false;
|
||||
RsServer::notify()->notifyChatMessage(message);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue