diff --git a/src/chat/chat_core.h b/src/chat/chat_core.h index d39c70a5..4da44ea8 100644 --- a/src/chat/chat_core.h +++ b/src/chat/chat_core.h @@ -68,8 +68,8 @@ struct chat_msg_submit { uint32_t data_len; /* размер data в байтах */ uint64_t timestamp; /* успешная отправка возвращает назначенное время */ uint8_t message_id[32]; /* успешная обычная отправка возвращает общий ID */ - uint64_t reply_to_ts; /* 0 = не ответ */ - uint64_t reply_to_node_id; /* node_id автора исходного сообщения */ + uint8_t reply_to[32]; /* общий ID оригинала в этом канале; нули = не ответ */ + uint64_t request_id; /* ненулевой ID: trampoline/media отправляет CHAT_EVT_MSG_SUBMITTED */ }; /* Подписать, сохранить и разослать сообщение. req/data остаются у вызывающего. 0/-1. */ diff --git a/src/chat/chat_event.c b/src/chat/chat_event.c index 5f1156f0..fd2509ce 100644 --- a/src/chat/chat_event.c +++ b/src/chat/chat_event.c @@ -51,12 +51,23 @@ void chat_event_post(struct UTUN_INSTANCE* inst, int type, const uint8_t* data, [44]="CALL_CONNECTION", [45]="DM_CONVERSATIONS", [46]="ATTACHMENT_PREPARATION", [47]="DM_CALL_ROUTE", [55]="RADIO_MUTE_RESULT", + [56]="MSG_SUBMITTED", }; const char* n = (type >= 1 && type < (int)(sizeof(names) / sizeof(names[0]))) ? names[type] : "?"; DEBUG_DEBUG(DEBUG_CATEGORY_CHAT, "chat_event: %s(%d) data=%d bytes", n, type, len); if (data && len > 0) log_dump(DEBUG_LEVEL_DEBUG, DEBUG_CATEGORY_CHAT, " ", data, len); } +/* Идентификатор связывает результат с конкретной отправкой, независимо от текущего канала GUI. */ +void chat_event_submitted(struct UTUN_INSTANCE* inst, uint64_t request_id, int success) { + if (!request_id) return; + uint8_t data[9]; + for (unsigned i = 0; i < 8; i++) data[i] = (uint8_t)(request_id >> (8 * i)); + data[8] = success != 0; + DEBUG_DEBUG(DEBUG_CATEGORY_CHAT, "message submit result: request=%llu success=%d", (unsigned long long)request_id, success); + chat_event_post(inst, CHAT_EVT_MSG_SUBMITTED, data, sizeof(data)); +} + /* ID задачи не даёт позднему завершению изменить статус другой подготовки. */ void chat_event_attachment(struct UTUN_INSTANCE* inst, int is_dm, const char* target, const uint8_t id[16], int state) { char name[68]; diff --git a/src/chat/chat_event.h b/src/chat/chat_event.h index ad317dc3..9c9ee28a 100644 --- a/src/chat/chat_event.h +++ b/src/chat/chat_event.h @@ -77,12 +77,15 @@ extern "C" { #define CHAT_EVT_FEEDBACK_CHANGED 53 /* [channel_len:1][channel][message_id:32][kind:1] — состояние после commit */ #define CHAT_EVT_FEEDBACK_RESULT 54 /* [request_id:8LE][success:1][JSON] — результат команды интерфейса */ #define CHAT_EVT_RADIO_MUTE_RESULT 55 /* [group_id:8LE][node_id:8LE][success:1] — локальный переключатель рации */ +#define CHAT_EVT_MSG_SUBMITTED 56 /* [request_id:8LE][success:1] — результат локального сохранения сообщения */ typedef void (*chat_event_handler_fn)(struct UTUN_INSTANCE* inst, int type, const uint8_t* data, int len); void chat_event_set_handler(struct UTUN_INSTANCE* inst, chat_event_handler_fn handler); void chat_event_post(struct UTUN_INSTANCE* inst, int type, const uint8_t* data, int len); void chat_event_attachment(struct UTUN_INSTANCE* inst, int is_dm, const char* target, const uint8_t id[16], int state); +/* request_id=0 отключает подтверждение; вызывается один раз после сохранения либо ошибки подготовки. */ +void chat_event_submitted(struct UTUN_INSTANCE* inst, uint64_t request_id, int success); #ifdef __cplusplus }