diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 87 |
1 files changed, 49 insertions, 38 deletions
diff --git a/src/main.rs b/src/main.rs index 0b8b3b8..106df79 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,10 +23,11 @@ use iced::widget::button::Status; use iced::widget::text::{Fragment, IntoFragment, Wrapping}; use iced::widget::{ button, center, checkbox, column, container, horizontal_space, image, mouse_area, opaque, row, - scrollable, stack, text, text_input, toggler, Column, Text, Toggler, + scrollable, stack, text, text_input, toggler, Column, Svg, Text, Toggler, }; use iced::Length::{self, Fill, Shrink}; use iced::{color, stream, Color, Element, Subscription, Task, Theme}; +use icons::Icon; use indexmap::{indexmap, IndexMap}; use jid::JID; use keyring::Entry; @@ -37,9 +38,10 @@ use thiserror::Error; use tokio::sync::mpsc::Sender; use tokio::sync::{mpsc, oneshot}; use tokio_stream::wrappers::ReceiverStream; -use tracing::{error, info}; +use tracing::{debug, error, info}; use uuid::Uuid; +mod icons; mod login_modal; mod message_view; @@ -488,6 +490,7 @@ async fn main() -> iced::Result { Task::stream(stream), ]) } else { + debug!("no auto connect"); Task::batch([ Task::perform( async move { luz_handle1.get_roster_with_users().await }, @@ -524,7 +527,7 @@ async fn main() -> iced::Result { }; iced::application("Macaw", Macaw::update, Macaw::view) .subscription(subscription) - .theme(Macaw::theme) + // .theme(Macaw::theme) .run_with(|| { ( Macaw::new( @@ -698,7 +701,8 @@ impl Macaw { } UpdateMessage::Presence { from, presence } => { // TODO: presence handling - self.presences.insert(from, presence); + info!("got presence from {:?} {:?}", from, presence); + self.presences.insert(from.as_bare(), presence); Task::none() } UpdateMessage::Message { to, message, from } => { @@ -886,7 +890,7 @@ impl Macaw { client.connection_state = ConnectionState::Connecting; let client = client.client.clone(); Task::future(async move { - client.connect().await; + client.connect().await.unwrap(); }) .discard() } @@ -896,7 +900,7 @@ impl Macaw { Account::LoggedIn(client) => { let client = client.client.clone(); Task::future(async move { - client.disconnect(Offline::default()).await; + client.disconnect(Offline::default()).await.unwrap(); }) .discard() } @@ -1105,8 +1109,13 @@ impl Macaw { open = true; } } - let chat_list_item = - chat_list_item(&self.roster, client.files_root(), chat, open); + let chat_list_item = chat_list_item( + &self.presences, + &self.roster, + client.files_root(), + chat, + open, + ); chats_list = chats_list.push(chat_list_item); } } @@ -1288,6 +1297,7 @@ where } fn chat_list_item<'a>( + presences: &HashMap<JID, Presence>, roster: &HashMap<JID, MacawContact>, file_root: &'a Path, chat_list_item: &'a ChatListItem, @@ -1339,36 +1349,37 @@ fn chat_list_item<'a>( latest_message_text = None; } - let avatar_image = if let Some(avatar) = avatar { + let mut avatar_stack = stack([]); + if let Some(avatar) = avatar { let mut path = file_root.join(avatar); path.set_extension("jpg"); info!("got avatar: {:?}", path); - Some(image(path).width(48).height(48)) - } else { - None - }; - let content: Element<Message> = if let Some(avatar_image) = avatar_image { - if let Some((message, time)) = latest_message_text { - row![ - avatar_image, - column![ - text(name), - row![ - container(text(message).wrapping(Wrapping::None)) - .clip(true) - .width(Fill), - text(time) - ] - .spacing(8) - .width(Fill) - ] - ] - .into() - } else { - row![avatar_image, text(name)].into() + avatar_stack = avatar_stack.push(image(path).width(48).height(48)); + } + let mut status_icon: Option<Icon> = None; + if let Some(presence) = presences.get(&chat_list_item.user.jid) { + debug!("found a presence"); + match &presence.presence { + PresenceType::Online(online) => match online.show { + Some(s) => match s { + filamento::presence::Show::Away => status_icon = Some(Icon::Away16Color), + filamento::presence::Show::Chat => status_icon = Some(Icon::Bubble16Color), + filamento::presence::Show::DoNotDisturb => status_icon = Some(Icon::Dnd16Color), + filamento::presence::Show::ExtendedAway => { + status_icon = Some(Icon::Away16Color) + } + }, + None => status_icon = Some(Icon::Bubble16Color), + }, + PresenceType::Offline(offline) => {} } - } else { - if let Some((message, time)) = latest_message_text { + } + if let Some(status_icon) = status_icon { + avatar_stack = avatar_stack.push(Into::<Svg>::into(status_icon)); + } + let content: Element<Message> = if let Some((message, time)) = latest_message_text { + row![ + avatar_stack, column![ text(name), row![ @@ -1380,10 +1391,10 @@ fn chat_list_item<'a>( .spacing(8) .width(Fill) ] - .into() - } else { - text(name).into() - } + ] + .into() + } else { + row![avatar_stack, text(name)].into() }; let mut button = button(content).on_press(Message::ToggleChat(chat_list_item.correspondent().clone())); |