From 270730d9b36c8fc3a221da7e565632c1432d41c6 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sun, 5 Jun 2022 21:41:57 -0400 Subject: start attachments (image paste and upload) --- src/constants.hpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/constants.hpp') diff --git a/src/constants.hpp b/src/constants.hpp index 6c6276f..30de2ae 100644 --- a/src/constants.hpp +++ b/src/constants.hpp @@ -2,3 +2,4 @@ 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; -- cgit v1.2.3 From 02ce353c6d35af004dc1b6f5ae9f68fbb8540b54 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sat, 9 Jul 2022 01:57:56 -0400 Subject: check nitro size restriction + fix replying border --- res/css/main.css | 5 +++++ src/components/chatinput.cpp | 17 +++++++++++++++++ src/components/chatinput.hpp | 4 ++++ src/components/chatwindow.cpp | 24 +++++++++++++++++++++--- src/constants.hpp | 5 +++++ 5 files changed, 52 insertions(+), 3 deletions(-) (limited to 'src/constants.hpp') 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 &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 &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 GetBuffer(); bool ProcessKeyPress(GdkEventKey *event); void AddAttachment(const Glib::RefPtr &file); + void IndicateTooLarge(); + + void StartReplying(); + void StopReplying(); private: bool AddFileAsImageAttachment(const Glib::RefPtr &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()); 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; -- cgit v1.2.3 From 59acd0f82f500d743ca4be7324f913903c8de237 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sat, 23 Jul 2022 18:34:33 -0400 Subject: handle max message payload + show filename label --- src/components/chatinput.cpp | 32 +++++++++++++++++++++++++++----- src/components/chatinput.hpp | 1 + src/components/chatwindow.cpp | 15 ++++++++++++--- src/constants.hpp | 1 + 4 files changed, 41 insertions(+), 8 deletions(-) (limited to 'src/constants.hpp') diff --git a/src/components/chatinput.cpp b/src/components/chatinput.cpp index fc5ef38..04ba0d9 100644 --- a/src/components/chatinput.cpp +++ b/src/components/chatinput.cpp @@ -2,7 +2,6 @@ #include "abaddon.hpp" #include "constants.hpp" #include -#include ChatInputText::ChatInputText() { get_style_context()->add_class("message-input"); @@ -96,6 +95,8 @@ ChatInputAttachmentContainer::ChatInputAttachmentContainer() : m_box(Gtk::ORIENTATION_HORIZONTAL) { get_style_context()->add_class("attachment-container"); + m_box.set_halign(Gtk::ALIGN_START); + add(m_box); m_box.show(); @@ -194,16 +195,25 @@ ChatInputAttachmentContainer::type_signal_emptied ChatInputAttachmentContainer:: ChatInputAttachmentItem::ChatInputAttachmentItem(const Glib::RefPtr &file) : m_file(file) , m_img(Gtk::make_managed()) - , m_type(ChatSubmitParams::ExtantFile) { + , m_type(ChatSubmitParams::ExtantFile) + , m_box(Gtk::ORIENTATION_VERTICAL) { get_style_context()->add_class("attachment-item"); set_size_request(AttachmentItemSize, AttachmentItemSize); - m_box.set_halign(Gtk::ALIGN_CENTER); + set_halign(Gtk::ALIGN_START); + m_box.set_hexpand(true); + m_box.set_halign(Gtk::ALIGN_FILL); m_box.set_valign(Gtk::ALIGN_CENTER); m_box.add(*m_img); + m_box.add(m_label); add(m_box); show_all_children(); + m_label.set_max_width_chars(0); // will constrain to given size + m_label.set_ellipsize(Pango::ELLIPSIZE_MIDDLE); + m_label.set_margin_start(7); + m_label.set_margin_end(7); + m_img->property_icon_name() = "document-send-symbolic"; m_img->property_icon_size() = Gtk::ICON_SIZE_DIALOG; // todo figure out how to not use this weird property??? i dont know how icons work (screw your theme) @@ -217,7 +227,9 @@ ChatInputAttachmentItem::ChatInputAttachmentItem(const Glib::RefPtr & : m_file(file) , m_img(Gtk::make_managed()) , m_type(is_extant ? ChatSubmitParams::ExtantFile : ChatSubmitParams::PastedImage) - , m_filename("unknown.png") { + , m_filename("unknown.png") + , m_label("unknown.png") + , m_box(Gtk::ORIENTATION_VERTICAL) { get_style_context()->add_class("attachment-item"); int outw, outh; @@ -225,12 +237,20 @@ ChatInputAttachmentItem::ChatInputAttachmentItem(const Glib::RefPtr & m_img->property_pixbuf() = pb->scale_simple(outw, outh, Gdk::INTERP_BILINEAR); set_size_request(AttachmentItemSize, AttachmentItemSize); - m_box.set_halign(Gtk::ALIGN_CENTER); + set_halign(Gtk::ALIGN_START); + m_box.set_hexpand(true); + m_box.set_halign(Gtk::ALIGN_FILL); m_box.set_valign(Gtk::ALIGN_CENTER); m_box.add(*m_img); + m_box.add(m_label); add(m_box); show_all_children(); + m_label.set_max_width_chars(0); // will constrain to given size + m_label.set_ellipsize(Pango::ELLIPSIZE_MIDDLE); + m_label.set_margin_start(7); + m_label.set_margin_end(7); + if (is_extant) SetFilenameFromFile(); @@ -262,6 +282,7 @@ void ChatInputAttachmentItem::RemoveIfTemp() { void ChatInputAttachmentItem::SetFilenameFromFile() { auto info = m_file->query_info(G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME); m_filename = info->get_attribute_string(G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME); + m_label.set_text(m_filename); } void ChatInputAttachmentItem::SetupMenu() { @@ -275,6 +296,7 @@ void ChatInputAttachmentItem::SetupMenu() { const auto name = Abaddon::Get().ShowTextPrompt("Enter new filename for attachment", "Enter filename", m_filename); if (name.has_value()) { m_filename = *name; + m_label.set_text(m_filename); UpdateTooltip(); } }); diff --git a/src/components/chatinput.hpp b/src/components/chatinput.hpp index 2b88fd1..d8484b8 100644 --- a/src/components/chatinput.hpp +++ b/src/components/chatinput.hpp @@ -24,6 +24,7 @@ private: Gtk::MenuItem m_menu_set_filename; Gtk::Box m_box; + Gtk::Label m_label; Gtk::Image *m_img = nullptr; Glib::RefPtr m_file; diff --git a/src/components/chatwindow.cpp b/src/components/chatwindow.cpp index 38e0247..b68ceba 100644 --- a/src/components/chatwindow.cpp +++ b/src/components/chatwindow.cpp @@ -250,11 +250,20 @@ bool ChatWindow::OnInputSubmit(ChatSubmitParams data) { int restriction = std::max(nitro_restriction, guild_restriction); + goffset total_size = 0; 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 (info) { + const auto size = info->get_size(); + if (size > restriction) { + m_input->IndicateTooLarge(); + return false; + } + total_size += size; + if (total_size > MaxMessagePayloadSize) { + m_input->IndicateTooLarge(); + return false; + } } } diff --git a/src/constants.hpp b/src/constants.hpp index 9b2413d..14fa076 100644 --- a/src/constants.hpp +++ b/src/constants.hpp @@ -8,3 +8,4 @@ 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; +constexpr static int MaxMessagePayloadSize = 199 * 1024 * 1024; -- cgit v1.2.3 From 8396d07d9e7c8a3b7d7942694bd82c433eda99b4 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Mon, 25 Jul 2022 00:26:04 -0400 Subject: try to align stuff a little better --- src/components/chatinput.cpp | 19 +++++++++++++++---- src/constants.hpp | 3 ++- 2 files changed, 17 insertions(+), 5 deletions(-) (limited to 'src/constants.hpp') diff --git a/src/components/chatinput.cpp b/src/components/chatinput.cpp index 04ba0d9..77757cf 100644 --- a/src/components/chatinput.cpp +++ b/src/components/chatinput.cpp @@ -135,8 +135,10 @@ bool ChatInputAttachmentContainer::AddImage(const Glib::RefPtr &pb) } auto *item = Gtk::make_managed(Gio::File::create_for_path(path), pb); + item->set_valign(Gtk::ALIGN_FILL); + item->set_vexpand(true); + item->set_margin_bottom(5); item->show(); - item->set_valign(Gtk::ALIGN_CENTER); m_box.add(*item); m_attachments.push_back(item); @@ -161,8 +163,10 @@ bool ChatInputAttachmentContainer::AddFile(const Glib::RefPtr &file, item = Gtk::make_managed(file, pb, true); else item = Gtk::make_managed(file); + item->set_valign(Gtk::ALIGN_FILL); + item->set_vexpand(true); + item->set_margin_bottom(5); item->show(); - item->set_valign(Gtk::ALIGN_CENTER); m_box.add(*item); m_attachments.push_back(item); @@ -202,18 +206,21 @@ ChatInputAttachmentItem::ChatInputAttachmentItem(const Glib::RefPtr & set_size_request(AttachmentItemSize, AttachmentItemSize); set_halign(Gtk::ALIGN_START); m_box.set_hexpand(true); + m_box.set_vexpand(true); m_box.set_halign(Gtk::ALIGN_FILL); - m_box.set_valign(Gtk::ALIGN_CENTER); + m_box.set_valign(Gtk::ALIGN_FILL); m_box.add(*m_img); m_box.add(m_label); add(m_box); show_all_children(); + m_label.set_valign(Gtk::ALIGN_END); m_label.set_max_width_chars(0); // will constrain to given size m_label.set_ellipsize(Pango::ELLIPSIZE_MIDDLE); m_label.set_margin_start(7); m_label.set_margin_end(7); + m_img->set_vexpand(true); m_img->property_icon_name() = "document-send-symbolic"; m_img->property_icon_size() = Gtk::ICON_SIZE_DIALOG; // todo figure out how to not use this weird property??? i dont know how icons work (screw your theme) @@ -239,18 +246,22 @@ ChatInputAttachmentItem::ChatInputAttachmentItem(const Glib::RefPtr & set_size_request(AttachmentItemSize, AttachmentItemSize); set_halign(Gtk::ALIGN_START); m_box.set_hexpand(true); + m_box.set_vexpand(true); m_box.set_halign(Gtk::ALIGN_FILL); - m_box.set_valign(Gtk::ALIGN_CENTER); + m_box.set_valign(Gtk::ALIGN_FILL); m_box.add(*m_img); m_box.add(m_label); add(m_box); show_all_children(); + m_label.set_valign(Gtk::ALIGN_END); m_label.set_max_width_chars(0); // will constrain to given size m_label.set_ellipsize(Pango::ELLIPSIZE_MIDDLE); m_label.set_margin_start(7); m_label.set_margin_end(7); + m_img->set_vexpand(true); + if (is_extant) SetFilenameFromFile(); diff --git a/src/constants.hpp b/src/constants.hpp index 14fa076..b1ef82b 100644 --- a/src/constants.hpp +++ b/src/constants.hpp @@ -1,8 +1,9 @@ +#pragma once #include 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 AttachmentItemSize = 120; constexpr static int BaseAttachmentSizeLimit = 8 * 1024 * 1024; constexpr static int NitroClassicAttachmentSizeLimit = 50 * 1024 * 1024; constexpr static int NitroAttachmentSizeLimit = 100 * 1024 * 1024; -- cgit v1.2.3