Merge pull request #383 from jolavillette/fix/distant-chat-locally-closed-event

Distant chat: tell every client when a conversation is closed locally
This commit is contained in:
csoler 2026-09-03 18:46:18 +02:00 committed by GitHub
commit 2f093fd7b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 53 additions and 5 deletions

View File

@ -327,11 +327,58 @@ 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) ;
// The contact has to go with the tunnel: the entry in mDistantChatContacts
// is the core's record of an open conversation -- handleOutgoingItem()
// accepts outgoing items for as long as it is there -- and
// markDistantChatAsClosed(), the remote-close path, removes it. Nothing
// removed it when we closed the conversation ourselves.
// also remove contact. Or do we wait for the notification?
bool tunnel_closed = mGxsTunnels->closeExistingTunnel(
RsGxsTunnelId(tunnel_id), DISTANT_CHAT_GXS_TUNNEL_SERVICE_ID );
return true ;
bool contact_removed = false;
{
RS_STACK_MUTEX(mDistantChatMtx) ;
auto it = mDistantChatContacts.find(tunnel_id) ;
if(it != mDistantChatContacts.end())
{
mDistantChatContacts.erase(it) ;
contact_removed = true ;
}
}
// The two can disagree in one direction only: p3GxsTunnelService prunes
// remotely-closed tunnels on its own after 20s, so the tunnel may already
// be gone while the contact is still registered. The converse -- a closed
// tunnel with no contact -- is an anomaly.
if(tunnel_closed && !contact_removed)
std::cerr << "(EE) closeDistantChatConnexion(): tunnel " << tunnel_id << " was closed, but no distant chat contact was registered for it." << std::endl;
// 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.
bool closed = tunnel_closed || contact_removed ;
// The client that asked for the close knows about it; the others do not,
// and a conversation closed from the web UI stayed open in the desktop
// chat window. Polling cannot fix that: once the tunnel is gone,
// getDistantChatStatus() answers the same false for a conversation the
// peer closed (where the window should stay open) and for one we closed
// from another client (where it should go). Only an explicit event tells
// them apart, so post it here -- and every client of this core drops the
// conversation at the same time.
if(closed && rsEvents)
{
auto ev = std::make_shared<RsDistantChatEvent>();
ev->mEventCode = RsDistantChatEventCode::TUNNEL_STATUS_LOCALLY_CLOSED;
ev->mId = tunnel_id;
rsEvents->postEvent(ev);
}
return closed ;
}
uint32_t DistantChatService::getDistantChatPermissionFlags()

View File

@ -249,6 +249,7 @@ enum class RsDistantChatEventCode: uint8_t
TUNNEL_STATUS_TUNNEL_DN = 0x02,
TUNNEL_STATUS_REMOTELY_CLOSED = 0x03,
TUNNEL_STATUS_CONNECTION_REFUSED = 0x04,
TUNNEL_STATUS_LOCALLY_CLOSED = 0x05, // we closed it ourselves (closeDistantChatConnexion), from any client of this core
};
struct RsChatLobbyEvent : RsEvent // This event handles events internal to the distributed chat system