From 36f2ec0996d937400e2fce028c3da729ad951f31 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Mon, 28 Aug 2023 21:47:04 -0400 Subject: fix webhook messages not using right username + avatar (fixes #209) --- src/components/chatlist.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/components/chatlist.cpp') diff --git a/src/components/chatlist.cpp b/src/components/chatlist.cpp index ba18c0a..4dde8a3 100644 --- a/src/components/chatlist.cpp +++ b/src/components/chatlist.cpp @@ -67,8 +67,22 @@ void ChatList::ProcessNewMessage(const Message &data, bool prepend) { if (last_row != nullptr) { const uint64_t diff = std::max(data.ID, last_row->NewestID) - std::min(data.ID, last_row->NewestID); - if (last_row->UserID == data.Author.ID && (prepend || (diff < SnowflakeSplitDifference * Snowflake::SecondsInterval))) + if (last_row->UserID == data.Author.ID && (prepend || (diff < SnowflakeSplitDifference * Snowflake::SecondsInterval))) { should_attach = true; + } + // Separate webhooks if the usernames or avatar URLs are different + if (data.IsWebhook() && last_row->UserID == data.Author.ID) { + const auto last_message = discord.GetMessage(last_row->NewestID); + if (last_message.has_value() && last_message->IsWebhook()) { + const auto last_webhook_data = last_message->GetWebhookData(); + const auto next_webhook_data = data.GetWebhookData(); + if (last_webhook_data.has_value() && next_webhook_data.has_value()) { + if (last_webhook_data->Username != next_webhook_data->Username || last_webhook_data->Avatar != next_webhook_data->Avatar) { + should_attach = false; + } + } + } + } } } -- cgit v1.2.3