From efc97aa2b0d7a4d63a2e6219070919559a0cf64d Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Thu, 10 Jun 2021 15:27:32 -0400 Subject: reduce db access + refactor --- windows/mainwindow.cpp | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'windows/mainwindow.cpp') diff --git a/windows/mainwindow.cpp b/windows/mainwindow.cpp index 04ae7eb..cbf91d9 100644 --- a/windows/mainwindow.cpp +++ b/windows/mainwindow.cpp @@ -199,17 +199,8 @@ void MainWindow::UpdateChannelsUpdateGuild(Snowflake id) { void MainWindow::UpdateChatWindowContents() { auto &discord = Abaddon::Get().GetDiscordClient(); - auto allmsgs = discord.GetMessagesForChannel(m_chat.GetActiveChannel()); - if (allmsgs.size() > 50) { - std::vector msgvec(allmsgs.begin(), allmsgs.end()); - std::vector cutvec(msgvec.end() - 50, msgvec.end()); - std::set msgs; - for (const auto s : cutvec) - msgs.insert(s); - m_chat.SetMessages(msgs); - } else { - m_chat.SetMessages(allmsgs); - } + auto msgs = discord.GetMessagesForChannel(m_chat.GetActiveChannel(), 50); + m_chat.SetMessages(msgs); m_members.UpdateMemberList(); } @@ -225,9 +216,9 @@ Snowflake MainWindow::GetChatActiveChannel() const { return m_chat.GetActiveChannel(); } -void MainWindow::UpdateChatNewMessage(Snowflake id) { - if (Abaddon::Get().GetDiscordClient().GetMessage(id)->ChannelID == GetChatActiveChannel()) { - m_chat.AddNewMessage(id); +void MainWindow::UpdateChatNewMessage(const Message &data) { + if (data.ChannelID == GetChatActiveChannel()) { + m_chat.AddNewMessage(data); } } @@ -241,8 +232,8 @@ void MainWindow::UpdateChatMessageUpdated(Snowflake id, Snowflake channel_id) { m_chat.UpdateMessage(id); } -void MainWindow::UpdateChatPrependHistory(const std::vector &msgs) { - m_chat.AddNewHistory(msgs); +void MainWindow::UpdateChatPrependHistory(const std::vector &msgs) { + m_chat.AddNewHistory(msgs); // given vector should be sorted ascending } void MainWindow::InsertChatInput(std::string text) { -- cgit v1.2.3