From 5ac63b84fb1fd21757c6b9b3cc987f4875c52ece Mon Sep 17 00:00:00 2001 From: Mikhail Kilin Date: Wed, 20 May 2026 23:56:18 +0300 Subject: [PATCH] Expose iOS copy payload API --- crates/tele-core/src/session.rs | 19 +++++++++++++++++++ crates/tele-ios-ffi/src/lib.rs | 18 ++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/crates/tele-core/src/session.rs b/crates/tele-core/src/session.rs index 57c6b39..03fe8bd 100644 --- a/crates/tele-core/src/session.rs +++ b/crates/tele-core/src/session.rs @@ -218,6 +218,20 @@ impl CoreSession { .collect()) } + pub async fn copy_payload( + &mut self, + chat_id: ChatId, + message_id: MessageId, + ) -> Result { + self.client + .get_chat_history(chat_id, i32::MAX) + .await? + .into_iter() + .find(|message| message.id() == message_id) + .map(|message| message.text().to_string()) + .ok_or_else(|| "message not found".to_string()) + } + pub async fn open_profile(&mut self, chat_id: ChatId) -> Result { let profile = self .client @@ -871,6 +885,10 @@ mod tests { .edit_text_message(chat_id, MessageId::new(10), "After".to_string()) .await .unwrap(); + let copied = session + .copy_payload(chat_id, MessageId::new(10)) + .await + .unwrap(); session .delete_messages(chat_id, vec![MessageId::new(10)], true) .await @@ -878,6 +896,7 @@ mod tests { assert_eq!(sent.text, "Hello"); assert_eq!(edited.text, "After"); + assert_eq!(copied, "After"); assert_eq!( session.poll_events(), vec![ diff --git a/crates/tele-ios-ffi/src/lib.rs b/crates/tele-ios-ffi/src/lib.rs index cc1fd57..cc25006 100644 --- a/crates/tele-ios-ffi/src/lib.rs +++ b/crates/tele-ios-ffi/src/lib.rs @@ -690,6 +690,13 @@ impl SessionHandle { .map_err(IosFfiError::from) } + pub fn copy_payload(&self, chat_id: i64, message_id: i64) -> Result { + let mut session = self.session.lock().expect("session mutex poisoned"); + self.runtime + .block_on(session.copy_payload(ChatId::new(chat_id), MessageId::new(message_id))) + .map_err(IosFfiError::from) + } + pub fn download_photo(&self, file_id: i32) -> Result { let session = self.session.lock().expect("session mutex poisoned"); self.runtime @@ -1175,6 +1182,16 @@ impl SessionHandle { Ok(()) } + pub fn copy_payload(&self, chat_id: i64, message_id: i64) -> Result { + let state = self.state.lock().expect("session mutex poisoned"); + state + .messages + .get(&chat_id) + .and_then(|messages| messages.iter().find(|message| message.id == message_id)) + .map(|message| message.text.clone()) + .ok_or_else(|| IosFfiError::Operation { message: "message not found".to_string() }) + } + pub fn download_photo(&self, file_id: i32) -> Result { self.standalone_download_file(file_id) } @@ -1265,6 +1282,7 @@ mod tests { .send_message(chats[0].id, "Hi from Swift".to_string(), None) .unwrap(); assert_eq!(sent.text, "Hi from Swift"); + assert_eq!(session.copy_payload(chats[0].id, sent.id).unwrap(), "Hi from Swift"); let reactions = session .react(chats[0].id, sent.id, "👍".to_string())