Prepare channel history before enabling network synchronization
This commit is contained in:
1 parent
865657b3bd
commit
6a67cc2038
3 files changed
+6
-8
No files matched your search
@@ -64,16 +64,14 @@ void chat_core_ensure_channel_ready(struct UTUN_INSTANCE* inst, const char* ch_i
|
||||
char tbl_msg[80]; msg_table_name(ch_id, tbl_msg, sizeof(tbl_msg));
|
||||
|
||||
uint64_t gid = strtoull(ch_id, NULL, 10);
|
||||
struct DB_SYNC_INSTANCE* si = db_sync_instance_add(inst, tbl_msg, gid, 1);
|
||||
|
||||
if (gid != 0 && inst->topo_groups && !topo_groups_find(inst->topo_groups, gid)) {
|
||||
struct TOPO_GROUP* g = topo_groups_create_group(inst->topo_groups, gid, TOPO_GROUP_TYPE_CHAT, ch_id);
|
||||
if (g) member_sync_subscribe_group(inst, g);
|
||||
}
|
||||
struct DB_SYNC_INSTANCE* si = db_sync_instance_add(inst, tbl_msg, gid);
|
||||
if (si) {
|
||||
si_register(inst, si, ch_id);
|
||||
db_sync_set_insert_cb(si, on_msg_inserted, inst);
|
||||
db_sync_instance_set_gated(si, 1);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CHAT_SYNC, "%s: channel ready ch=%s tbl=%s group=0x%016llx",
|
||||
CC_ID, ch_id, tbl_msg, (unsigned long long)gid);
|
||||
} else {
|
||||
|
||||
@@ -1454,7 +1454,6 @@ static void cs_handle_join_ready(struct chat_sync* cs, uint64_t peer,
|
||||
evt[0] = ch_id_len; memcpy(evt + 1, ch_id, ch_id_len);
|
||||
chat_event_post(cs->inst, CHAT_EVT_CHANNEL_UPDATED, evt, 1 + ch_id_len);
|
||||
cs_post_channel_online(cs, ch_id);
|
||||
cs_resume_db_sync(cs, ch_id);
|
||||
|
||||
if (cs->pending_invite_ch_id != 0) {
|
||||
uint64_t ch_id_num = strtoull(ch_id, NULL, 10);
|
||||
|
||||
+5
-4
@@ -41,6 +41,7 @@ struct DB_SYNC_INSTANCE;
|
||||
// Error codes for DB_MSG_ERROR
|
||||
#define DB_ERR_NOT_FOUND 0x01 // instance not found
|
||||
#define DB_ERR_DISABLED 0x02 // instance exists but disabled
|
||||
#define DB_ERR_NOT_READY 0x03 // участники или групповая сессия ещё не готовы
|
||||
|
||||
// Defaults
|
||||
#define DB_SYNC_DEFAULT_TTL 86400
|
||||
@@ -65,8 +66,8 @@ int db_sync_enable(struct UTUN_INSTANCE* inst);
|
||||
// Отменить таймеры/обмен, снять обработчики; общую SQLite не закрывает.
|
||||
void db_sync_destroy(struct UTUN_INSTANCE* inst);
|
||||
|
||||
// Зарегистрировать/найти таблицу для group_id. auto_sync запускает начальный обмен; NULL при ошибке.
|
||||
struct DB_SYNC_INSTANCE* db_sync_instance_add(struct UTUN_INSTANCE* inst, const char* table_name, uint64_t group_id, int auto_sync);
|
||||
// Зарегистрировать таблицу существующей группы без сетевого обмена; первоначально gated. NULL при ошибке.
|
||||
struct DB_SYNC_INSTANCE* db_sync_instance_add(struct UTUN_INSTANCE* inst, const char* table_name, uint64_t group_id);
|
||||
// Освободить экземпляр синхронизации; сама таблица остаётся в БД.
|
||||
void db_sync_instance_remove(struct DB_SYNC_INSTANCE* si);
|
||||
// Заимствованный указатель по group_id; действителен до remove/destroy, NULL если нет.
|
||||
@@ -115,8 +116,8 @@ void db_sync_peer_set_state(struct DB_SYNC_INSTANCE* si, uint64_t node_id, uint8
|
||||
// Per-(chat,peer) «play sound on message» flag: sound_off + sleeping peer → throttled.
|
||||
void db_sync_set_peer_sound(struct UTUN_INSTANCE* inst, uint64_t group_id, uint64_t peer_node_id, int sound_on);
|
||||
|
||||
// Gate auto-sync: while gated the instance does not auto-initiate sync (waits for
|
||||
// member_sync/pubkeys). Un-gating launches sync to peers in sync_state==0.
|
||||
// До успешного member_sync блокирует входящий и исходящий обмен. После снятия
|
||||
// блокировки запускает историю только через READY-пиров этой группы.
|
||||
void db_sync_instance_set_gated(struct DB_SYNC_INSTANCE* si, int gated);
|
||||
|
||||
// Force re-initiate sync to a specific peer (for testing)
|
||||
|
||||
Reference in new issue
Block a user