Browse Source

fix(chat_sync): online status for joiner on inviter side not sent to GUI/peers

- cs_handle_channel_join: call cs_post_channel_online immediately after adding joiner
- member_sync_start with _on_invite_sync_done callback: on MT_OK push online=1 via merkle_sync_push_update
- DEBUG per-peer online status in cs_post_channel_online
topo_upd
Evgeny 2 months ago
parent
commit
3a7b359f87
  1. 42
      tools/chatgui/transport/chat_sync.c

42
tools/chatgui/transport/chat_sync.c

@ -477,8 +477,12 @@ static void cs_post_channel_online(struct chat_sync* cs, const char* ch_id) {
for (int i = 0; i < cs->channel_count; i++) for (int i = 0; i < cs->channel_count; i++)
if (strcmp(cs->channels[i].channel_id, ch_id) == 0) { ch = &cs->channels[i]; break; } if (strcmp(cs->channels[i].channel_id, ch_id) == 0) { ch = &cs->channels[i]; break; }
if (ch) { if (ch) {
for (int j = 0; j < ch->peer_count; j++) for (int j = 0; j < ch->peer_count; j++) {
if (cs_is_peer_online(cs->inst, ch->peer_ids[j])) online++; int p_on = cs_is_peer_online(cs->inst, ch->peer_ids[j]);
if (p_on) online++;
DEBUG_DEBUG(DEBUG_CATEGORY_DB_SYNC, "%s: PEERS_ONLINE peer[%d]=0x%016llx online=%d",
CS_ID, j, (unsigned long long)ch->peer_ids[j], p_on);
}
} }
size_t cl = strlen(ch_id); size_t cl = strlen(ch_id);
if (cl > 63) cl = 63; if (cl > 63) cl = 63;
@ -486,7 +490,7 @@ static void cs_post_channel_online(struct chat_sync* cs, const char* ch_id) {
memcpy(evt + 1, ch_id, cl); memcpy(evt + 1, ch_id, cl);
uint16_t oc = (uint16_t)online; memcpy(evt + 1 + cl, &oc, 2); uint16_t oc = (uint16_t)online; memcpy(evt + 1 + cl, &oc, 2);
gui_bridge_post(GUI_EVT_CHANNEL_PEERS_ONLINE, evt, 1 + (int)cl + 2); gui_bridge_post(GUI_EVT_CHANNEL_PEERS_ONLINE, evt, 1 + (int)cl + 2);
DEBUG_DEBUG(DEBUG_CATEGORY_DB_SYNC, "%s: PEERS_ONLINE ch=%.*s online=%d", CS_ID, (int)cl, ch_id, online); DEBUG_DEBUG(DEBUG_CATEGORY_DB_SYNC, "%s: PEERS_ONLINE ch=%.*s total_online=%d", CS_ID, (int)cl, ch_id, online);
} }
/* ── Throttled sync (не чаще CS_SYNC_INTERVAL_MS) ── */ /* ── Throttled sync (не чаще CS_SYNC_INTERVAL_MS) ── */
@ -577,6 +581,26 @@ static void _on_member_sync_done(uint64_t peer, const char* ns, int result, void
CS_ID, result == MT_OK ? "OK" : "FAIL", ns, (unsigned long long)peer); CS_ID, result == MT_OK ? "OK" : "FAIL", ns, (unsigned long long)peer);
} }
struct invite_sync_arg {
uint64_t node_id;
char ch_id[64];
};
static void _on_invite_sync_done(uint64_t peer, const char* ns, int result, void* arg) {
struct invite_sync_arg* sa = (struct invite_sync_arg*)arg;
DEBUG_INFO(DEBUG_CATEGORY_DB_SYNC, "%s: invite_sync %s ns=%s peer=%016llx node=0x%016llx",
CS_ID, result == MT_OK ? "OK" : "FAIL", ns,
(unsigned long long)peer, sa ? (unsigned long long)sa->node_id : 0);
if (result == MT_OK && sa && g_cs) {
cs_post_channel_online(g_cs, sa->ch_id);
uint8_t one = 1;
merkle_sync_push_update(g_cs->inst, sa->ch_id, sa->node_id, 0x01, &one, 1);
DEBUG_INFO(DEBUG_CATEGORY_DB_SYNC, "%s: invite_sync push_update node=0x%016llx online=1 ch=%s",
CS_ID, (unsigned long long)sa->node_id, sa->ch_id);
}
u_free(sa);
}
static void cs_on_conn_up(struct ETCP_CONN* conn, void* arg) { static void cs_on_conn_up(struct ETCP_CONN* conn, void* arg) {
(void)arg; (void)arg;
if (!conn || !g_cs) return; if (!conn || !g_cs) return;
@ -1239,10 +1263,16 @@ static void cs_handle_channel_join(struct chat_sync* cs, uint64_t peer,
{ uint8_t evt[65]; uint8_t cl=(uint8_t)strlen(ch_id); evt[0]=cl; memcpy(evt+1,ch_id,cl); { uint8_t evt[65]; uint8_t cl=(uint8_t)strlen(ch_id); evt[0]=cl; memcpy(evt+1,ch_id,cl);
gui_bridge_post(GUI_EVT_MEMBERS_CHANGED, evt, 1+cl); } gui_bridge_post(GUI_EVT_MEMBERS_CHANGED, evt, 1+cl); }
cs_post_channel_online(cs, ch_id);
/* initiate member sync with the joiner (server side) */ /* initiate member sync with the joiner (server side) */
member_sync_start(cs->inst, node_id, ch_id, NULL, NULL); struct invite_sync_arg* sa = u_malloc(sizeof(struct invite_sync_arg));
DEBUG_INFO(DEBUG_CATEGORY_DB_SYNC, "%s: JOIN starting member_sync with joiner node=0x%016llx ch=%s", if (sa) { sa->node_id = node_id;
CS_ID, (unsigned long long)node_id, ch_id); strncpy(sa->ch_id, ch_id, sizeof(sa->ch_id) - 1); sa->ch_id[sizeof(sa->ch_id) - 1] = '\0';
member_sync_start(cs->inst, node_id, ch_id, _on_invite_sync_done, sa); }
else member_sync_start(cs->inst, node_id, ch_id, NULL, NULL);
DEBUG_INFO(DEBUG_CATEGORY_DB_SYNC, "%s: JOIN starting member_sync with joiner node=0x%016llx ch=%s done_cb=%s",
CS_ID, (unsigned long long)node_id, ch_id, sa ? "yes" : "no");
DEBUG_INFO(DEBUG_CATEGORY_DB_SYNC, "%s: JOIN accepted node=0x%016llx ch=%s addrs=%d", DEBUG_INFO(DEBUG_CATEGORY_DB_SYNC, "%s: JOIN accepted node=0x%016llx ch=%s addrs=%d",
CS_ID, (unsigned long long)node_id, ch_id, addr_cnt); CS_ID, (unsigned long long)node_id, ch_id, addr_cnt);

Loading…
Cancel
Save