diff --git a/spacetimedb/src/reducers.rs b/spacetimedb/src/reducers.rs index ffff3cd..f83dd63 100644 --- a/spacetimedb/src/reducers.rs +++ b/spacetimedb/src/reducers.rs @@ -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() diff --git a/spacetimedb/src/utils.rs b/spacetimedb/src/utils.rs index 9b47c3c..cbbd5cf 100644 --- a/spacetimedb/src/utils.rs +++ b/spacetimedb/src/utils.rs @@ -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::().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); diff --git a/src/chat/components/MessageList.svelte b/src/chat/components/MessageList.svelte index 0e4cf37..8b6f874 100644 --- a/src/chat/components/MessageList.svelte +++ b/src/chat/components/MessageList.svelte @@ -1,5 +1,5 @@