From 96e9a8badddcb6efcfc1e9f73f20cc1cbd338bd5 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Fri, 11 Apr 2025 21:54:10 +0200 Subject: [PATCH] also load attachments in note_load_content --- application/note.c | 41 +++++++++++++++++++++++++++++++++++------ application/store.c | 4 ++-- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/application/note.c b/application/note.c index d3f97ce..b97267f 100644 --- a/application/note.c +++ b/application/note.c @@ -101,19 +101,48 @@ void notemodel_set_note(NoteModel *model, Resource *note) { } } +typedef struct LoadNoteContent { + Resource *note; + UiBool content; + UiBool attachments; +} LoadNoteContent; -static void note_content_loaded(UiEvent *event, cxmutstr result, void *userdata) { - Resource *note = userdata; - note->content = result; - printf("note content: %s\n", result.ptr); +static void note_loading_completed(LoadNoteContent *op) { + Resource *note = op->note; + free(op); + if(note->model) { - editor_load_markdown(note->model->text, result); + editor_load_markdown(note->model->text, note->content); } note->content_loaded = TRUE; } +static void note_content_loaded(UiEvent *event, cxmutstr result, void *userdata) { + LoadNoteContent *op = userdata; + op->note->content = result; + printf("note content: %s\n", result.ptr); + op->content = TRUE; + if(op->attachments) { + note_loading_completed(op); + } +} + +static void note_attachments_loaded(UiEvent *event, int error, void *userdata) { + LoadNoteContent *op = userdata; + op->attachments = TRUE; + if(op->content) { + note_loading_completed(op); + } +} + void note_load_content(UiObject *obj, NotebookModel *notebook, Resource *note) { - note_store_get_note_content_async(obj, notebook->current_notes_pool->allocator, note->resource_id, note_content_loaded, note); + LoadNoteContent *op = malloc(sizeof(LoadNoteContent)); + op->note = note; + op->content = FALSE; + op->attachments = FALSE; + + note_store_get_note_content_async(obj, notebook->current_notes_pool->allocator, note->resource_id, note_content_loaded, op); + note_store_load_note_attachments_async(obj, note, note_attachments_loaded, op); } void note_add_attachment(Resource *note, Attachment *attachment) { diff --git a/application/store.c b/application/store.c index 75be1a7..a434e74 100644 --- a/application/store.c +++ b/application/store.c @@ -76,7 +76,7 @@ #define SQL_ATTACHMENTS_GET "select attachment_id, attachment_resource_id, parent_resource_id, a.type, "\ "r.name, r.bin_content from attachments a "\ - "inner join resource r on a.attachment_resource_id = r.resource_id " \ + "inner join resources r on a.attachment_resource_id = r.resource_id " \ "where parent_resource_id = ? order by attachment_id;" static DBUConnection *connection; @@ -723,9 +723,9 @@ static void uithr_load_attachments_finished(UiEvent *event, LoadAttachmentsJob * if(job->result) { CxMempool *note_mp = job->note->model->note_allocator->data; cxMempoolTransfer(job->temp_mp, note_mp); - cxMempoolFree(job->temp_mp); job->note->attachments = job->result; } + cxMempoolFree(job->temp_mp); if(job->resultcb) { job->resultcb(event, job->error, job->userdata); -- 2.43.5