check nitro size restriction + fix replying border

This commit is contained in:
ouwou 2022-07-09 01:57:56 -04:00
parent 241d9a2140
commit 02ce353c6d
5 changed files with 52 additions and 3 deletions

View File

@ -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;
}

View File

@ -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();

View File

@ -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);

View File

@ -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();
}

View File

@ -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;