diff --git a/client/Configuration.cs b/client/Configuration.cs index 153fabd..db2c6d4 100644 --- a/client/Configuration.cs +++ b/client/Configuration.cs @@ -11,4 +11,5 @@ public class Configuration : IPluginConfiguration { public bool DisableTrials = true; public bool DisableDeepDungeon = true; public bool RemoveGlow = true; + public bool AutoViewer; } diff --git a/client/Ui/MainWindowTabs/Settings.cs b/client/Ui/MainWindowTabs/Settings.cs index c1ace84..99579a6 100644 --- a/client/Ui/MainWindowTabs/Settings.cs +++ b/client/Ui/MainWindowTabs/Settings.cs @@ -14,12 +14,15 @@ internal class Settings : ITab { } public void Draw() { + ImGui.PushTextWrapPos(); + var anyChanged = false; var vfx = false; anyChanged |= vfx |= ImGui.Checkbox("Disable in trials", ref this.Plugin.Config.DisableTrials); anyChanged |= vfx |= ImGui.Checkbox("Disable in Deep Dungeons", ref this.Plugin.Config.DisableDeepDungeon); anyChanged |= vfx |= ImGui.Checkbox("Remove glow effect from signs", ref this.Plugin.Config.RemoveGlow); + anyChanged |= ImGui.Checkbox("Open the viewer automatically when near a sign", ref this.Plugin.Config.AutoViewer); if (anyChanged) { this.Plugin.SaveConfig(); @@ -31,6 +34,8 @@ internal class Settings : ITab { } this.ExtraCodeInput(); + + ImGui.PopTextWrapPos(); } private void ExtraCodeInput() { diff --git a/client/Ui/Viewer.cs b/client/Ui/Viewer.cs index ecdc0ca..11e225d 100644 --- a/client/Ui/Viewer.cs +++ b/client/Ui/Viewer.cs @@ -35,6 +35,10 @@ internal class Viewer { .OrderBy(msg => msg.Id) .ToList(); if (nearby.Count == 0) { + if (this.Plugin.Config.AutoViewer) { + this.Visible = false; + } + ImGui.TextUnformatted("No nearby messages"); goto End; } diff --git a/client/Ui/ViewerButton.cs b/client/Ui/ViewerButton.cs index 3b1dff7..9df7d4b 100644 --- a/client/Ui/ViewerButton.cs +++ b/client/Ui/ViewerButton.cs @@ -19,6 +19,11 @@ internal class ViewerButton { return; } + if (this.Plugin.Config.AutoViewer) { + this.Plugin.Ui.Viewer.Visible = true; + return; + } + ImGui.SetNextWindowBgAlpha(0.5f); if (!ImGui.Begin("##ogt-viewer-button", ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.AlwaysAutoResize)) { ImGui.End(); diff --git a/server/src/message.rs b/server/src/message.rs index fcd8175..0939c2a 100644 --- a/server/src/message.rs +++ b/server/src/message.rs @@ -34,6 +34,8 @@ pub struct RetrievedMessage { pub user_vote: i64, #[serde(skip)] pub created: NaiveDateTime, + #[serde(skip)] + pub user: String, } #[derive(Debug, Serialize)] diff --git a/server/src/web/get_location.rs b/server/src/web/get_location.rs index ca28ed8..91d3fb8 100644 --- a/server/src/web/get_location.rs +++ b/server/src/web/get_location.rs @@ -1,4 +1,3 @@ -use std::collections::HashMap; use std::sync::Arc; use anyhow::Context; @@ -16,15 +15,13 @@ pub fn get_location(state: Arc) -> BoxedFilter<(impl Reply, )> { .and(warp::path("messages")) .and(warp::path::param()) .and(warp::path::end()) - .and(warp::query::>()) .and(super::get_id(Arc::clone(&state))) - .and_then(move |location: u32, query: HashMap, (id, _)| logic(Arc::clone(&state), id, location, query)) + .and_then(move |location: u32, (id, _)| logic(Arc::clone(&state), id, location)) .boxed() } -async fn logic(state: Arc, id: i64, location: u32, query: HashMap) -> Result { +async fn logic(state: Arc, id: i64, location: u32) -> Result { // TODO: when we're not just returning all results, make sure own messages are always present - let filter = query.contains_key("filter"); let location = location as i64; let mut messages = sqlx::query_as!( RetrievedMessage, @@ -39,7 +36,8 @@ async fn logic(state: Arc, id: i64, location: u32, query: HashMap, id: i64, location: u32, query: HashMap) { +fn filter_messages(messages: &mut Vec, id: i64) { + // FIXME: make a migration to fix this, smh I'm dumb + let id_str = id.to_string(); + // just count nearby messages. this is O(n^2) but alternatives are hard let mut ids = Vec::with_capacity(messages.len()); for a in messages.iter() { @@ -81,9 +80,7 @@ fn filter_messages(messages: &mut Vec) { nearby += 1; } - println!("{} ({} nearby)", a.id, nearby); - - if nearby <= 2 { + if a.user == id_str || nearby <= 2 { // always include groups of three or fewer ids.push(a.id.clone()); continue; @@ -91,8 +88,6 @@ fn filter_messages(messages: &mut Vec) { let score = (a.positive_votes - a.negative_votes).max(0); let time_since_creation = Utc::now().naive_utc().signed_duration_since(a.created) - Duration::weeks(score as i64); - println!(" time_since_creation: {}", Utc::now().naive_utc().signed_duration_since(a.created)); - println!(" modified: {}", time_since_creation); if time_since_creation > Duration::weeks(1) { continue; } @@ -114,7 +109,6 @@ fn filter_messages(messages: &mut Vec) { numerator += rounded.max(nearby / 2); } - println!(" chance: {}/{}", numerator, nearby * 2); if rand::thread_rng().gen_ratio(numerator.min(nearby), nearby * 2) { ids.push(a.id.clone()); }