summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--components/chatmessage.cpp4
-rw-r--r--components/chatmessage.hpp1
-rw-r--r--components/chatwindow.cpp4
-rw-r--r--discord/snowflake.cpp2
-rw-r--r--discord/snowflake.hpp3
5 files changed, 11 insertions, 3 deletions
diff --git a/components/chatmessage.cpp b/components/chatmessage.cpp
index 8608fdc..97d6d4a 100644
--- a/components/chatmessage.cpp
+++ b/components/chatmessage.cpp
@@ -1210,4 +1210,8 @@ void ChatMessageHeader::AddContent(Gtk::Widget *widget, bool prepend) {
m_content_box->add(*widget);
if (prepend)
m_content_box->reorder_child(*widget, 1);
+ if (auto *x = dynamic_cast<ChatMessageItemContainer *>(widget)) {
+ if (x->ID > NewestID)
+ NewestID = x->ID;
+ }
}
diff --git a/components/chatmessage.hpp b/components/chatmessage.hpp
index 1e92882..6074b20 100644
--- a/components/chatmessage.hpp
+++ b/components/chatmessage.hpp
@@ -109,6 +109,7 @@ class ChatMessageHeader : public Gtk::ListBoxRow {
public:
Snowflake UserID;
Snowflake ChannelID;
+ Snowflake NewestID = 0;
ChatMessageHeader(const Message *data);
void AddContent(Gtk::Widget *widget, bool prepend);
diff --git a/components/chatwindow.cpp b/components/chatwindow.cpp
index 28c9820..8235a21 100644
--- a/components/chatwindow.cpp
+++ b/components/chatwindow.cpp
@@ -4,6 +4,8 @@
#include "chatinputindicator.hpp"
#include "chatinput.hpp"
+constexpr static uint64_t SnowflakeSplitDifference = 600;
+
ChatWindow::ChatWindow() {
Abaddon::Get().GetDiscordClient().signal_message_send_fail().connect(sigc::mem_fun(*this, &ChatWindow::OnMessageSendFail));
@@ -238,7 +240,7 @@ void ChatWindow::ProcessNewMessage(Snowflake id, bool prepend) {
last_row = dynamic_cast<ChatMessageHeader *>(m_list->get_row_at_index(m_num_rows - 1));
if (last_row != nullptr)
- if (last_row->UserID == data->Author.ID)
+ if (last_row->UserID == data->Author.ID && (prepend || (id - last_row->NewestID < SnowflakeSplitDifference * Snowflake::SecondsInterval)))
should_attach = true;
}
diff --git a/discord/snowflake.cpp b/discord/snowflake.cpp
index 595f87c..18c7805 100644
--- a/discord/snowflake.cpp
+++ b/discord/snowflake.cpp
@@ -41,7 +41,7 @@ bool Snowflake::IsValid() const {
}
std::string Snowflake::GetLocalTimestamp() const {
- const time_t secs_since_epoch = (m_num / 4194304000) + 1420070400;
+ const time_t secs_since_epoch = (m_num / SecondsInterval) + DiscordEpochSeconds;
const std::tm tm = *localtime(&secs_since_epoch);
std::stringstream ss;
const static std::locale locale("");
diff --git a/discord/snowflake.hpp b/discord/snowflake.hpp
index c6770a1..4263bab 100644
--- a/discord/snowflake.hpp
+++ b/discord/snowflake.hpp
@@ -26,7 +26,8 @@ struct Snowflake {
return m_num;
}
- const static int Invalid = -1;
+ const static uint64_t Invalid = -1ULL; // makes sense to me
+ const static uint64_t SecondsInterval = 4194304000ULL; // the "difference" between two snowflakes one second apart
friend void from_json(const nlohmann::json &j, Snowflake &s);
friend void to_json(nlohmann::json &j, const Snowflake &s);