summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2021-04-14 02:11:36 -0400
committerouwou <26526779+ouwou@users.noreply.github.com>2021-04-14 02:11:36 -0400
commit9733ae54c386f347e338c7854869ba2e57b113cb (patch)
tree9954638cbd0b7172e7822b0bdf799c02eb41d0df /components
parent9a7a468607d0e289c8a42adfa13bc2e9f65e9696 (diff)
downloadabaddon-portaudio-9733ae54c386f347e338c7854869ba2e57b113cb.tar.gz
abaddon-portaudio-9733ae54c386f347e338c7854869ba2e57b113cb.zip
update rate limit indicator on failed message send
this happens when you start the client while already rate-limited
Diffstat (limited to 'components')
-rw-r--r--components/chatwindow.cpp2
-rw-r--r--components/chatwindow.hpp2
-rw-r--r--components/ratelimitindicator.cpp13
-rw-r--r--components/ratelimitindicator.hpp1
4 files changed, 16 insertions, 2 deletions
diff --git a/components/chatwindow.cpp b/components/chatwindow.cpp
index 51f5985..1a2bb48 100644
--- a/components/chatwindow.cpp
+++ b/components/chatwindow.cpp
@@ -365,7 +365,7 @@ void ChatWindow::ScrollToBottom() {
x->set_value(x->get_upper());
}
-void ChatWindow::OnMessageSendFail(const std::string &nonce) {
+void ChatWindow::OnMessageSendFail(const std::string &nonce, float retry_after) {
for (auto [id, widget] : m_id_to_widget) {
if (auto *container = dynamic_cast<ChatMessageItemContainer *>(widget); container->Nonce == nonce) {
container->SetFailed();
diff --git a/components/chatwindow.hpp b/components/chatwindow.hpp
index 078c66d..1226d7e 100644
--- a/components/chatwindow.hpp
+++ b/components/chatwindow.hpp
@@ -54,7 +54,7 @@ protected:
void ScrollToBottom();
bool m_should_scroll_to_bottom = true;
- void OnMessageSendFail(const std::string &nonce);
+ void OnMessageSendFail(const std::string &nonce, float retry_after);
Gtk::Box *m_main;
Gtk::ListBox *m_list;
diff --git a/components/ratelimitindicator.cpp b/components/ratelimitindicator.cpp
index 8f867ec..4d8afdc 100644
--- a/components/ratelimitindicator.cpp
+++ b/components/ratelimitindicator.cpp
@@ -25,6 +25,7 @@ RateLimitIndicator::RateLimitIndicator()
}
Abaddon::Get().GetDiscordClient().signal_message_create().connect(sigc::mem_fun(*this, &RateLimitIndicator::OnMessageCreate));
+ Abaddon::Get().GetDiscordClient().signal_message_send_fail().connect(sigc::mem_fun(*this, &RateLimitIndicator::OnMessageSendFail));
}
void RateLimitIndicator::SetActiveChannel(Snowflake id) {
@@ -109,3 +110,15 @@ void RateLimitIndicator::OnMessageCreate(const Message &message) {
UpdateIndicator();
}
}
+
+void RateLimitIndicator::OnMessageSendFail(const std::string &nonce, float retry_after) {
+ if (retry_after != 0) { // failed to rate limit
+ const auto msg = Abaddon::Get().GetDiscordClient().GetMessage(nonce);
+ const auto channel_id = msg->ChannelID;
+ const auto channel = *Abaddon::Get().GetDiscordClient().GetChannel(channel_id);
+ const auto rate_limit = *channel.RateLimitPerUser;
+ const auto sent_time = std::chrono::steady_clock::now() - std::chrono::duration<int>(rate_limit - std::lroundf(retry_after + 0.5f)); // + 0.5 will ceil it
+ m_times[channel_id] = sent_time;
+ UpdateIndicator();
+ }
+}
diff --git a/components/ratelimitindicator.hpp b/components/ratelimitindicator.hpp
index 5cbba4d..95dddb6 100644
--- a/components/ratelimitindicator.hpp
+++ b/components/ratelimitindicator.hpp
@@ -17,6 +17,7 @@ private:
int GetRateLimit() const;
bool UpdateIndicator();
void OnMessageCreate(const Message &message);
+ void OnMessageSendFail(const std::string &nonce, float rate_limit);
Gtk::Image m_img;
Gtk::Label m_label;