mirror of
https://gitea.mizah.xyz/mizah/dergchat
synced 2025-01-30 18:40:09 -05:00
Cargo fmt.
This commit is contained in:
parent
837dca3e15
commit
5064adbd21
@ -14,8 +14,8 @@
|
|||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use chrono::{DateTime, FixedOffset};
|
|
||||||
use crate::types::{DirectMessage, MessageDeliveryError, MucMessage, Nickname};
|
use crate::types::{DirectMessage, MessageDeliveryError, MucMessage, Nickname};
|
||||||
|
use chrono::{DateTime, FixedOffset};
|
||||||
|
|
||||||
/// An outgoing status for a message.
|
/// 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.
|
/// This is a trait, because MUC messages and direct messages are subtly different.
|
||||||
pub trait Message {
|
pub trait Message {
|
||||||
|
|
||||||
/// Whether the message is incoming or outgoing.
|
/// Whether the message is incoming or outgoing.
|
||||||
/// If outgoing, also contains the status of the message.
|
/// If outgoing, also contains the status of the message.
|
||||||
fn in_out(&self) -> &MessageInOut;
|
fn in_out(&self) -> &MessageInOut;
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::passwords::Password;
|
use crate::passwords::Password;
|
||||||
use jid::BareJid;
|
|
||||||
use std::fmt::Debug;
|
|
||||||
use chrono::{DateTime, FixedOffset};
|
use chrono::{DateTime, FixedOffset};
|
||||||
|
use jid::BareJid;
|
||||||
use message::{Message, MessageInOut};
|
use message::{Message, MessageInOut};
|
||||||
|
use std::fmt::Debug;
|
||||||
|
|
||||||
pub mod message;
|
pub mod message;
|
||||||
pub mod room;
|
pub mod room;
|
||||||
@ -86,4 +86,3 @@ pub struct LoginCredentials {
|
|||||||
pub struct MessageDeliveryError {
|
pub struct MessageDeliveryError {
|
||||||
pub error: String,
|
pub error: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,6 @@ impl<'a> TryInto<&'a mut DirectMessageRoom> for &'a mut Room {
|
|||||||
_ => Err(WrongRoomType),
|
_ => Err(WrongRoomType),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> TryInto<&'a mut MucRoom> for &'a mut Room {
|
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),
|
_ => Err(WrongRoomType),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
use crate::types::room::Room;
|
||||||
|
use crate::xmpp_interface::Messages;
|
||||||
use crate::{
|
use crate::{
|
||||||
configuration::store_login_details,
|
configuration::store_login_details,
|
||||||
configuration::{load_config, try_retrieve_credentials},
|
configuration::{load_config, try_retrieve_credentials},
|
||||||
@ -22,9 +24,9 @@ use crate::{
|
|||||||
login_screen::LoginAttempt,
|
login_screen::LoginAttempt,
|
||||||
login_screen::{LoginScreen, LoginStatus},
|
login_screen::{LoginScreen, LoginStatus},
|
||||||
no_room_open::NoRoomPlaceholder,
|
no_room_open::NoRoomPlaceholder,
|
||||||
|
room_list::RoomMeta,
|
||||||
room_view::RoomView,
|
room_view::RoomView,
|
||||||
sidebar::SideBar,
|
sidebar::SideBar,
|
||||||
room_list::RoomMeta,
|
|
||||||
},
|
},
|
||||||
xmpp_interface,
|
xmpp_interface,
|
||||||
xmpp_interface::NetworkCommand,
|
xmpp_interface::NetworkCommand,
|
||||||
@ -35,8 +37,6 @@ use futures_util::StreamExt;
|
|||||||
use jid::BareJid;
|
use jid::BareJid;
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use std::string::String;
|
use std::string::String;
|
||||||
use crate::xmpp_interface::Messages;
|
|
||||||
use crate::types::room::Room;
|
|
||||||
|
|
||||||
pub mod login_screen;
|
pub mod login_screen;
|
||||||
pub mod no_room_open;
|
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?
|
// 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?
|
// 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! {
|
render! {
|
||||||
|
|
||||||
|
@ -14,18 +14,18 @@
|
|||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use std::time::Instant;
|
|
||||||
use chrono::{DateTime, FixedOffset};
|
use chrono::{DateTime, FixedOffset};
|
||||||
use dioxus::core::{Element, Scope};
|
use dioxus::core::{Element, Scope};
|
||||||
use dioxus::core_macro::Props;
|
use dioxus::core_macro::Props;
|
||||||
use dioxus::html::button;
|
use dioxus::html::button;
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
use jid::BareJid;
|
use jid::BareJid;
|
||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
#[derive(Clone, Eq, PartialEq)]
|
#[derive(Clone, Eq, PartialEq)]
|
||||||
pub struct RoomMeta {
|
pub struct RoomMeta {
|
||||||
pub room: BareJid,
|
pub room: BareJid,
|
||||||
pub last_update_time: Option<DateTime<FixedOffset>>
|
pub last_update_time: Option<DateTime<FixedOffset>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Eq, PartialEq, Copy)]
|
#[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.
|
/// How "selecting" and "leaving" a room is handled is up to the context.
|
||||||
#[component]
|
#[component]
|
||||||
pub fn RoomList<'a>(cx: Scope<'a>,
|
pub fn RoomList<'a>(
|
||||||
rooms: Vec<RoomMeta>, // TODO: Should this be a reference of some kind?
|
cx: Scope<'a>,
|
||||||
on_room_picked: EventHandler<'a, BareJid>,
|
rooms: Vec<RoomMeta>, // TODO: Should this be a reference of some kind?
|
||||||
on_room_left: EventHandler<'a, BareJid>) -> Element<'a> {
|
on_room_picked: EventHandler<'a, BareJid>,
|
||||||
|
on_room_left: EventHandler<'a, BareJid>,
|
||||||
|
) -> Element<'a> {
|
||||||
let sort_method = use_state(cx, || SortMethod::Recency);
|
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() {
|
match *sort_method.current() {
|
||||||
SortMethod::Alphabetical => rooms.sort_by_key(|room| room.room.to_string()),
|
SortMethod::Alphabetical => rooms.sort_by_key(|room| room.room.to_string()),
|
||||||
SortMethod::Recency => rooms.sort_by_key(|room| room.last_update_time),
|
SortMethod::Recency => rooms.sort_by_key(|room| room.last_update_time),
|
||||||
|
@ -15,21 +15,21 @@
|
|||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::types::message::Message;
|
use crate::types::message::Message;
|
||||||
|
use crate::types::Room;
|
||||||
use crate::widgets::send_message::SendMessage;
|
use crate::widgets::send_message::SendMessage;
|
||||||
use dioxus::core::{Element, Scope};
|
use dioxus::core::{Element, Scope};
|
||||||
use dioxus::core_macro::Props;
|
use dioxus::core_macro::Props;
|
||||||
use dioxus::hooks::use_state;
|
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
use jid::BareJid;
|
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.
|
/// A widget that shows a room, including a list of messages and a widget to send new messages.
|
||||||
#[component]
|
#[component]
|
||||||
pub fn RoomView<'a, R:Room>(cx: Scope<'a>,
|
pub fn RoomView<'a, R: Room>(
|
||||||
room: BareJid,
|
cx: Scope<'a>,
|
||||||
messages: R,
|
room: BareJid,
|
||||||
on_message_sent: EventHandler<'a, String>) -> Element<'a> {
|
messages: R,
|
||||||
|
on_message_sent: EventHandler<'a, String>,
|
||||||
|
) -> Element<'a> {
|
||||||
render! {
|
render! {
|
||||||
div {
|
div {
|
||||||
padding: "5mm",
|
padding: "5mm",
|
||||||
|
@ -24,14 +24,15 @@ use jid::BareJid;
|
|||||||
|
|
||||||
/// A widget that combines the RoomList, RoomJoinWidget, and current user info into a sidebar.
|
/// A widget that combines the RoomList, RoomJoinWidget, and current user info into a sidebar.
|
||||||
#[component]
|
#[component]
|
||||||
pub fn SideBar<'a>(cx: Scope<'a, SideBarProps>,
|
pub fn SideBar<'a>(
|
||||||
current_user: BareJid,
|
cx: Scope<'a, SideBarProps>,
|
||||||
rooms: Vec<RoomMeta>,
|
current_user: BareJid,
|
||||||
on_room_picked: EventHandler<'a, BareJid>,
|
rooms: Vec<RoomMeta>,
|
||||||
on_room_left: EventHandler<'a, BareJid>,
|
on_room_picked: EventHandler<'a, BareJid>,
|
||||||
on_join_room: EventHandler<'a, BareJid>,
|
on_room_left: EventHandler<'a, BareJid>,
|
||||||
on_logout: EventHandler<'a, ()>) -> Element<'a> {
|
on_join_room: EventHandler<'a, BareJid>,
|
||||||
|
on_logout: EventHandler<'a, ()>,
|
||||||
|
) -> Element<'a> {
|
||||||
render! {
|
render! {
|
||||||
div {
|
div {
|
||||||
padding: "5mm",
|
padding: "5mm",
|
||||||
|
@ -14,19 +14,21 @@
|
|||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
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 dioxus::hooks::{UnboundedReceiver, UseRef, UseState};
|
||||||
use futures_util::stream::StreamExt;
|
use futures_util::stream::StreamExt;
|
||||||
use jid::BareJid;
|
use jid::BareJid;
|
||||||
use log::{debug, error, info, warn};
|
use log::{debug, error, info, warn};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use crate::widgets::login_screen::LoginStatus;
|
|
||||||
use tokio::select;
|
use tokio::select;
|
||||||
use xmpp::parsers::message::MessageType;
|
use xmpp::parsers::message::MessageType;
|
||||||
use xmpp::{Agent, ClientBuilder, ClientType};
|
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.
|
/// An enum of commands that can be sent to the XMPP interface.
|
||||||
///
|
///
|
||||||
@ -34,16 +36,25 @@ use crate::types::message::MessageInOut;
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum NetworkCommand {
|
pub enum NetworkCommand {
|
||||||
/// Start a new login attempt, resulting in either a successful login or an error.
|
/// Start a new login attempt, resulting in either a successful login or an error.
|
||||||
TryLogin { credentials: LoginCredentials },
|
TryLogin {
|
||||||
|
credentials: LoginCredentials,
|
||||||
|
},
|
||||||
|
|
||||||
/// Join a room.
|
/// Join a room.
|
||||||
JoinRoom { room: BareJid },
|
JoinRoom {
|
||||||
|
room: BareJid,
|
||||||
|
},
|
||||||
|
|
||||||
/// Leave a room.
|
/// Leave a room.
|
||||||
LeaveRoom { room: BareJid },
|
LeaveRoom {
|
||||||
|
room: BareJid,
|
||||||
|
},
|
||||||
|
|
||||||
/// Send a message to a recipient.
|
/// Send a message to a recipient.
|
||||||
SendMessage { recipient: BareJid, message: String },
|
SendMessage {
|
||||||
|
recipient: BareJid,
|
||||||
|
message: String,
|
||||||
|
},
|
||||||
|
|
||||||
Logout,
|
Logout,
|
||||||
}
|
}
|
||||||
@ -54,7 +65,6 @@ pub struct Messages {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Messages {
|
impl Messages {
|
||||||
|
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
messages: HashMap::new(),
|
messages: HashMap::new(),
|
||||||
@ -65,18 +75,22 @@ impl Messages {
|
|||||||
self.messages.get(room)
|
self.messages.get(room)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_or_create_mut_direct(&mut self, room: &BareJid) -> Result<&mut DirectMessageRoom, WrongRoomType> {
|
pub fn get_or_create_mut_direct(
|
||||||
self.messages.entry(room.clone()).or_insert(Room::Direct(DirectMessageRoom {
|
&mut self,
|
||||||
messages: vec![],
|
room: &BareJid,
|
||||||
})).try_into()
|
) -> 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> {
|
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 {
|
self.messages
|
||||||
messages: vec![],
|
.entry(room.clone())
|
||||||
})).try_into()
|
.or_insert(Room::Muc(MucRoom { messages: vec![] }))
|
||||||
|
.try_into()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_event(
|
async fn handle_event(
|
||||||
@ -92,9 +106,9 @@ async fn handle_event(
|
|||||||
xmpp::Event::RoomJoined(room_jid) => {
|
xmpp::Event::RoomJoined(room_jid) => {
|
||||||
debug!("Joined room: {}", &room_jid);
|
debug!("Joined room: {}", &room_jid);
|
||||||
messages.with_mut(move |m| {
|
messages.with_mut(move |m| {
|
||||||
m.messages.entry(room_jid.clone()).or_insert(Room::Muc(MucRoom {
|
m.messages
|
||||||
messages: vec![],
|
.entry(room_jid.clone())
|
||||||
}));
|
.or_insert(Room::Muc(MucRoom { messages: vec![] }));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
xmpp::Event::RoomLeft(room_jid) => {
|
xmpp::Event::RoomLeft(room_jid) => {
|
||||||
@ -106,9 +120,12 @@ async fn handle_event(
|
|||||||
xmpp::Event::ChatMessage(_id, sender, body, timestamp) => {
|
xmpp::Event::ChatMessage(_id, sender, body, timestamp) => {
|
||||||
debug!("Message from {}: {}", &sender, &body.0);
|
debug!("Message from {}: {}", &sender, &body.0);
|
||||||
messages.with_mut(move |m| {
|
messages.with_mut(move |m| {
|
||||||
let dms : &mut DirectMessageRoom = m.messages.entry(sender.clone()).or_insert(Room::Direct(DirectMessageRoom {
|
let dms: &mut DirectMessageRoom = m
|
||||||
messages: vec![],
|
.messages
|
||||||
})).try_into().expect("Received direct message with a JID from a MUC");
|
.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 {
|
dms.messages.push(DirectMessage {
|
||||||
in_out: MessageInOut::Incoming,
|
in_out: MessageInOut::Incoming,
|
||||||
@ -123,8 +140,8 @@ async fn handle_event(
|
|||||||
&room_jid, &sender_nick, &body.0
|
&room_jid, &sender_nick, &body.0
|
||||||
);
|
);
|
||||||
messages.with_mut(move |m| {
|
messages.with_mut(move |m| {
|
||||||
|
let muc: &mut MucRoom = m
|
||||||
let muc : &mut MucRoom = m.get_or_create_mut_muc(&room_jid)
|
.get_or_create_mut_muc(&room_jid)
|
||||||
.expect("Received direct message with a JID from a MUC");
|
.expect("Received direct message with a JID from a MUC");
|
||||||
|
|
||||||
muc.messages.push(MucMessage {
|
muc.messages.push(MucMessage {
|
||||||
@ -134,7 +151,6 @@ async fn handle_event(
|
|||||||
timestamp,
|
timestamp,
|
||||||
is_private: false,
|
is_private: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
xmpp::Event::RoomPrivateMessage(_id, room_jid, sender_nick, body, timestamp) => {
|
xmpp::Event::RoomPrivateMessage(_id, room_jid, sender_nick, body, timestamp) => {
|
||||||
@ -143,8 +159,8 @@ async fn handle_event(
|
|||||||
&room_jid, &sender_nick, &body.0
|
&room_jid, &sender_nick, &body.0
|
||||||
);
|
);
|
||||||
messages.with_mut(move |m| {
|
messages.with_mut(move |m| {
|
||||||
|
let muc: &mut MucRoom = m
|
||||||
let muc : &mut MucRoom = m.get_or_create_mut_muc(&room_jid)
|
.get_or_create_mut_muc(&room_jid)
|
||||||
.expect("Received direct message with a JID from a MUC");
|
.expect("Received direct message with a JID from a MUC");
|
||||||
|
|
||||||
muc.messages.push(MucMessage {
|
muc.messages.push(MucMessage {
|
||||||
@ -154,7 +170,6 @@ async fn handle_event(
|
|||||||
timestamp,
|
timestamp,
|
||||||
is_private: true,
|
is_private: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
Loading…
Reference in New Issue
Block a user