-
-
Notifications
You must be signed in to change notification settings - Fork 100
Add API to get next fresh message #3777
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
Conversation
Rust: Context.get_next_fresh_msg() C: dc_get_next_fresh_msg() JSON-RPC: get_next_fresh_msg method
* | ||
* @memberof dc_context_t | ||
* @param context The context object as returned from dc_context_new(). | ||
* @return Message ID of the next fresh message. Returns 0 on error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if there is no next fresh message?
@@ -751,6 +760,19 @@ impl Context { | |||
Ok(list) | |||
} | |||
|
|||
/// Returns oldest fresh message in unmuted and unblocked chats. | |||
/// | |||
/// If there are no such messages, waits until there is one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
waits until there is one.
is this also true for cffi/jsonprc? if so, this information should be added to the docs there as well.
maybe also add a line for the usecase. though i am sure, there is concrete need somewhere, the uscase is not clear to at least to me :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or maybe better rename the function to wait_for_next_fresh_message()
, i would not expect a get
-function to block for maybe hours.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I named it similarly to get_next_event()
for consistency. We can call it something with wait
, but then there can be an impression that get_next_event()
is somehow different and non-blocking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, get_next_event() is called on an explicit event emitter object that does not have many other usages, so that seems less confusing than for the context where all the other get() work differently.
but i agree, wait() would have been better for the context emitter as well.
i still suggest to not repeat the "mistake" use sth. with "wait" in the name here. maybe we can rename the other usages accordingly when we iterate over or so.
@r10s The use case is to make it easier to write bots that have only a single thread and loop for the next message to process in infinite loop, then process them, then mark as read, like this:
Then you can be sure all messages are processed in the order they arrive, bot processes old messages after starting and never forgets about incoming message because it was busy processing another message already. It makes easier to quick start with bots without using any frameworks. There is a PR with a quickstart deltachat-bot/bot-pages#45 but example code is currently busy looping on Users can then switch to advanced techniques like writing an event loop that, processing events and so on, but then there is a need to think about how message processing (initial processing of old messages and new messages that arrive while the bot works) works together with event processing, use some synchronization primitives available in the language bot is written in etc. With this simple API synchronization is done in the core. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, i'd modify the name and maybe add a line "this is mainly useful for bot usage" or so to the comment.
but these are no blockers.
I still don't like that there is no way to stop this loop. With events loop you call Maybe it really makes more sense to have a function that only waits and may be interrupted, but you have to check if there are actually any messages yourself. |
I found a better way to do a simple bot without IPC and all this stuff. An echo bot in #3734 is running an event loop in the main task and has a separate function that processes all fresh messages. Will try to get it into quickstart guide then. |
Rust: Context.get_next_fresh_msg()
C: dc_get_next_fresh_msg()
JSON-RPC: get_next_fresh_msg method