New APIs for message processing loops

This patch adds new C APIs
dc_get_next_msgs() and dc_wait_next_msgs(),
and their JSON-RPC counterparts
get_next_msgs() and wait_next_msgs().

New configuration "last_msg_id"
tracks the last message ID processed by the bot.
get_next_msgs() returns message IDs above
the "last_msg_id".
wait_next_msgs() waits for new message notification
and calls get_next_msgs().
wait_next_msgs() can be used to build
a separate message processing loop
independent of the event loop.

Async Python API get_fresh_messages_in_arrival_order()
is deprecated in favor of get_next_messages().

Introduced Python APIs:
- Account.wait_next_incoming_message()
- Message.is_from_self()
- Message.is_from_device()

Introduced Rust APIs:
- Context.set_config_u32()
- Context.get_config_u32()
This commit is contained in:
link2xt
2023-04-12 21:48:14 +00:00
parent 28a13e98a6
commit fa87d2e225
18 changed files with 398 additions and 15 deletions

View File

@@ -308,6 +308,9 @@ pub enum Config {
/// This value is used internally to remember the MsgId of the logging xdc
#[strum(props(default = "0"))]
DebugLogging,
/// Last message processed by the bot.
LastMsgId,
}
impl Context {
@@ -358,6 +361,11 @@ impl Context {
Ok(self.get_config_parsed(key).await?.unwrap_or_default())
}
/// Returns 32-bit unsigned integer configuration value for the given key.
pub async fn get_config_u32(&self, key: Config) -> Result<u32> {
Ok(self.get_config_parsed(key).await?.unwrap_or_default())
}
/// Returns 64-bit signed integer configuration value for the given key.
pub async fn get_config_i64(&self, key: Config) -> Result<i64> {
Ok(self.get_config_parsed(key).await?.unwrap_or_default())
@@ -459,6 +467,12 @@ impl Context {
Ok(())
}
/// Set the given config to an unsigned 32-bit integer value.
pub async fn set_config_u32(&self, key: Config, value: u32) -> Result<()> {
self.set_config(key, Some(&value.to_string())).await?;
Ok(())
}
/// Set the given config to a boolean value.
pub async fn set_config_bool(&self, key: Config, value: bool) -> Result<()> {
self.set_config(key, if value { Some("1") } else { Some("0") })