Some checks failed
ci/woodpecker/pr/check Pipeline failed
CI / Check (pull_request) Has been cancelled
CI / Format (pull_request) Has been cancelled
CI / Clippy (pull_request) Has been cancelled
CI / Build (macos-latest) (pull_request) Has been cancelled
CI / Build (ubuntu-latest) (pull_request) Has been cancelled
CI / Build (windows-latest) (pull_request) Has been cancelled
118 lines
3.4 KiB
Rust
118 lines
3.4 KiB
Rust
//! Compose methods for App
|
|
//!
|
|
//! Handles reply, forward, and draft functionality
|
|
|
|
use crate::app::methods::messages::MessageMethods;
|
|
use crate::app::{App, ChatState};
|
|
use crate::tdlib::{MessageInfo, TdClientTrait};
|
|
|
|
/// Compose methods for reply/forward/draft
|
|
pub trait ComposeMethods<T: TdClientTrait> {
|
|
/// Start replying to the selected message
|
|
/// Returns true if reply mode started, false if no message selected
|
|
fn start_reply_to_selected(&mut self) -> bool;
|
|
|
|
/// Cancel reply mode
|
|
fn cancel_reply(&mut self);
|
|
|
|
/// Check if currently in reply mode
|
|
fn is_replying(&self) -> bool;
|
|
|
|
/// Get the message being replied to
|
|
fn get_replying_to_message(&self) -> Option<MessageInfo>;
|
|
|
|
/// Start forwarding the selected message
|
|
/// Returns true if forward mode started, false if no message selected
|
|
fn start_forward_selected(&mut self) -> bool;
|
|
|
|
/// Cancel forward mode
|
|
fn cancel_forward(&mut self);
|
|
|
|
/// Check if currently in forward mode (selecting target chat)
|
|
fn is_forwarding(&self) -> bool;
|
|
|
|
/// Get the message being forwarded
|
|
fn get_forwarding_message(&self) -> Option<MessageInfo>;
|
|
|
|
/// Get draft for the currently selected chat
|
|
fn get_current_draft(&self) -> Option<String>;
|
|
|
|
/// Load draft into message_input (called when opening chat)
|
|
fn load_draft(&mut self);
|
|
}
|
|
|
|
impl<T: TdClientTrait> ComposeMethods<T> for App<T> {
|
|
fn start_reply_to_selected(&mut self) -> bool {
|
|
if let Some(msg) = self.get_selected_message() {
|
|
self.chat_state = ChatState::Reply { message_id: msg.id() };
|
|
return true;
|
|
}
|
|
false
|
|
}
|
|
|
|
fn cancel_reply(&mut self) {
|
|
self.chat_state = ChatState::Normal;
|
|
}
|
|
|
|
fn is_replying(&self) -> bool {
|
|
self.chat_state.is_reply()
|
|
}
|
|
|
|
fn get_replying_to_message(&self) -> Option<MessageInfo> {
|
|
self.chat_state.selected_message_id().and_then(|id| {
|
|
self.td_client
|
|
.current_chat_messages()
|
|
.iter()
|
|
.find(|m| m.id() == id)
|
|
.cloned()
|
|
})
|
|
}
|
|
|
|
fn start_forward_selected(&mut self) -> bool {
|
|
if let Some(msg) = self.get_selected_message() {
|
|
self.chat_state = ChatState::Forward { message_id: msg.id() };
|
|
// Сбрасываем выбор чата на первый
|
|
self.chat_list_state.select(Some(0));
|
|
return true;
|
|
}
|
|
false
|
|
}
|
|
|
|
fn cancel_forward(&mut self) {
|
|
self.chat_state = ChatState::Normal;
|
|
}
|
|
|
|
fn is_forwarding(&self) -> bool {
|
|
self.chat_state.is_forward()
|
|
}
|
|
|
|
fn get_forwarding_message(&self) -> Option<MessageInfo> {
|
|
if !self.chat_state.is_forward() {
|
|
return None;
|
|
}
|
|
self.chat_state.selected_message_id().and_then(|id| {
|
|
self.td_client
|
|
.current_chat_messages()
|
|
.iter()
|
|
.find(|m| m.id() == id)
|
|
.cloned()
|
|
})
|
|
}
|
|
|
|
fn get_current_draft(&self) -> Option<String> {
|
|
self.selected_chat_id.and_then(|chat_id| {
|
|
self.chats
|
|
.iter()
|
|
.find(|c| c.id == chat_id)
|
|
.and_then(|c| c.draft_text.clone())
|
|
})
|
|
}
|
|
|
|
fn load_draft(&mut self) {
|
|
if let Some(draft) = self.get_current_draft() {
|
|
self.message_input = draft;
|
|
self.cursor_position = self.message_input.chars().count();
|
|
}
|
|
}
|
|
}
|