commit a51af1b923c57868391034d1fdae5034b8224599
parent 218f9943a95e7fd742ecdb75eb8d8f4efb7eeea0
Author: Jonas Platte <jplatte+git@posteo.de>
Date: Fri, 3 Jul 2020 20:52:35 +0200
Use `Rc` to clone `Room`s even less
Diffstat:
8 files changed, 30 insertions(+), 18 deletions(-)
diff --git a/src/app/components/event_list.rs b/src/app/components/event_list.rs
@@ -1,10 +1,11 @@
+use std::{collections::HashMap, rc::Rc};
+
use log::*;
use matrix_sdk::{
events::room::message::{MessageEvent, MessageEventContent},
identifiers::RoomId,
Room,
};
-use std::collections::HashMap;
use yew::prelude::*;
use crate::app::components::{
@@ -36,7 +37,7 @@ pub enum Msg {
#[derive(Clone, PartialEq, Properties, Debug)]
pub struct Props {
#[prop_or_default]
- pub current_room: Option<Room>,
+ pub current_room: Option<Rc<Room>>,
}
impl Component for EventList {
diff --git a/src/app/components/events/image.rs b/src/app/components/events/image.rs
@@ -1,3 +1,5 @@
+use std::rc::Rc;
+
use crate::app::components::events::{get_sender_displayname, is_new_user};
use matrix_sdk::{
events::room::message::{ImageMessageEventContent, MessageEvent},
@@ -19,7 +21,7 @@ pub struct Props {
#[prop_or_default]
pub image_event: Option<ImageMessageEventContent>,
#[prop_or_default]
- pub room: Option<Room>,
+ pub room: Option<Rc<Room>>,
}
impl Component for Image {
diff --git a/src/app/components/events/notice.rs b/src/app/components/events/notice.rs
@@ -1,3 +1,5 @@
+use std::rc::Rc;
+
use linkify::LinkFinder;
use matrix_sdk::{
events::room::message::{MessageEvent, NoticeMessageEventContent},
@@ -22,7 +24,7 @@ pub struct Props {
#[prop_or_default]
pub notice_event: Option<NoticeMessageEventContent>,
#[prop_or_default]
- pub room: Option<Room>,
+ pub room: Option<Rc<Room>>,
}
impl Component for Notice {
diff --git a/src/app/components/events/text.rs b/src/app/components/events/text.rs
@@ -1,3 +1,5 @@
+use std::rc::Rc;
+
use crate::app::components::events::{get_sender_displayname, is_new_user};
use linkify::LinkFinder;
use matrix_sdk::{
@@ -21,7 +23,7 @@ pub struct Props {
#[prop_or_default]
pub text_event: Option<TextMessageEventContent>,
#[prop_or_default]
- pub room: Option<Room>,
+ pub room: Option<Rc<Room>>,
}
impl Component for Text {
diff --git a/src/app/components/events/video.rs b/src/app/components/events/video.rs
@@ -1,3 +1,5 @@
+use std::rc::Rc;
+
use crate::app::components::events::{get_sender_displayname, is_new_user};
use matrix_sdk::{
events::room::message::{MessageEvent, VideoMessageEventContent},
@@ -19,7 +21,7 @@ pub struct Props {
#[prop_or_default]
pub video_event: Option<VideoMessageEventContent>,
#[prop_or_default]
- pub room: Option<Room>,
+ pub room: Option<Rc<Room>>,
}
impl Component for Video {
diff --git a/src/app/components/room_list/item.rs b/src/app/components/room_list/item.rs
@@ -1,3 +1,5 @@
+use std::rc::Rc;
+
use matrix_sdk::{events::room::message::MessageEventContent, identifiers::RoomId, Room};
use yew::prelude::*;
use yewtil::NeqAssign;
@@ -8,13 +10,13 @@ pub(crate) struct RoomItem {
}
pub enum Msg {
- ChangeRoom(Room),
+ ChangeRoom(Rc<Room>),
}
#[derive(Clone, Properties, Debug, PartialEq)]
pub struct Props {
#[prop_or_default]
- pub room: Option<Room>,
+ pub room: Option<Rc<Room>>,
#[prop_or_default]
pub change_room_callback: Callback<RoomId>,
@@ -31,7 +33,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.room_id);
+ self.props.change_room_callback.emit(room.room_id.clone());
}
}
false
diff --git a/src/app/components/room_list/mod.rs b/src/app/components/room_list/mod.rs
@@ -1,5 +1,4 @@
-use std::collections::HashMap;
-use std::include_str;
+use std::{collections::HashMap, rc::Rc};
use log::*;
use matrix_sdk::{identifiers::RoomId, Room};
@@ -36,7 +35,7 @@ pub enum Msg {
#[derive(Serialize, Deserialize, Default)]
pub struct State {
- rooms: HashMap<RoomId, Room>,
+ rooms: HashMap<RoomId, Rc<Room>>,
current_room: Option<RoomId>,
loading: bool,
search_query: Option<String>,
@@ -46,7 +45,7 @@ pub struct State {
#[derive(Clone, PartialEq, Properties)]
pub struct Props {
#[prop_or_default]
- pub change_room_callback: Callback<Room>,
+ pub change_room_callback: Callback<Rc<Room>>,
}
impl Component for RoomList {
@@ -85,7 +84,7 @@ impl Component for RoomList {
}
Response::JoinedRoom((room_id, room)) => {
info!("Got JoinedRoom");
- self.state.rooms.insert(room_id, room);
+ self.state.rooms.insert(room_id, Rc::new(room));
if self.state.loading {
self.state.loading = false;
}
@@ -213,10 +212,10 @@ impl Component for RoomList {
}
impl RoomList {
- fn get_room(&self, matrix_room: &Room) -> Html {
+ fn get_room(&self, matrix_room: &Rc<Room>) -> Html {
let room = matrix_room.clone();
html! {
- <RoomItem change_room_callback=self.link.callback(Msg::ChangeRoom) room=Some(room)/>
+ <RoomItem change_room_callback=self.link.callback(Msg::ChangeRoom) room=room.clone() />
}
/*html! {
<li class=classes>
diff --git a/src/app/views/main_view.rs b/src/app/views/main_view.rs
@@ -1,3 +1,5 @@
+use std::rc::Rc;
+
use log::*;
use matrix_sdk::Room;
use serde::{Deserialize, Serialize};
@@ -15,12 +17,12 @@ pub struct MainView {
}
pub enum Msg {
- ChangeRoom(Room),
+ ChangeRoom(Rc<Room>),
}
#[derive(Serialize, Deserialize, Default)]
pub struct State {
- pub current_room: Option<Room>,
+ pub current_room: Option<Rc<Room>>,
pub current_room_displayname: String,
}