diff --git a/src/chat/chat_event.c b/src/chat/chat_event.c index 4ecceabb..5625c329 100644 --- a/src/chat/chat_event.c +++ b/src/chat/chat_event.c @@ -9,6 +9,8 @@ #include "chat_event.h" #include "../utun_instance.h" #include "../lib/debug_config.h" +#include +#include #ifdef __ANDROID__ #include @@ -47,8 +49,21 @@ void chat_event_post(struct UTUN_INSTANCE* inst, int type, const uint8_t* data, [40]="CALL_ERROR", [41]="DM_MESSAGES", [42]="CALL_PATH", [43]="RADIO_TALK", [44]="CALL_CONNECTION", + [45]="DM_CONVERSATIONS", [46]="ATTACHMENT_PREPARATION", }; 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); } + +/* 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]; + int n = snprintf(name, sizeof(name), "%s%s", is_dm ? "dm:" : "", target); + if (n <= 0 || (size_t)n >= sizeof(name) || state < 0 || state > 2) { + DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "attachment: invalid preparation event target=%s state=%d", target, state); return; + } + uint8_t data[1 + 68 + 16 + 1]; + data[0] = (uint8_t)n; memcpy(data + 1, name, (size_t)n); memcpy(data + 1 + n, id, 16); data[17 + n] = (uint8_t)state; + chat_event_post(inst, CHAT_EVT_ATTACHMENT_PREPARATION, data, n + 18); +} diff --git a/src/chat/chat_event.h b/src/chat/chat_event.h index 898eb400..4093c9f0 100644 --- a/src/chat/chat_event.h +++ b/src/chat/chat_event.h @@ -66,11 +66,13 @@ extern "C" { #define CHAT_EVT_RADIO_TALK 43 /* [group_id:8][src_node_id:8][stream_id:2][on:1] — кто-то начал/закончил говорить */ #define CHAT_EVT_CALL_CONNECTION 44 /* [call_id:8][CONN_TYPE:1][next_hop_node_id:8] — текущий путь отправки звонка */ #define CHAT_EVT_DM_CONVERSATIONS 45 /* [JSON:utf8] — последние 200 личных бесед */ +#define CHAT_EVT_ATTACHMENT_PREPARATION 46 /* [target_len:1][target:var][job_uuid:16][state:1], 0=start 1=ready 2=failed */ 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); #ifdef __cplusplus }