@ -11,6 +11,7 @@
# include "../../../lib/json_flat.h"
# include "../../../lib/json_flat.h"
# include "topo_node_sqlite.h"
# include "topo_node_sqlite.h"
# include "topo_group.h"
# include "topo_group.h"
# include "topo_group_connect.h"
# include "member_sync.h"
# include "member_sync.h"
# include "../../../src/utun_instance.h"
# include "../../../src/utun_instance.h"
@ -755,6 +756,39 @@ void chat_core_create_channel_trampoline(void* arg) {
u_free ( req ) ;
u_free ( req ) ;
}
}
/* ─── управление подключением к каналу (выбор в GUI) ─── */
void chat_core_connect_channel ( const char * ch_id ) {
DEBUG_TRACE ( DEBUG_CATEGORY_CONNECTIVITY , " %s: connect_channel called ch_id=%s initialized=%d " , CC_ID , ch_id ? ch_id : " (null) " , g_cc . initialized ) ;
if ( ! g_cc . initialized | | ! ch_id | | ! ch_id [ 0 ] ) { DEBUG_WARN ( DEBUG_CATEGORY_CONNECTIVITY , " %s: connect_channel — skip (not ready) " , CC_ID ) ; return ; }
if ( ! g_cc . inst - > topo_groups ) { DEBUG_ERROR ( DEBUG_CATEGORY_CONNECTIVITY , " %s: connect_channel — no topo_groups " , CC_ID ) ; return ; }
uint64_t gid = strtoull ( ch_id , NULL , 10 ) ;
if ( gid = = 0 ) { DEBUG_ERROR ( DEBUG_CATEGORY_CONNECTIVITY , " %s: connect_channel — invalid ch_id=%s " , CC_ID , ch_id ) ; return ; }
chat_core_ensure_channel_ready ( ch_id ) ;
struct TOPO_GROUP * group = topo_groups_find ( g_cc . inst - > topo_groups , gid ) ;
if ( ! group ) { DEBUG_ERROR ( DEBUG_CATEGORY_CONNECTIVITY , " %s: connect_channel — group not found ch=%s gid=%016llx total_groups=%d " , CC_ID , ch_id , ( unsigned long long ) gid , queue_entry_count ( g_cc . inst - > topo_groups - > group_list ) ) ; return ; }
if ( group - > connect ) {
DEBUG_INFO ( DEBUG_CATEGORY_CONNECTIVITY , " %s: connect_channel — already in progress ch=%s active=%d " ,
CC_ID , ch_id , topo_group_connect_active_count ( group ) ) ;
return ;
}
DEBUG_INFO ( DEBUG_CATEGORY_CONNECTIVITY , " %s: connect_channel ch=%s gid=%016llx group_type=%d — starting connect_init " , CC_ID , ch_id , ( unsigned long long ) gid , group - > group_type ) ;
topo_group_connect_init ( group ) ;
}
void chat_core_connect_channel_trampoline ( void * arg ) {
char * ch_id = ( char * ) arg ;
DEBUG_TRACE ( DEBUG_CATEGORY_CONNECTIVITY , " %s: connect_channel_trampoline ch_id=%s " , CC_ID , ch_id ? ch_id : " (null) " ) ;
if ( ! ch_id ) return ;
chat_core_connect_channel ( ch_id ) ;
u_free ( ch_id ) ;
}
/* ─── db_sync helpers ─── */
/* ─── db_sync helpers ─── */
static void on_msg_inserted ( struct DB_SYNC_INSTANCE * si , uint64_t record_ts , const char * data , size_t len , uint64_t author , void * arg ) {
static void on_msg_inserted ( struct DB_SYNC_INSTANCE * si , uint64_t record_ts , const char * data , size_t len , uint64_t author , void * arg ) {