diff options
-rw-r--r-- | res/css/main.css | 5 | ||||
-rw-r--r-- | src/components/chatinput.cpp | 17 | ||||
-rw-r--r-- | src/components/chatinput.hpp | 4 | ||||
-rw-r--r-- | src/components/chatwindow.cpp | 24 | ||||
-rw-r--r-- | src/constants.hpp | 5 |
5 files changed, 52 insertions, 3 deletions
diff --git a/res/css/main.css b/res/css/main.css index a3d0421..142dede 100644 --- a/res/css/main.css +++ b/res/css/main.css @@ -102,12 +102,17 @@ background-color: #242424; color: #adadad; border-radius: 15px; + border: 1px solid transparent; } .message-input.replying { border: 1px solid #026FB9; } +.message-input.bad-input { + border: 1px solid #dd3300; +} + .message-input { padding: 0px 0px 0px 5px; } diff --git a/src/components/chatinput.cpp b/src/components/chatinput.cpp index b71a234..fc5ef38 100644 --- a/src/components/chatinput.cpp +++ b/src/components/chatinput.cpp @@ -392,6 +392,23 @@ void ChatInput::AddAttachment(const Glib::RefPtr<Gio::File> &file) { } } +void ChatInput::IndicateTooLarge() { + m_input.get_style_context()->add_class("bad-input"); + const auto cb = [this] { + m_input.get_style_context()->remove_class("bad-input"); + }; + Glib::signal_timeout().connect_seconds_once(sigc::track_obj(cb, *this), 2); +} + +void ChatInput::StartReplying() { + m_input.grab_focus(); + m_input.get_style_context()->add_class("replying"); +} + +void ChatInput::StopReplying() { + m_input.get_style_context()->remove_class("replying"); +} + bool ChatInput::AddFileAsImageAttachment(const Glib::RefPtr<Gio::File> &file) { try { const auto read_stream = file->read(); diff --git a/src/components/chatinput.hpp b/src/components/chatinput.hpp index 625161a..2b88fd1 100644 --- a/src/components/chatinput.hpp +++ b/src/components/chatinput.hpp @@ -102,6 +102,10 @@ public: Glib::RefPtr<Gtk::TextBuffer> GetBuffer(); bool ProcessKeyPress(GdkEventKey *event); void AddAttachment(const Glib::RefPtr<Gio::File> &file); + void IndicateTooLarge(); + + void StartReplying(); + void StopReplying(); private: bool AddFileAsImageAttachment(const Glib::RefPtr<Gio::File> &file); diff --git a/src/components/chatwindow.cpp b/src/components/chatwindow.cpp index 5cbeea1..61d3712 100644 --- a/src/components/chatwindow.cpp +++ b/src/components/chatwindow.cpp @@ -4,6 +4,7 @@ #include "ratelimitindicator.hpp" #include "chatinput.hpp" #include "chatlist.hpp" +#include "constants.hpp" #ifdef WITH_LIBHANDY #include "channeltabswitcherhandy.hpp" #endif @@ -222,6 +223,24 @@ Snowflake ChatWindow::GetActiveChannel() const { } bool ChatWindow::OnInputSubmit(ChatSubmitParams data) { + int restriction = BaseAttachmentSizeLimit; + const auto nitro = Abaddon::Get().GetDiscordClient().GetUserData().PremiumType; + if (!nitro.has_value() || nitro == EPremiumType::None) { + restriction = BaseAttachmentSizeLimit; + } else if (nitro == EPremiumType::NitroClassic) { + restriction = NitroClassicAttachmentSizeLimit; + } else if (nitro == EPremiumType::Nitro) { + restriction = NitroAttachmentSizeLimit; + } + + for (const auto &attachment : data.Attachments) { + const auto info = attachment.File->query_info(); + if (info && info->get_size() > restriction) { + m_input->IndicateTooLarge(); + return false; + } + } + if (!m_rate_limit_indicator->CanSpeak()) return false; @@ -255,8 +274,7 @@ void ChatWindow::StartReplying(Snowflake message_id) { const auto author = discord.GetUser(message.Author.ID); m_replying_to = message_id; m_is_replying = true; - m_input->grab_focus(); - m_input->get_style_context()->add_class("replying"); + m_input->StartReplying(); if (author.has_value()) m_input_indicator->SetCustomMarkup("Replying to " + author->GetEscapedBoldString<false>()); else @@ -266,7 +284,7 @@ void ChatWindow::StartReplying(Snowflake message_id) { void ChatWindow::StopReplying() { m_is_replying = false; m_replying_to = Snowflake::Invalid; - m_input->get_style_context()->remove_class("replying"); + m_input->StopReplying(); m_input_indicator->ClearCustom(); } diff --git a/src/constants.hpp b/src/constants.hpp index 30de2ae..9b2413d 100644 --- a/src/constants.hpp +++ b/src/constants.hpp @@ -3,3 +3,8 @@ constexpr static uint64_t SnowflakeSplitDifference = 600; constexpr static int MaxMessagesForChatCull = 50; // this has to be 50 (for now) cuz that magic number is used in a couple other places and i dont feel like replacing them constexpr static int AttachmentItemSize = 128; +constexpr static int BaseAttachmentSizeLimit = 8 * 1024 * 1024; +constexpr static int NitroClassicAttachmentSizeLimit = 50 * 1024 * 1024; +constexpr static int NitroAttachmentSizeLimit = 100 * 1024 * 1024; +constexpr static int BoostLevel2AttachmentSizeLimit = 50 * 1024 * 1024; +constexpr static int BoostLevel3AttachmentSizeLimit = 100 * 1024 * 1024; |