daydream

A small matrix web client written in rust
git clone git://archive.git.mtrnord.blog/daydream-mx/daydream.git
Log | Files | Refs | README | LICENSE

commit ad542d87df8dc1cb0d4058872c2e51b778b5a3ab
parent b557df96506d072dfdf1a511e70ac2f20db5e26d
Author: Marcel <mtrnord1@gmail.com>
Date:   Fri,  3 Jul 2020 20:13:59 +0200

Use RoomId on change Room instead of a full Room clone

Took 13 minutes

Diffstat:
Msrc/app/components/events/image.rs | 7++++---
Msrc/app/components/events/notice.rs | 7++++---
Msrc/app/components/events/text.rs | 7++++---
Msrc/app/components/events/video.rs | 7++++---
Msrc/app/components/room_list/item.rs | 6+++---
Msrc/app/components/room_list/mod.rs | 16+++++++++-------
Msrc/app/matrix/sync.rs | 2+-
7 files changed, 29 insertions(+), 23 deletions(-)

diff --git a/src/app/components/events/image.rs b/src/app/components/events/image.rs @@ -34,14 +34,15 @@ impl Component for Image { false } - fn change(&mut self, props: Self::Properties) -> bool { + fn change(&mut self, _props: Self::Properties) -> bool { // TODO fix the PartialEq hack - if format!("{:?}", self.props) != format!("{:?}", props) { + /*if format!("{:?}", self.props) != format!("{:?}", props) { self.props = props; true } else { false - } + }*/ + true } //noinspection RsTypeCheck diff --git a/src/app/components/events/notice.rs b/src/app/components/events/notice.rs @@ -37,14 +37,15 @@ impl Component for Notice { false } - fn change(&mut self, props: Self::Properties) -> bool { + fn change(&mut self, _props: Self::Properties) -> bool { // TODO fix the PartialEq hack - if format!("{:?}", self.props) != format!("{:?}", props) { + /*if format!("{:?}", self.props) != format!("{:?}", props) { self.props = props; true } else { false - } + }*/ + true } //noinspection RsTypeCheck diff --git a/src/app/components/events/text.rs b/src/app/components/events/text.rs @@ -36,14 +36,15 @@ impl Component for Text { false } - fn change(&mut self, props: Self::Properties) -> bool { + fn change(&mut self, _props: Self::Properties) -> bool { // TODO fix the PartialEq hack - if format!("{:?}", self.props) != format!("{:?}", props) { + /*if format!("{:?}", self.props) != format!("{:?}", props) { self.props = props; true } else { false - } + }*/ + true } //noinspection RsTypeCheck diff --git a/src/app/components/events/video.rs b/src/app/components/events/video.rs @@ -34,14 +34,15 @@ impl Component for Video { false } - fn change(&mut self, props: Self::Properties) -> bool { + fn change(&mut self, _props: Self::Properties) -> bool { // TODO fix the PartialEq hack - if format!("{:?}", self.props) != format!("{:?}", props) { + /*if format!("{:?}", self.props) != format!("{:?}", props) { self.props = props; true } else { false - } + }*/ + true } //noinspection RsTypeCheck diff --git a/src/app/components/room_list/item.rs b/src/app/components/room_list/item.rs @@ -1,4 +1,4 @@ -use matrix_sdk::{events::room::message::MessageEventContent, Room}; +use matrix_sdk::{events::room::message::MessageEventContent, Room, identifiers::RoomId}; use yew::prelude::*; use yewtil::NeqAssign; @@ -17,7 +17,7 @@ pub struct Props { pub room: Option<Room>, #[prop_or_default] - pub change_room_callback: Callback<Room>, + pub change_room_callback: Callback<RoomId>, } impl Component for RoomItem { @@ -31,7 +31,7 @@ impl Component for RoomItem { fn update(&mut self, msg: Self::Message) -> bool { match msg { Msg::ChangeRoom(room) => { - self.props.change_room_callback.emit(room); + self.props.change_room_callback.emit(room.room_id); } } false diff --git a/src/app/components/room_list/mod.rs b/src/app/components/room_list/mod.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use std::include_str; use log::*; -use matrix_sdk::{identifiers::RoomId, js_int::UInt, Room}; +use matrix_sdk::{identifiers::RoomId, Room}; use serde::{Deserialize, Serialize}; use wasm_bindgen::JsCast; use web_sys::HtmlElement; @@ -29,7 +29,7 @@ pub struct RoomList { #[allow(clippy::large_enum_variant)] pub enum Msg { NewMessage(Response), - ChangeRoom(Room), + ChangeRoom(RoomId), SetFilter(String), ToggleTheme, } @@ -37,7 +37,7 @@ pub enum Msg { #[derive(Serialize, Deserialize, Default)] pub struct State { rooms: HashMap<RoomId, Room>, - current_room: Option<Room>, + current_room: Option<RoomId>, loading: bool, search_query: Option<String>, dark_theme: bool, @@ -93,14 +93,16 @@ impl Component for RoomList { } _ => false, }, - Msg::ChangeRoom(room) => { + Msg::ChangeRoom(room_id) => { if self.state.current_room.is_some() - && self.state.current_room.as_ref().unwrap() == &room + && self.state.current_room.as_ref().unwrap() == &room_id { return false; } - self.props.change_room_callback.emit(room.clone()); - self.state.current_room = Some(room); + + let room = self.state.rooms[&room_id].clone(); + self.props.change_room_callback.emit(room); + self.state.current_room = Some(room_id); true } Msg::SetFilter(query) => { diff --git a/src/app/matrix/sync.rs b/src/app/matrix/sync.rs @@ -169,7 +169,7 @@ impl Sync { let serialized_event = EventJson::from(event.clone()); let resp = Response::Sync((room_id.clone(), serialized_event)); - //self.callback.emit(resp); + self.callback.emit(resp); } } }