diff --git a/src/types/message.rs b/src/types/message.rs
index b809d25..c814a98 100644
--- a/src/types/message.rs
+++ b/src/types/message.rs
@@ -14,8 +14,8 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
-use chrono::{DateTime, FixedOffset};
use crate::types::{DirectMessage, MessageDeliveryError, MucMessage, Nickname};
+use chrono::{DateTime, FixedOffset};
/// An outgoing status for a message.
///
@@ -42,7 +42,6 @@ pub enum MessageInOut {
///
/// This is a trait, because MUC messages and direct messages are subtly different.
pub trait Message {
-
/// Whether the message is incoming or outgoing.
/// If outgoing, also contains the status of the message.
fn in_out(&self) -> &MessageInOut;
diff --git a/src/types/mod.rs b/src/types/mod.rs
index a571671..3e38fed 100644
--- a/src/types/mod.rs
+++ b/src/types/mod.rs
@@ -15,10 +15,10 @@
// along with this program. If not, see .
use crate::passwords::Password;
-use jid::BareJid;
-use std::fmt::Debug;
use chrono::{DateTime, FixedOffset};
+use jid::BareJid;
use message::{Message, MessageInOut};
+use std::fmt::Debug;
pub mod message;
pub mod room;
@@ -86,4 +86,3 @@ pub struct LoginCredentials {
pub struct MessageDeliveryError {
pub error: String,
}
-
diff --git a/src/types/room.rs b/src/types/room.rs
index 5bca4b3..7c7d14f 100644
--- a/src/types/room.rs
+++ b/src/types/room.rs
@@ -50,7 +50,6 @@ impl<'a> TryInto<&'a mut DirectMessageRoom> for &'a mut Room {
_ => Err(WrongRoomType),
}
}
-
}
impl<'a> TryInto<&'a mut MucRoom> for &'a mut Room {
@@ -62,5 +61,4 @@ impl<'a> TryInto<&'a mut MucRoom> for &'a mut Room {
_ => Err(WrongRoomType),
}
}
-
}
diff --git a/src/widgets/mod.rs b/src/widgets/mod.rs
index 8e00a85..76a7d57 100644
--- a/src/widgets/mod.rs
+++ b/src/widgets/mod.rs
@@ -14,6 +14,8 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
+use crate::types::room::Room;
+use crate::xmpp_interface::Messages;
use crate::{
configuration::store_login_details,
configuration::{load_config, try_retrieve_credentials},
@@ -22,9 +24,9 @@ use crate::{
login_screen::LoginAttempt,
login_screen::{LoginScreen, LoginStatus},
no_room_open::NoRoomPlaceholder,
+ room_list::RoomMeta,
room_view::RoomView,
sidebar::SideBar,
- room_list::RoomMeta,
},
xmpp_interface,
xmpp_interface::NetworkCommand,
@@ -35,8 +37,6 @@ use futures_util::StreamExt;
use jid::BareJid;
use log::{error, info};
use std::string::String;
-use crate::xmpp_interface::Messages;
-use crate::types::room::Room;
pub mod login_screen;
pub mod no_room_open;
@@ -76,7 +76,10 @@ pub fn App(cx: Scope) -> Element {
// Can I not clone this? Am I reconstructing the entire VDOM every time? What's happening?
// TODO: The borrowing situation here is kinda fucked; how do I fix this?
- let current_room_messages = current_room.get().clone().and_then(|x| messages.read().messages.get(&x).map(|x| x.clone()));
+ let current_room_messages = current_room
+ .get()
+ .clone()
+ .and_then(|x| messages.read().messages.get(&x).map(|x| x.clone()));
render! {
diff --git a/src/widgets/room_list.rs b/src/widgets/room_list.rs
index 4aef489..19e668f 100644
--- a/src/widgets/room_list.rs
+++ b/src/widgets/room_list.rs
@@ -14,18 +14,18 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
-use std::time::Instant;
use chrono::{DateTime, FixedOffset};
use dioxus::core::{Element, Scope};
use dioxus::core_macro::Props;
use dioxus::html::button;
use dioxus::prelude::*;
use jid::BareJid;
+use std::time::Instant;
#[derive(Clone, Eq, PartialEq)]
pub struct RoomMeta {
pub room: BareJid,
- pub last_update_time: Option>
+ pub last_update_time: Option>,
}
#[derive(Clone, Eq, PartialEq, Copy)]
@@ -41,16 +41,15 @@ pub enum SortMethod {
///
/// How "selecting" and "leaving" a room is handled is up to the context.
#[component]
-pub fn RoomList<'a>(cx: Scope<'a>,
- rooms: Vec, // TODO: Should this be a reference of some kind?
- on_room_picked: EventHandler<'a, BareJid>,
- on_room_left: EventHandler<'a, BareJid>) -> Element<'a> {
-
-
+pub fn RoomList<'a>(
+ cx: Scope<'a>,
+ rooms: Vec, // TODO: Should this be a reference of some kind?
+ on_room_picked: EventHandler<'a, BareJid>,
+ on_room_left: EventHandler<'a, BareJid>,
+) -> Element<'a> {
let sort_method = use_state(cx, || SortMethod::Recency);
- let sorted_rooms = use_memo(cx, (rooms,sort_method), |(mut rooms, sort_method)| {
-
+ let sorted_rooms = use_memo(cx, (rooms, sort_method), |(mut rooms, sort_method)| {
match *sort_method.current() {
SortMethod::Alphabetical => rooms.sort_by_key(|room| room.room.to_string()),
SortMethod::Recency => rooms.sort_by_key(|room| room.last_update_time),
diff --git a/src/widgets/room_view.rs b/src/widgets/room_view.rs
index db8a8f8..9de3937 100644
--- a/src/widgets/room_view.rs
+++ b/src/widgets/room_view.rs
@@ -15,21 +15,21 @@
// along with this program. If not, see .
use crate::types::message::Message;
+use crate::types::Room;
use crate::widgets::send_message::SendMessage;
use dioxus::core::{Element, Scope};
use dioxus::core_macro::Props;
-use dioxus::hooks::use_state;
use dioxus::prelude::*;
use jid::BareJid;
-use crate::types::Room;
/// A widget that shows a room, including a list of messages and a widget to send new messages.
#[component]
-pub fn RoomView<'a, R:Room>(cx: Scope<'a>,
- room: BareJid,
- messages: R,
- on_message_sent: EventHandler<'a, String>) -> Element<'a> {
-
+pub fn RoomView<'a, R: Room>(
+ cx: Scope<'a>,
+ room: BareJid,
+ messages: R,
+ on_message_sent: EventHandler<'a, String>,
+) -> Element<'a> {
render! {
div {
padding: "5mm",
diff --git a/src/widgets/sidebar.rs b/src/widgets/sidebar.rs
index bee431d..c51f0a9 100644
--- a/src/widgets/sidebar.rs
+++ b/src/widgets/sidebar.rs
@@ -24,14 +24,15 @@ use jid::BareJid;
/// A widget that combines the RoomList, RoomJoinWidget, and current user info into a sidebar.
#[component]
-pub fn SideBar<'a>(cx: Scope<'a, SideBarProps>,
- current_user: BareJid,
- rooms: Vec,
- on_room_picked: EventHandler<'a, BareJid>,
- on_room_left: EventHandler<'a, BareJid>,
- on_join_room: EventHandler<'a, BareJid>,
- on_logout: EventHandler<'a, ()>) -> Element<'a> {
-
+pub fn SideBar<'a>(
+ cx: Scope<'a, SideBarProps>,
+ current_user: BareJid,
+ rooms: Vec,
+ on_room_picked: EventHandler<'a, BareJid>,
+ on_room_left: EventHandler<'a, BareJid>,
+ on_join_room: EventHandler<'a, BareJid>,
+ on_logout: EventHandler<'a, ()>,
+) -> Element<'a> {
render! {
div {
padding: "5mm",
diff --git a/src/xmpp_interface.rs b/src/xmpp_interface.rs
index cdae3b6..112c08f 100644
--- a/src/xmpp_interface.rs
+++ b/src/xmpp_interface.rs
@@ -14,19 +14,21 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
-use crate::types::{DirectMessage, DirectMessageRoom, LoginCredentials, MucMessage, MucRoom, Nickname};
+use crate::types::message::MessageInOut;
+use crate::types::room::{Room, WrongRoomType};
+use crate::types::{
+ DirectMessage, DirectMessageRoom, LoginCredentials, MucMessage, MucRoom, Nickname,
+};
+use crate::widgets::login_screen::LoginStatus;
use dioxus::hooks::{UnboundedReceiver, UseRef, UseState};
use futures_util::stream::StreamExt;
use jid::BareJid;
use log::{debug, error, info, warn};
use std::collections::HashMap;
use std::future::Future;
-use crate::widgets::login_screen::LoginStatus;
use tokio::select;
use xmpp::parsers::message::MessageType;
use xmpp::{Agent, ClientBuilder, ClientType};
-use crate::types::room::{Room, WrongRoomType};
-use crate::types::message::MessageInOut;
/// An enum of commands that can be sent to the XMPP interface.
///
@@ -34,16 +36,25 @@ use crate::types::message::MessageInOut;
#[derive(Debug)]
pub enum NetworkCommand {
/// Start a new login attempt, resulting in either a successful login or an error.
- TryLogin { credentials: LoginCredentials },
+ TryLogin {
+ credentials: LoginCredentials,
+ },
/// Join a room.
- JoinRoom { room: BareJid },
+ JoinRoom {
+ room: BareJid,
+ },
/// Leave a room.
- LeaveRoom { room: BareJid },
+ LeaveRoom {
+ room: BareJid,
+ },
/// Send a message to a recipient.
- SendMessage { recipient: BareJid, message: String },
+ SendMessage {
+ recipient: BareJid,
+ message: String,
+ },
Logout,
}
@@ -54,7 +65,6 @@ pub struct Messages {
}
impl Messages {
-
pub fn new() -> Self {
Self {
messages: HashMap::new(),
@@ -65,18 +75,22 @@ impl Messages {
self.messages.get(room)
}
- pub fn get_or_create_mut_direct(&mut self, room: &BareJid) -> Result<&mut DirectMessageRoom, WrongRoomType> {
- self.messages.entry(room.clone()).or_insert(Room::Direct(DirectMessageRoom {
- messages: vec![],
- })).try_into()
+ pub fn get_or_create_mut_direct(
+ &mut self,
+ room: &BareJid,
+ ) -> Result<&mut DirectMessageRoom, WrongRoomType> {
+ self.messages
+ .entry(room.clone())
+ .or_insert(Room::Direct(DirectMessageRoom { messages: vec![] }))
+ .try_into()
}
pub fn get_or_create_mut_muc(&mut self, room: &BareJid) -> Result<&mut MucRoom, WrongRoomType> {
- self.messages.entry(room.clone()).or_insert(Room::Muc(MucRoom {
- messages: vec![],
- })).try_into()
+ self.messages
+ .entry(room.clone())
+ .or_insert(Room::Muc(MucRoom { messages: vec![] }))
+ .try_into()
}
-
}
async fn handle_event(
@@ -92,9 +106,9 @@ async fn handle_event(
xmpp::Event::RoomJoined(room_jid) => {
debug!("Joined room: {}", &room_jid);
messages.with_mut(move |m| {
- m.messages.entry(room_jid.clone()).or_insert(Room::Muc(MucRoom {
- messages: vec![],
- }));
+ m.messages
+ .entry(room_jid.clone())
+ .or_insert(Room::Muc(MucRoom { messages: vec![] }));
});
}
xmpp::Event::RoomLeft(room_jid) => {
@@ -106,9 +120,12 @@ async fn handle_event(
xmpp::Event::ChatMessage(_id, sender, body, timestamp) => {
debug!("Message from {}: {}", &sender, &body.0);
messages.with_mut(move |m| {
- let dms : &mut DirectMessageRoom = m.messages.entry(sender.clone()).or_insert(Room::Direct(DirectMessageRoom {
- messages: vec![],
- })).try_into().expect("Received direct message with a JID from a MUC");
+ let dms: &mut DirectMessageRoom = m
+ .messages
+ .entry(sender.clone())
+ .or_insert(Room::Direct(DirectMessageRoom { messages: vec![] }))
+ .try_into()
+ .expect("Received direct message with a JID from a MUC");
dms.messages.push(DirectMessage {
in_out: MessageInOut::Incoming,
@@ -123,8 +140,8 @@ async fn handle_event(
&room_jid, &sender_nick, &body.0
);
messages.with_mut(move |m| {
-
- let muc : &mut MucRoom = m.get_or_create_mut_muc(&room_jid)
+ let muc: &mut MucRoom = m
+ .get_or_create_mut_muc(&room_jid)
.expect("Received direct message with a JID from a MUC");
muc.messages.push(MucMessage {
@@ -134,7 +151,6 @@ async fn handle_event(
timestamp,
is_private: false,
});
-
});
}
xmpp::Event::RoomPrivateMessage(_id, room_jid, sender_nick, body, timestamp) => {
@@ -143,8 +159,8 @@ async fn handle_event(
&room_jid, &sender_nick, &body.0
);
messages.with_mut(move |m| {
-
- let muc : &mut MucRoom = m.get_or_create_mut_muc(&room_jid)
+ let muc: &mut MucRoom = m
+ .get_or_create_mut_muc(&room_jid)
.expect("Received direct message with a JID from a MUC");
muc.messages.push(MucMessage {
@@ -154,7 +170,6 @@ async fn handle_event(
timestamp,
is_private: true,
});
-
});
}
_ => {