Commit 8d42e3e9 authored by Daniel García Moreno's avatar Daniel García Moreno

Room select signal connected

See #34
parent c2168542
......@@ -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();
}
......
......@@ -47,6 +47,7 @@ pub enum BKCommand {
Search(String, Option<String>),
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),
......
......@@ -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<Mutex<AppOp>>, rx: Receiver<BKResponse>) {
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);
}
......
......@@ -12,6 +12,8 @@ pub struct RoomList {
pub rooms: HashMap<String, RoomRow>,
pub baseu: Url,
list: gtk::ListBox,
roomvec: Vec<Room>,
// 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<F: Fn(Room) + 'static>(&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());
});
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment