Expose leave chat to iOS bridge

This commit is contained in:
Mikhail Kilin
2026-05-21 00:45:39 +03:00
parent 928a5aeda2
commit f7abd1dba0
7 changed files with 57 additions and 0 deletions

View File

@@ -638,6 +638,13 @@ impl SessionHandle {
.map_err(IosFfiError::from)
}
pub fn leave_chat(&self, chat_id: i64) -> Result<(), IosFfiError> {
let mut session = self.session.lock().expect("session mutex poisoned");
self.runtime
.block_on(session.leave_chat(ChatId::new(chat_id)))
.map_err(IosFfiError::from)
}
pub fn send_message(
&self,
chat_id: i64,
@@ -1072,6 +1079,16 @@ impl SessionHandle {
Ok(profile)
}
pub fn leave_chat(&self, chat_id: i64) -> Result<(), IosFfiError> {
let mut state = self.state.lock().expect("session mutex poisoned");
state.chats.retain(|chat| chat.id != chat_id);
state.messages.remove(&chat_id);
state.profiles.remove(&chat_id);
let chats = state.chats.clone();
state.events.push(IosEvent::ChatListChanged { chats });
Ok(())
}
pub fn send_message(
&self,
chat_id: i64,
@@ -1374,6 +1391,11 @@ mod tests {
assert!(events
.iter()
.any(|event| matches!(event, IosEvent::IncomingNotificationCandidate { .. })));
session.leave_chat(chats[0].id).unwrap();
if !cfg!(feature = "core-session") {
assert!(session.load_history(chats[0].id, 20).unwrap().is_empty());
}
}
#[test]