[fractal] roomlist: flatten sibling_id function
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal] roomlist: flatten sibling_id function
- Date: Tue, 14 May 2019 11:43:24 +0000 (UTC)
commit a6722dbfc5c3a2d3f593e509acb04d6966757d78
Author: Daniel Garcia Moreno <dani danigm net>
Date: Tue May 14 06:47:40 2019 +0000
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.
fractal-gtk/src/widgets/roomlist.rs | 52 +++++++++++++++++++++++--------------
1 file changed, 32 insertions(+), 20 deletions(-)
---
diff --git a/fractal-gtk/src/widgets/roomlist.rs b/fractal-gtk/src/widgets/roomlist.rs
index c9132444..3f58349a 100644
--- a/fractal-gtk/src/widgets/roomlist.rs
+++ b/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)
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]