deltachat-core-rust icon indicating copy to clipboard operation
deltachat-core-rust copied to clipboard

simon/better draft api in jsonrpc

Open Simon-Laux opened this issue 10 months ago • 1 comments

  • feat: jsonrpc: add create_draft, draft_set_text, draft_set_subject, draft_set_quoted_message, draft_set_quoted_text
  • refactor: jsonrpc: deprecate misc_set_draft andmisc_send_draft

Still a work in progress. Preparation for Composer refactoring in desktop.

Why did I choose that message id instead of just using the current draft based on chat id? Because using the message id is more robust and has less potential for unexpected behaviour, since the UI always knows what message it is editing or sending because of the message id. The motto is: don't rely on global state.

closes #4643

Simon-Laux avatar Jan 12 '25 03:01 Simon-Laux

Less stateful API could be like this:

  • set_draft() that takes a whole draft as a JSON object and stores it into the database, returning msg_id for use with WebXDC. UI calls it with some debouncing when user changes things in the composer, but the whole draft is stored as a whole. If there is already a draft set, msg_id should be preserved so WebXDC updates are not lost. If new draft has a different attachment path, new msg_id should be returned so WebXDC updates are dropped.
  • load_draft() which returns the whole message object. msg_id is part of the object. This is called by the UI when opening a chat.
  • send_msg() which takes the messages object from the composer and sends it. If the chat has a draft, the draft should be updated with the given message object and sent without changing the draft msg_id, so existing WebXDC updates are preserved. When the function returns, draft should be cleared.

If there are concurrent calls to set_draft(), load_draft() etc. for whatever reason, and they return different msg_id, the result with the lower than current msg_id should be ignored. UI unfortunately needs to track current msg_id because of WebXDC, but otherwise I'd avoid passing it around as much as possible.

link2xt avatar Jan 12 '25 09:01 link2xt