From 89424aa5e3017602102c4155da21c5b244f9c084 Mon Sep 17 00:00:00 2001 From: TicClick Date: Sat, 20 Jan 2024 00:38:25 +0100 Subject: [PATCH] limit max message length by 450 characters as per Bancho restrictions --- src/gui/chat.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/gui/chat.rs b/src/gui/chat.rs index 0e45f82..6af185a 100644 --- a/src/gui/chat.rs +++ b/src/gui/chat.rs @@ -8,6 +8,8 @@ use crate::core::chat::{Chat, ChatLike, Message, MessageChunk, MessageType}; use crate::gui::state::UIState; use crate::gui::DecoratedText; +const MAX_MESSAGE_LENGTH: usize = 450; + trait WithInnerShadow { fn inner_shadow_bottom(&self, pixels: usize); } @@ -71,13 +73,25 @@ impl ChatWindow { if interactive { egui::TopBottomPanel::bottom("input").show(ctx, |ui| { ui.vertical_centered_justified(|ui| { + let message_length_exceeded = self.chat_input.len() >= 450; + // Special tabs (server messages and highlights) are 1) fake and 2) read-only - let text_field = egui::TextEdit::singleline(&mut self.chat_input) + let mut text_field = egui::TextEdit::singleline(&mut self.chat_input) + .char_limit(MAX_MESSAGE_LENGTH) .id_source("chat-input") .hint_text("new message"); + if message_length_exceeded { + text_field = text_field.text_color(egui::Color32::RED); + } ui.add_space(8.); - let response = ui.add(text_field); + let mut response = ui.add(text_field); + if message_length_exceeded { + response = response.on_hover_text_at_pointer(format!( + "messages longer than {} characters are truncated", + MAX_MESSAGE_LENGTH + )); + } self.response_widget_id = Some(response.id); ui.add_space(2.);