Preserve typing events in iOS FFI

This commit is contained in:
Mikhail Kilin
2026-05-21 00:41:18 +03:00
parent b3b02835b6
commit 928a5aeda2
6 changed files with 80 additions and 2 deletions

View File

@@ -7,7 +7,7 @@ use std::collections::HashMap;
use tele_core::session::{
CoreAuthState, CoreChatSummary, CoreDownloadedFile, CoreDraft, CoreEvent, CoreFolder,
CoreMedia, CoreMessage, CoreNetworkState, CoreProfile, CoreReaction, CoreSearchResult,
CoreSession,
CoreSession, CoreTypingState,
};
#[cfg(feature = "core-session")]
use tele_core::tdlib::{ChatInfo, MessageBuilder, NetworkState, ProfileInfo};
@@ -86,6 +86,30 @@ impl From<CoreNetworkState> for IosNetworkState {
}
}
#[derive(Debug, Clone, PartialEq, Eq, uniffi::Enum)]
pub enum IosTypingState {
Idle,
Typing {
chat_id: i64,
user_id: i64,
text: String,
},
}
#[cfg(feature = "core-session")]
impl From<CoreTypingState> for IosTypingState {
fn from(value: CoreTypingState) -> Self {
match value {
CoreTypingState::Idle => Self::Idle,
CoreTypingState::Typing { chat_id, user_id, text } => Self::Typing {
chat_id: chat_id.as_i64(),
user_id: user_id.as_i64(),
text,
},
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, uniffi::Enum)]
pub enum IosDownloadState {
NotDownloaded,
@@ -412,6 +436,9 @@ pub enum IosEvent {
downloaded_size: i64,
total_size: i64,
},
TypingChanged {
state: IosTypingState,
},
}
#[cfg(feature = "core-session")]
@@ -455,7 +482,7 @@ impl From<CoreEvent> for IosEvent {
CoreEvent::MediaDownloadProgress { file_id, downloaded_size, total_size } => {
Self::MediaDownloadProgress { file_id, downloaded_size, total_size }
}
CoreEvent::TypingChanged(_) => Self::NetworkChanged { state: IosNetworkState::Ready },
CoreEvent::TypingChanged(state) => Self::TypingChanged { state: state.into() },
}
}
}
@@ -1363,4 +1390,21 @@ mod tests {
assert!(format!("{error}").contains("real TDLib sessions"));
}
#[cfg(feature = "core-session")]
#[test]
fn typing_events_are_preserved_for_ios() {
let event = IosEvent::from(CoreEvent::TypingChanged(CoreTypingState::Typing {
chat_id: ChatId::new(1),
user_id: tele_core::types::UserId::new(2),
text: "typing".to_string(),
}));
assert!(matches!(
event,
IosEvent::TypingChanged {
state: IosTypingState::Typing { chat_id: 1, user_id: 2, text }
} if text == "typing"
));
}
}