Tag DM history snapshots with conversation generation
This commit is contained in:
1 parent
07f63c3047
commit
fd82e7bf1b
3 files changed
+18
-6
No files matched your search
+14
-4
@@ -1310,19 +1310,29 @@ void dm_call_route_trampoline(void* arg) {
|
||||
/* Ограниченный JSON-снимок доставляется GUI асинхронно, без доступа UI к instance/SQLite. */
|
||||
void dm_messages_trampoline(void* arg) {
|
||||
struct dm_messages_req* req = arg;
|
||||
if (!req) return;
|
||||
if (!req) { DEBUG_ERROR(DEBUG_CATEGORY_DM, "%s: missing history request", DM_ID); return; }
|
||||
struct UTUN_INSTANCE* inst = req->inst;
|
||||
char conv[64];
|
||||
snprintf(conv, sizeof(conv), "%s", req->conv_id);
|
||||
uint64_t generation = req->generation;
|
||||
u_free(req);
|
||||
if (!dm_of(inst)) { DEBUG_WARN(DEBUG_CATEGORY_DM, "%s: snapshot after stop", DM_ID); return; }
|
||||
if (!generation) generation = dm_history_generation(inst, conv);
|
||||
if (!dm_history_current(inst, conv, generation)) {
|
||||
DEBUG_INFO(DEBUG_CATEGORY_DM, "%s: skipped stale history conv=%s generation=%llu", DM_ID, conv,
|
||||
(unsigned long long)generation); return;
|
||||
}
|
||||
size_t cl = strlen(conv), cap = 1024 * 1024, len = 0;
|
||||
uint8_t* evt = u_malloc(1 + cl + cap);
|
||||
uint8_t* evt = u_malloc(9 + cl + cap);
|
||||
if (!evt) { DEBUG_ERROR(DEBUG_CATEGORY_DM, "%s: snapshot allocation failed", DM_ID); return; }
|
||||
evt[0] = (uint8_t)cl;
|
||||
memcpy(evt + 1, conv, cl);
|
||||
if (!dm_list_messages_json(inst, conv, 200, 0, (char*)evt + 1 + cl, cap, &len))
|
||||
chat_event_post(inst, CHAT_EVT_DM_MESSAGES, evt, (int)(1 + cl + len));
|
||||
memcpy(evt + 1 + cl, &generation, 8);
|
||||
if (!dm_list_messages_json(inst, conv, 200, 0, (char*)evt + 9 + cl, cap, &len)) {
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_DM, "%s: history snapshot conv=%s generation=%llu bytes=%zu", DM_ID, conv,
|
||||
(unsigned long long)generation, len);
|
||||
chat_event_post(inst, CHAT_EVT_DM_MESSAGES, evt, (int)(9 + cl + len));
|
||||
}
|
||||
u_free(evt);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user