Expose pinned messages through iOS FFI

This commit is contained in:
Mikhail Kilin
2026-05-21 00:23:33 +03:00
parent 161cc343da
commit 4fd2a18ed9
5 changed files with 64 additions and 5 deletions

View File

@@ -591,6 +591,14 @@ impl SessionHandle {
.map_err(IosFfiError::from)
}
pub fn pinned_messages(&self, chat_id: i64) -> Result<Vec<IosMessage>, IosFfiError> {
let mut session = self.session.lock().expect("session mutex poisoned");
self.runtime
.block_on(session.pinned_messages(ChatId::new(chat_id)))
.map(|messages| messages.into_iter().map(IosMessage::from).collect())
.map_err(IosFfiError::from)
}
pub fn open_profile(&self, chat_id: i64) -> Result<IosProfile, IosFfiError> {
let mut session = self.session.lock().expect("session mutex poisoned");
self.runtime
@@ -766,13 +774,15 @@ fn seeded_fake_client() -> FakeTdClient {
online_status: Some("online".to_string()),
};
FakeTdClient::new()
let mut client = FakeTdClient::new()
.with_chat(chat.clone())
.with_message(chat.id.as_i64(), message)
.with_message(chat.id.as_i64(), message.clone())
.with_profile(chat.id.as_i64(), profile)
.with_network_state(NetworkState::Ready)
.with_downloaded_file(100, "/tmp/fake-photo.jpg")
.with_downloaded_file(200, "/tmp/fake-voice.ogg")
.with_downloaded_file(200, "/tmp/fake-voice.ogg");
client.set_current_pinned_message(Some(message));
client
}
#[derive(uniffi::Object)]
@@ -1002,6 +1012,18 @@ impl SessionHandle {
.collect())
}
pub fn pinned_messages(&self, chat_id: i64) -> Result<Vec<IosMessage>, IosFfiError> {
let state = self.state.lock().expect("session mutex poisoned");
Ok(state
.messages
.get(&chat_id)
.cloned()
.unwrap_or_default()
.into_iter()
.take(1)
.collect())
}
pub fn open_profile(&self, chat_id: i64) -> Result<IosProfile, IosFfiError> {
let mut state = self.state.lock().expect("session mutex poisoned");
let profile = state
@@ -1277,6 +1299,8 @@ mod tests {
let history = session.load_history(chats[0].id, 20).unwrap();
assert_eq!(history[0].text, "Hello from fake TDLib");
let pinned = session.pinned_messages(chats[0].id).unwrap();
assert_eq!(pinned[0].text, "Hello from fake TDLib");
let sent = session
.send_message(chats[0].id, "Hi from Swift".to_string(), None)