Expose iOS copy payload API

This commit is contained in:
Mikhail Kilin
2026-05-20 23:56:18 +03:00
parent c83d2a1354
commit 5ac63b84fb
2 changed files with 37 additions and 0 deletions

View File

@@ -690,6 +690,13 @@ impl SessionHandle {
.map_err(IosFfiError::from)
}
pub fn copy_payload(&self, chat_id: i64, message_id: i64) -> Result<String, IosFfiError> {
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<IosDownloadedFile, IosFfiError> {
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<String, IosFfiError> {
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<IosDownloadedFile, IosFfiError> {
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())