deltachat-core-rust
deltachat-core-rust copied to clipboard
simon/better draft api in jsonrpc
- feat: jsonrpc: add
create_draft,draft_set_text,draft_set_subject,draft_set_quoted_message,draft_set_quoted_text - refactor: jsonrpc: deprecate
misc_set_draftandmisc_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
Less stateful API could be like this:
set_draft()that takes a whole draft as a JSON object and stores it into the database, returningmsg_idfor 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_idshould be preserved so WebXDC updates are not lost. If new draft has a different attachment path, newmsg_idshould be returned so WebXDC updates are dropped.load_draft()which returns the whole message object.msg_idis 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.