Browse Source

roomlist: flatten sibling_id function

The sibling_id function has a complex if-else, to flatten that
I've split the functionality in three different functions with
one if-else in each one so the code is easier to read.
environments/review-bilelmouss-0wa3h6/deployments/78
Daniel Garcia Moreno 7 years ago
parent
commit
a6722dbfc5
  1. 52
      fractal-gtk/src/widgets/roomlist.rs

52
fractal-gtk/src/widgets/roomlist.rs

@ -524,8 +524,8 @@ impl RoomList {
//FIXME don't use to_string(), pass &str
run_in_group!(self, &r.to_string(), set_selected, Some(r.to_string()));
}
fn sibling_id(&self, unread_only: bool, direction: i32) -> Option<String> {
fn sibling_id_inv(&self, unread_only: bool, direction: i32) -> Option<String> {
let (room, _, next) = self.inv.get().sibling_id(unread_only, direction);
if let Some(room) = room {
@ -533,28 +533,40 @@ impl RoomList {
} else if next {
self.fav.get().first_id(unread_only)
} else {
let (room, prev, next) = self.fav.get().sibling_id(unread_only, direction);
if let Some(room) = room {
Some(room)
} else if prev {
self.inv.get().last_id(unread_only)
} else if next {
self.rooms.get().first_id(unread_only)
} else {
let (room, prev, _) = self.rooms.get().sibling_id(unread_only, direction);
self.sibling_id_fav(unread_only, direction)
}
}
if let Some(room) = room {
Some(room)
} else if prev {
self.fav.get().last_id(unread_only)
} else {
None
}
}
fn sibling_id_fav(&self, unread_only: bool, direction: i32) -> Option<String> {
let (room, prev, next) = self.fav.get().sibling_id(unread_only, direction);
if let Some(room) = room {
Some(room)
} else if prev {
self.inv.get().last_id(unread_only)
} else if next {
self.rooms.get().first_id(unread_only)
} else {
self.sibling_id_rooms(unread_only, direction)
}
}
fn sibling_id_rooms(&self, unread_only: bool, direction: i32) -> Option<String> {
let (room, prev, _) = self.rooms.get().sibling_id(unread_only, direction);
if let Some(room) = room {
Some(room)
} else if prev {
self.fav.get().last_id(unread_only)
} else {
None
}
}
fn sibling_id(&self, unread_only: bool, direction: i32) -> Option<String> {
self.sibling_id_inv(unread_only, direction)
}
pub fn next_id(&self) -> Option<String> {
self.sibling_id(false, 1)
}

Loading…
Cancel
Save