tweaking visible messages limits

This commit is contained in:
2026-04-08 23:51:02 -04:00
parent f44d2810bf
commit bc34f0c1be
4 changed files with 101 additions and 23 deletions
+9 -6
View File
@@ -414,8 +414,9 @@ pub fn subscribe_to_channel(ctx: &ReducerContext, channel_id: u64) {
.channel_id()
.find(channel_id);
let current_max = hwm.map(|h| h.last_seq_id).unwrap_or(0);
let earliest = if current_max > 99 {
current_max - 99
let limit = get_recent_message_limit(&ctx.db);
let earliest = if current_max >= limit {
current_max - (limit - 1)
} else {
1
};
@@ -1041,8 +1042,9 @@ pub fn create_thread_with_message(
ctx.db.recent_message().id().update(parent_rm);
}
if seq_id > 100 {
let old_seq_id = seq_id - 100;
let limit = get_recent_message_limit(&ctx.db);
if seq_id > limit {
let old_seq_id = seq_id - limit;
let to_delete: Vec<_> = ctx
.db
.recent_message()
@@ -1146,8 +1148,9 @@ pub fn send_message(
}
}
if seq_id > 100 {
let old_seq_id = seq_id - 100;
let limit = get_recent_message_limit(&ctx.db);
if seq_id > limit {
let old_seq_id = seq_id - limit;
let to_delete: Vec<_> = ctx
.db
.recent_message()
+8
View File
@@ -28,6 +28,14 @@ pub fn validate_message_length(db: &Local, text: &str) -> Result<(), String> {
Ok(())
}
pub fn get_recent_message_limit(db: &Local) -> u64 {
db.system_configuration()
.key()
.find("recent_message_limit".to_string())
.and_then(|c| c.value.parse::<u64>().ok())
.unwrap_or(50)
}
pub fn get_next_seq_id(db: &Local, channel_id: u64) -> u64 {
let hwm = db.channel_high_water_mark().channel_id().find(channel_id);
let next_seq_id = hwm.as_ref().map(|h| h.last_seq_id + 1).unwrap_or(1);