Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions src/chat/distantchat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,8 @@ void DistantChatService::receiveData( const RsGxsTunnelId& tunnel_id, unsigned c

void DistantChatService::markDistantChatAsClosed(const DistantChatPeerId& dcpid)
{
mGxsTunnels->closeExistingTunnel(
RsGxsTunnelId(dcpid), DISTANT_CHAT_GXS_TUNNEL_SERVICE_ID );

RS_STACK_MUTEX(mDistantChatMtx) ;

std::map<DistantChatPeerId,DistantChatContact>::iterator it = mDistantChatContacts.find(dcpid) ;

if(it != mDistantChatContacts.end())
mDistantChatContacts.erase(it) ;
// Same work, whether the close comes from the remote end or from us.
closeDistantChatConnexion(dcpid) ;
}

bool DistantChatService::initiateDistantChatConnexion(
Expand Down Expand Up @@ -327,11 +320,34 @@ bool DistantChatService::getDistantChatStatus(const DistantChatPeerId& tunnel_id

bool DistantChatService::closeDistantChatConnexion(const DistantChatPeerId &tunnel_id)
{
mGxsTunnels->closeExistingTunnel(RsGxsTunnelId(tunnel_id), DISTANT_CHAT_GXS_TUNNEL_SERVICE_ID) ;

// also remove contact. Or do we wait for the notification?

return true ;
// The contact has to go with the tunnel. Leaving it behind kept the
// conversation alive on our side: handleRecvDataItem() only drops incoming
// items for tunnels it finds no contact for, so a peer that keeps writing
// re-digs the tunnel and the chat we just left comes back. That is what
// markDistantChatAsClosed() does when the *remote* end closes, and closing
// it ourselves has to mean the same thing.

bool tunnel_closed = mGxsTunnels->closeExistingTunnel(
RsGxsTunnelId(tunnel_id), DISTANT_CHAT_GXS_TUNNEL_SERVICE_ID );

bool contact_removed = false;
{
RS_STACK_MUTEX(mDistantChatMtx) ;

auto it = mDistantChatContacts.find(tunnel_id) ;

if(it != mDistantChatContacts.end())
{
mDistantChatContacts.erase(it) ;
contact_removed = true ;
}
}

// Answering true whatever happened made every client -- the chat window,
// the web UI, any JSON API caller -- report a conversation as closed when
// nothing had been closed at all, the tunnel having died on its own before.

return tunnel_closed || contact_removed ;
}

uint32_t DistantChatService::getDistantChatPermissionFlags()
Expand Down
Loading