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

@@ -1666,6 +1666,7 @@ impl Chat {
],
)
.await?;
context.new_msgs_notify.notify_one();
msg.id = MsgId::new(u32::try_from(raw_id)?);
maybe_set_logging_xdc(context, msg, self.id).await?;
@@ -3628,6 +3629,7 @@ pub async fn add_device_msg_with_importance(
),
)
.await?;
context.new_msgs_notify.notify_one();
msg_id = MsgId::new(u32::try_from(row_id)?);
if !msg.hidden {
@@ -3741,6 +3743,7 @@ pub(crate) async fn add_info_msg_with_cmd(
parent.map(|msg|msg.rfc724_mid.clone()).unwrap_or_default()
)
).await?;
context.new_msgs_notify.notify_one();
let msg_id = MsgId::new(row_id.try_into()?);
context.emit_msgs_changed(chat_id, msg_id);