Files
telegram-tui/src/ui/components/chat_list_item.rs
Mikhail Kilin 644e36597d fixes
2026-01-31 03:48:50 +03:00

79 lines
2.2 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
use crate::tdlib::{ChatInfo, UserOnlineStatus};
use ratatui::{
style::{Color, Style},
widgets::ListItem,
};
/// Рендерит элемент списка чатов
///
/// # Параметры
/// - `chat`: Информация о чате
/// - `is_selected`: Выбран ли этот чат
/// - `user_status`: Онлайн-статус пользователя (если доступен)
///
/// # Возвращает
/// ListItem с форматированным отображением чата
pub fn render_chat_list_item(
chat: &ChatInfo,
is_selected: bool,
user_status: Option<&UserOnlineStatus>,
) -> ListItem<'static> {
let pin_icon = if chat.is_pinned { "📌 " } else { "" };
let mute_icon = if chat.is_muted { "🔇 " } else { "" };
// Онлайн-статус (зелёная точка для онлайн)
let status_icon = match user_status {
Some(UserOnlineStatus::Online) => "",
_ => " ",
};
let prefix = if is_selected { "" } else { " " };
let username_text = chat
.username
.as_ref()
.map(|u| format!(" {}", u))
.unwrap_or_default();
// Индикатор упоминаний @
let mention_badge = if chat.unread_mention_count > 0 {
" @".to_string()
} else {
String::new()
};
// Индикатор черновика ✎
let draft_badge = if chat.draft_text.is_some() {
"".to_string()
} else {
String::new()
};
let unread_badge = if chat.unread_count > 0 {
format!(" ({})", chat.unread_count)
} else {
String::new()
};
let content = format!(
"{}{}{}{}{}{}{}{}{}",
prefix,
status_icon,
pin_icon,
mute_icon,
chat.title,
username_text,
mention_badge,
draft_badge,
unread_badge
);
// Цвет: онлайн — зелёные, остальные — белые
let style = match user_status {
Some(UserOnlineStatus::Online) => Style::default().fg(Color::Green),
_ => Style::default().fg(Color::White),
};
ListItem::new(content).style(style)
}