Expose leave chat to iOS bridge
This commit is contained in:
@@ -249,6 +249,10 @@ impl<C: TdClientTrait> CoreSession<C> {
|
||||
Ok(profile)
|
||||
}
|
||||
|
||||
pub async fn leave_chat(&mut self, chat_id: ChatId) -> Result<(), String> {
|
||||
self.client.leave_chat(chat_id).await
|
||||
}
|
||||
|
||||
pub async fn set_draft(&mut self, chat_id: ChatId, text: String) -> Result<(), String> {
|
||||
self.client.set_draft_message(chat_id, text.clone()).await?;
|
||||
self.enqueue_event(CoreEvent::DraftChanged(CoreDraft { chat_id, text }));
|
||||
@@ -851,6 +855,7 @@ mod tests {
|
||||
session.emit_auth_state();
|
||||
session.emit_network_state();
|
||||
let loaded_profile = session.open_profile(ChatId::new(42)).await.unwrap();
|
||||
session.leave_chat(ChatId::new(42)).await.unwrap();
|
||||
session
|
||||
.set_draft(ChatId::new(42), "Later".to_string())
|
||||
.await
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user