diff --git a/fractal-api/src/backend/mod.rs b/fractal-api/src/backend/mod.rs index 2247f7dc..90ab2f0f 100644 --- a/fractal-api/src/backend/mod.rs +++ b/fractal-api/src/backend/mod.rs @@ -228,7 +228,9 @@ impl Backend { } // Internal commands - + Ok(BKCommand::SpreadResponse(resp)) => { + tx.send(resp).unwrap(); + } Ok(BKCommand::NotifyClicked(message)) => { tx.send(BKResponse::NotificationClicked(message)).unwrap(); } diff --git a/fractal-api/src/backend/types.rs b/fractal-api/src/backend/types.rs index 27cf44bd..668540cb 100644 --- a/fractal-api/src/backend/types.rs +++ b/fractal-api/src/backend/types.rs @@ -47,6 +47,7 @@ pub enum BKCommand { Search(String, Option), NotifyClicked(Message), NewRoom(String, RoomType), + SpreadResponse(BKResponse), } #[derive(Debug)] @@ -81,6 +82,7 @@ pub enum BKResponse { SearchEnd, NotificationClicked(Message), NewRoom(Room), + RoomSelected(Room), //errors UserNameError(Error), diff --git a/fractal-gtk/src/app.rs b/fractal-gtk/src/app.rs index 88ed28bf..339f4007 100644 --- a/fractal-gtk/src/app.rs +++ b/fractal-gtk/src/app.rs @@ -492,6 +492,11 @@ impl AppOp { self.roomlist.add_room(v.clone()); } + let bk = self.backend.clone(); + self.roomlist.connect(move |room| { + bk.send(BKCommand::SpreadResponse(BKResponse::RoomSelected(room))).unwrap(); + }); + let mut godef = def; if let Some(aroom) = self.active_room.clone() { if let Some(r) = self.rooms.get(&aroom) { @@ -1983,6 +1988,9 @@ fn backend_loop(op: Arc>, rx: Receiver) { println!("SYNC"); op.lock().unwrap().synced(Some(since)); } + Ok(BKResponse::RoomSelected(room)) => { + op.lock().unwrap().set_active_room(&room); + } Ok(BKResponse::Rooms(rooms, default)) => { op.lock().unwrap().set_rooms(rooms, default); } diff --git a/fractal-gtk/src/widgets/roomlist.rs b/fractal-gtk/src/widgets/roomlist.rs index 531f03cf..36f3b75d 100644 --- a/fractal-gtk/src/widgets/roomlist.rs +++ b/fractal-gtk/src/widgets/roomlist.rs @@ -12,6 +12,8 @@ pub struct RoomList { pub rooms: HashMap, pub baseu: Url, list: gtk::ListBox, + + roomvec: Vec, // TODO: // * Add a header to the list // * Add a collapse/expand button with a revealer @@ -26,11 +28,13 @@ impl RoomList { None => Url::parse("https://matrix.org").unwrap() }; let rooms = HashMap::new(); + let roomvec = vec![]; RoomList { list, baseu, rooms, + roomvec, } } @@ -41,6 +45,8 @@ impl RoomList { } let rid = r.id.clone(); + self.roomvec.push(r.clone()); + let row = RoomRow::new(r, &self.baseu); self.list.add(&row.widget()); @@ -76,4 +82,12 @@ impl RoomList { b } + + pub fn connect(&self, cb: F) { + let rs = self.roomvec.clone(); + self.list.connect_row_activated(move |_, row| { + let idx = row.get_index(); + cb(rs[idx as usize].clone()); + }); + } }