Make history-related constants configurable
This commit is contained in:
@ -39,7 +39,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub struct App {
|
pub struct App {
|
||||||
pub config: Config,
|
pub config: Arc<Config>,
|
||||||
pub clients: NonEmpty<matrix_sdk::Client>,
|
pub clients: NonEmpty<matrix_sdk::Client>,
|
||||||
pub commands: RataCommands,
|
pub commands: RataCommands,
|
||||||
pub tick_rate: f64,
|
pub tick_rate: f64,
|
||||||
@ -120,6 +120,7 @@ impl App {
|
|||||||
}
|
}
|
||||||
let clients = NonEmpty::collect(clients).expect("map on NonEmpty returned empty vec");
|
let clients = NonEmpty::collect(clients).expect("map on NonEmpty returned empty vec");
|
||||||
|
|
||||||
|
let config = Arc::new(config);
|
||||||
let home = Home::new(config.clone());
|
let home = Home::new(config.clone());
|
||||||
let fps = FpsCounter::default();
|
let fps = FpsCounter::default();
|
||||||
let mode = Mode::Home;
|
let mode = Mode::Home;
|
||||||
@ -398,7 +399,7 @@ impl App {
|
|||||||
) {
|
) {
|
||||||
futures::future::join_all(
|
futures::future::join_all(
|
||||||
rooms
|
rooms
|
||||||
.map(|(client, room)| RoomBuffer::new(client, room))
|
.map(|(client, room)| RoomBuffer::new(self.config.clone(), client, room))
|
||||||
.map(|fut| fut.map(|res| res.expect("Failed to create RoomBuffer at startup"))),
|
.map(|fut| fut.map(|res| res.expect("Failed to create RoomBuffer at startup"))),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
@ -47,6 +47,7 @@ use sorted_vec::SortedVec;
|
|||||||
use tokio::sync::oneshot;
|
use tokio::sync::oneshot;
|
||||||
|
|
||||||
use super::{Buffer, BufferId, BufferItem, BufferItemContent, BufferSortKey, FullyReadStatus};
|
use super::{Buffer, BufferId, BufferItem, BufferItemContent, BufferSortKey, FullyReadStatus};
|
||||||
|
use crate::config::Config;
|
||||||
use crate::widgets::Prerender;
|
use crate::widgets::Prerender;
|
||||||
|
|
||||||
/// Like [`BufferItemContent`] but owned.
|
/// Like [`BufferItemContent`] but owned.
|
||||||
@ -368,6 +369,8 @@ impl SingleClientRoomBuffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct RoomBuffer {
|
pub struct RoomBuffer {
|
||||||
|
config: Arc<Config>,
|
||||||
|
|
||||||
room_id: OwnedRoomId,
|
room_id: OwnedRoomId,
|
||||||
|
|
||||||
computed_roominfo: Option<ComputedRoomInfo>,
|
computed_roominfo: Option<ComputedRoomInfo>,
|
||||||
@ -400,8 +403,13 @@ impl DynamicUsage for RoomBuffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl RoomBuffer {
|
impl RoomBuffer {
|
||||||
pub async fn new(initial_client: Client, room_id: OwnedRoomId) -> Result<Self> {
|
pub async fn new(
|
||||||
|
config: Arc<Config>,
|
||||||
|
initial_client: Client,
|
||||||
|
room_id: OwnedRoomId,
|
||||||
|
) -> Result<Self> {
|
||||||
let mut self_ = RoomBuffer {
|
let mut self_ = RoomBuffer {
|
||||||
|
config,
|
||||||
room_id,
|
room_id,
|
||||||
computed_roominfo: None,
|
computed_roominfo: None,
|
||||||
update_roominfo_rx: None,
|
update_roominfo_rx: None,
|
||||||
@ -674,8 +682,12 @@ impl Buffer for RoomBuffer {
|
|||||||
// * we already backfilled a lot so we don't exhaust the available memory
|
// * we already backfilled a lot so we don't exhaust the available memory
|
||||||
// * we already reached an unread message, in which case it's pointless to
|
// * we already reached an unread message, in which case it's pointless to
|
||||||
// backfill as we already know there are unread messages.
|
// backfill as we already know there are unread messages.
|
||||||
if buf.items.len() < 1000 {
|
if buf.items.len() < self.config.history.max_prefetch_unread
|
||||||
buf.back_pagination_request.fetch_max(50, Ordering::Relaxed);
|
&& self.config.history.prefetch_unread > 0
|
||||||
|
{
|
||||||
|
buf
|
||||||
|
.back_pagination_request
|
||||||
|
.fetch_max(self.config.history.prefetch_unread, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use std::ops::DerefMut;
|
use std::ops::DerefMut;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use color_eyre::eyre::{Result, WrapErr};
|
use color_eyre::eyre::{Result, WrapErr};
|
||||||
use crossterm::event::{KeyCode, KeyEvent, KeyEventKind, KeyModifiers};
|
use crossterm::event::{KeyCode, KeyEvent, KeyEventKind, KeyModifiers};
|
||||||
@ -41,7 +42,7 @@ struct ScrollPosition {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Backlog {
|
pub struct Backlog {
|
||||||
config: Config,
|
config: Arc<Config>,
|
||||||
/// Used to compute scroll on PageUp/PageDown when configured to a percentage.
|
/// Used to compute scroll on PageUp/PageDown when configured to a percentage.
|
||||||
last_height: u16,
|
last_height: u16,
|
||||||
scroll_position: Option<ScrollPosition>,
|
scroll_position: Option<ScrollPosition>,
|
||||||
@ -97,8 +98,10 @@ impl Component for Backlog {
|
|||||||
|
|
||||||
// We are reaching the end of the backlog we have locally, ask the buffer to fetch
|
// We are reaching the end of the backlog we have locally, ask the buffer to fetch
|
||||||
// more if it can
|
// more if it can
|
||||||
if undrawn_widgets_at_top <= 100 {
|
if undrawn_widgets_at_top <= self.config.history.min_prefetch
|
||||||
active_buffer.request_back_pagination(200);
|
&& self.config.history.prefetch > 0
|
||||||
|
{
|
||||||
|
active_buffer.request_back_pagination(self.config.history.prefetch);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -106,7 +109,7 @@ impl Component for Backlog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Backlog {
|
impl Backlog {
|
||||||
pub fn new(config: Config) -> Self {
|
pub fn new(config: Arc<Config>) -> Self {
|
||||||
Backlog {
|
Backlog {
|
||||||
config,
|
config,
|
||||||
last_height: 30, // Arbitrary default, only useful when user scrolls before first render
|
last_height: 30, // Arbitrary default, only useful when user scrolls before first render
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use color_eyre::eyre::{Result, WrapErr};
|
use color_eyre::eyre::{Result, WrapErr};
|
||||||
use crossterm::event::{MouseEvent, MouseEventKind};
|
use crossterm::event::{MouseEvent, MouseEventKind};
|
||||||
use ratatui::{prelude::*, widgets::*};
|
use ratatui::{prelude::*, widgets::*};
|
||||||
@ -29,14 +31,14 @@ use crate::{
|
|||||||
|
|
||||||
pub struct Buflist {
|
pub struct Buflist {
|
||||||
command_tx: Option<UnboundedSender<Action>>,
|
command_tx: Option<UnboundedSender<Action>>,
|
||||||
config: Config,
|
config: Arc<Config>,
|
||||||
|
|
||||||
/// Updated by [`draw`], used by [`handle_mouse_events`] to find which buffer was clicked.
|
/// Updated by [`draw`], used by [`handle_mouse_events`] to find which buffer was clicked.
|
||||||
last_area: Option<Rect>,
|
last_area: Option<Rect>,
|
||||||
last_num_buffers: Option<usize>,
|
last_num_buffers: Option<usize>,
|
||||||
}
|
}
|
||||||
impl Buflist {
|
impl Buflist {
|
||||||
pub fn new(config: Config) -> Self {
|
pub fn new(config: Arc<Config>) -> Self {
|
||||||
Buflist {
|
Buflist {
|
||||||
command_tx: None,
|
command_tx: None,
|
||||||
config,
|
config,
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
use std::{collections::HashMap, time::Duration};
|
use std::{collections::HashMap, time::Duration};
|
||||||
|
|
||||||
use color_eyre::eyre::{Result, WrapErr};
|
use color_eyre::eyre::{Result, WrapErr};
|
||||||
@ -32,14 +33,14 @@ use crate::{
|
|||||||
|
|
||||||
pub struct Home {
|
pub struct Home {
|
||||||
command_tx: Option<UnboundedSender<Action>>,
|
command_tx: Option<UnboundedSender<Action>>,
|
||||||
config: Config,
|
config: Arc<Config>,
|
||||||
buflist: Buflist,
|
buflist: Buflist,
|
||||||
backlog: Backlog,
|
backlog: Backlog,
|
||||||
textarea: TextArea<'static>,
|
textarea: TextArea<'static>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Home {
|
impl Home {
|
||||||
pub fn new(config: Config) -> Self {
|
pub fn new(config: Arc<Config>) -> Self {
|
||||||
let mut self_ = Home {
|
let mut self_ = Home {
|
||||||
command_tx: None,
|
command_tx: None,
|
||||||
buflist: Buflist::new(config.clone()),
|
buflist: Buflist::new(config.clone()),
|
||||||
|
@ -102,6 +102,14 @@ impl<'de> Visitor<'de> for ScrollAmountVisitor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
|
pub struct HistoryConfig {
|
||||||
|
pub prefetch_unread: u16,
|
||||||
|
pub max_prefetch_unread: usize,
|
||||||
|
pub min_prefetch: usize,
|
||||||
|
pub prefetch: u16,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
pub struct MouseConfig {
|
pub struct MouseConfig {
|
||||||
pub enable: bool,
|
pub enable: bool,
|
||||||
@ -149,6 +157,7 @@ pub struct Config {
|
|||||||
#[serde(default, flatten)]
|
#[serde(default, flatten)]
|
||||||
pub config: AppConfig,
|
pub config: AppConfig,
|
||||||
pub accounts: nonempty::NonEmpty<AccountConfig>,
|
pub accounts: nonempty::NonEmpty<AccountConfig>,
|
||||||
|
pub history: HistoryConfig,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub keybindings: KeyBindings,
|
pub keybindings: KeyBindings,
|
||||||
pub keyboard: KeyboardConfig,
|
pub keyboard: KeyboardConfig,
|
||||||
|
@ -14,6 +14,23 @@ scroll_page = "50%"
|
|||||||
[mouse]
|
[mouse]
|
||||||
enable = true
|
enable = true
|
||||||
|
|
||||||
|
[history]
|
||||||
|
# When there are unread events in a room, how many past events should be fetched
|
||||||
|
# at once to check whether there are unread messages (as opposed to non-message
|
||||||
|
# events), to find if the room should colored with style.buflist.unread_message or
|
||||||
|
# style.buflist.unread_event
|
||||||
|
prefetch_unread = 50
|
||||||
|
# When do stop iteratively fetching pages of size $prefetch_unread when no unread
|
||||||
|
# messages are found
|
||||||
|
max_prefetch_unread = 1000
|
||||||
|
|
||||||
|
# How many older events to keep above the screen in case the user hits PageUp later.
|
||||||
|
# Set to 0 to only fetch when the user reaches an unfetched message.
|
||||||
|
min_prefetch = 100
|
||||||
|
# When getting close to the oldest event we know about, how many events should be
|
||||||
|
# fetched at once
|
||||||
|
prefetch = 200
|
||||||
|
|
||||||
# Configuration for the list of rooms on the right.
|
# Configuration for the list of rooms on the right.
|
||||||
[layout.buflist]
|
[layout.buflist]
|
||||||
# How long room names can be before being truncated.
|
# How long room names can be before being truncated.
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use color_eyre::eyre::WrapErr;
|
use color_eyre::eyre::WrapErr;
|
||||||
@ -29,7 +30,7 @@ fn config() -> Config {
|
|||||||
std::env::set_var("RATATRIX_CONFIG", PathBuf::from(".config/"));
|
std::env::set_var("RATATRIX_CONFIG", PathBuf::from(".config/"));
|
||||||
let c = Config::new();
|
let c = Config::new();
|
||||||
std::env::remove_var("RATATRIX_CONFIG");
|
std::env::remove_var("RATATRIX_CONFIG");
|
||||||
c.unwrap()
|
Arc::new(c.unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rect(x: u16, y: u16, width: u16, height: u16) -> Rect {
|
fn rect(x: u16, y: u16, width: u16, height: u16) -> Rect {
|
||||||
|
Reference in New Issue
Block a user