Expose iOS copy payload API
This commit is contained in:
@@ -218,6 +218,20 @@ impl<C: TdClientTrait> CoreSession<C> {
|
||||
.collect())
|
||||
}
|
||||
|
||||
pub async fn copy_payload(
|
||||
&mut self,
|
||||
chat_id: ChatId,
|
||||
message_id: MessageId,
|
||||
) -> Result<String, String> {
|
||||
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<CoreProfile, String> {
|
||||
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![
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user