summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoscha <joscha@plugh.de>2022-09-26 20:34:45 +0200
committerJoscha <joscha@plugh.de>2022-09-26 20:34:45 +0200
commit7dfa8c604865d24a9e3c8352522c0d9379aa0e8b (patch)
treedb60ffee9fe676f7f0363049cd0ecfb701f77448
parent61a9cc10f1058f3fcabd18993d42afe9a25671a7 (diff)
Make initial rooms sort order configurable
-rw-r--r--CHANGELOG.md1
-rw-r--r--README.md16
-rw-r--r--src/config.rs10
-rw-r--r--src/ui/rooms.rs13
4 files changed, 38 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1dd5b1e..21d390b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,7 @@ Procedure when bumping the version number:
- Message inspection popup
- Session inspection popup
- Error popup when external editor fails
+- `rooms_sort_order` config option
### Changed
- Use nick changes to detect sessions for nick list
diff --git a/README.md b/README.md
index 3517bce..e9b1ee8 100644
--- a/README.md
+++ b/README.md
@@ -115,6 +115,22 @@ the rooms list.
See also the `--offline` command line option.
+### `rooms_sort_order`
+
+**Type:** String, one of `alphabetic`, `importance`
+**Default:** `alphabetic`
+
+Initial sort order of rooms list.
+
+`alphabetic` sorts rooms in alphabetic order.
+
+`importance` sorts rooms by the following criteria (in descending order of
+priority):
+
+1. connected rooms before unconnected rooms
+2. rooms with unread messages before rooms without
+3. alphabetic order
+
### `euph.rooms.<room>.autojoin`
**Type:** Boolean
diff --git a/src/config.rs b/src/config.rs
index e0823bb..c6c98b5 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -6,6 +6,14 @@ use serde::Deserialize;
use crate::macros::ok_or_return;
+#[derive(Debug, Clone, Copy, Default, Deserialize)]
+#[serde(rename_all = "snake_case")]
+pub enum RoomsSortOrder {
+ #[default]
+ Alphabet,
+ Importance,
+}
+
#[derive(Debug, Clone, Default, Deserialize)]
pub struct EuphRoom {
// TODO Mark favourite rooms via printable ascii characters
@@ -29,6 +37,8 @@ pub struct Config {
pub ephemeral: bool,
#[serde(default)]
pub offline: bool,
+ #[serde(default)]
+ pub rooms_sort_order: RoomsSortOrder,
// TODO Invoke external notification command?
pub euph: Euph,
}
diff --git a/src/ui/rooms.rs b/src/ui/rooms.rs
index 683ef5a..3e4d9d0 100644
--- a/src/ui/rooms.rs
+++ b/src/ui/rooms.rs
@@ -10,7 +10,7 @@ use tokio::sync::mpsc;
use toss::styled::Styled;
use toss::terminal::Terminal;
-use crate::config::Config;
+use crate::config::{Config, RoomsSortOrder};
use crate::euph::EuphRoomEvent;
use crate::vault::Vault;
@@ -38,6 +38,15 @@ enum Order {
Importance,
}
+impl Order {
+ fn from_rooms_sort_order(order: RoomsSortOrder) -> Self {
+ match order {
+ RoomsSortOrder::Alphabet => Self::Alphabet,
+ RoomsSortOrder::Importance => Self::Importance,
+ }
+ }
+}
+
pub struct Rooms {
config: &'static Config,
@@ -63,7 +72,7 @@ impl Rooms {
ui_event_tx,
state: State::ShowList,
list: ListState::new(),
- order: Order::Alphabet,
+ order: Order::from_rooms_sort_order(config.rooms_sort_order),
euph_rooms: HashMap::new(),
};