feat: enhance deployment instructions and exclude spam threads from message capture
This commit is contained in:
@@ -44,8 +44,9 @@ fn render_emojis(content: &str) -> Vec<AnyView> {
|
||||
}
|
||||
|
||||
fn time_ago(ts: i64) -> String {
|
||||
let now = (js_sys::Date::now() / 1000.0) as i64;
|
||||
let secs = if now > ts { now - ts } else { 0 };
|
||||
let now = js_sys::Date::now() as i64;
|
||||
// created_at is in milliseconds (from Discord's message.createdTimestamp)
|
||||
let secs = if now > ts { (now - ts) / 1000 } else { 0 };
|
||||
if secs < 60 {
|
||||
format!("{}s ago", secs)
|
||||
} else if secs < 3600 {
|
||||
@@ -53,13 +54,13 @@ fn time_ago(ts: i64) -> String {
|
||||
} else if secs < 86400 {
|
||||
format!("{}h ago", secs / 3600)
|
||||
} else {
|
||||
let d = js_sys::Date::new(&JsValue::from_f64((ts as f64) * 1000.0));
|
||||
let d = js_sys::Date::new(&JsValue::from_f64(ts as f64));
|
||||
format!("{}", d.to_locale_date_string("en-US", &JsValue::UNDEFINED))
|
||||
}
|
||||
}
|
||||
|
||||
fn fmt_time(ts: i64) -> String {
|
||||
let d = js_sys::Date::new(&JsValue::from_f64((ts as f64) * 1000.0));
|
||||
let d = js_sys::Date::new(&JsValue::from_f64(ts as f64));
|
||||
format!("{:02}:{:02}", d.get_hours(), d.get_minutes())
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,17 @@ use shared_types::message::{AiStatus, MessageRecord, PageResult};
|
||||
use std::sync::Arc;
|
||||
use wasm_bindgen_futures::spawn_local;
|
||||
|
||||
/// Threads whose messages should be hidden from both the feed and the
|
||||
/// Images tab. A bot or selfbot may be spamming in a thread, polluting
|
||||
/// the dashboard — add its thread ID here to keep the view clean.
|
||||
const EXCLUDED_THREAD_IDS: &[&str] = &["1522077685508083893"];
|
||||
|
||||
fn is_excluded_thread(m: &MessageRecord) -> bool {
|
||||
m.thread_id
|
||||
.as_deref()
|
||||
.is_some_and(|tid| EXCLUDED_THREAD_IDS.contains(&tid))
|
||||
}
|
||||
|
||||
pub mod components;
|
||||
pub mod hooks;
|
||||
|
||||
@@ -82,6 +93,7 @@ pub fn MessagesPanel() -> impl IntoView {
|
||||
}
|
||||
format!("{:?}", status).to_lowercase() == filter
|
||||
})
|
||||
.filter(|m| !is_excluded_thread(m))
|
||||
.collect()
|
||||
});
|
||||
|
||||
@@ -174,30 +186,36 @@ pub fn MessagesPanel() -> impl IntoView {
|
||||
|
||||
// Fetch image messages when Images tab is selected
|
||||
let fetch_images = {
|
||||
let image_messages = image_messages.clone();
|
||||
move || {
|
||||
spawn_local({
|
||||
async move {
|
||||
if let Some(config) = use_context::<crate::app::AppConfig>() {
|
||||
if let Some(ref guild_id) = config.monitor_guild_id.get() {
|
||||
match crate::api::messages::get_images(guild_id, Some(100)).await {
|
||||
Ok(PageResult { data, .. }) => {
|
||||
web_sys::console::log_2(
|
||||
&"[images] fetch OK".into(),
|
||||
&format!("count={}", data.len()).into(),
|
||||
);
|
||||
image_messages.set(data);
|
||||
}
|
||||
Err(e) => {
|
||||
web_sys::console::log_2(
|
||||
&"[images] fetch ERROR".into(),
|
||||
&format!("{}", e).into(),
|
||||
);
|
||||
}
|
||||
let guild_id = use_context::<crate::app::AppConfig>()
|
||||
.and_then(|c| c.monitor_guild_id.get());
|
||||
if let Some(gid) = guild_id {
|
||||
spawn_local({
|
||||
let image_messages = image_messages.clone();
|
||||
async move {
|
||||
match crate::api::messages::get_images(&gid, Some(100)).await {
|
||||
Ok(PageResult { data, .. }) => {
|
||||
web_sys::console::log_2(
|
||||
&"[images] fetch OK".into(),
|
||||
&format!("count={}", data.len()).into(),
|
||||
);
|
||||
image_messages.set(
|
||||
data.into_iter()
|
||||
.filter(|m| !is_excluded_thread(m))
|
||||
.collect(),
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
web_sys::console::log_2(
|
||||
&"[images] fetch ERROR".into(),
|
||||
&format!("{}", e).into(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
// Fetch images when tab changes to Images
|
||||
|
||||
Reference in New Issue
Block a user