Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simon/better draft api in jsonrpc #6426

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Simon-Laux
Copy link
Member

@Simon-Laux Simon-Laux commented Jan 12, 2025

  • 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

message.set_text(text);
message
.get_chat_id()
.set_draft(&ctx, Some(&mut message))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit ugly that this function sets the draft, so if there are concurrent calls to e.g. draft_set_text and draft_set_subject, only one will be applied.

Maybe better manage the draft in the UI and call only create_draft and some sort of "send message" API that sends the draft passed from the UI as a whole and resets the draft?

The idea of managing the draft on the core side and updating it does not look like a good API to me, it's just how it is historically.

If we at some point make it possible to connect to remote core, managing the draft over high-latency JSON-RPC connection is going to be even worse.

@link2xt
Copy link
Collaborator

link2xt commented Jan 12, 2025

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.

@Simon-Laux Simon-Laux self-assigned this Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

not possible to send webxdc app staged in draft with JSON-RPC API
2 participants