diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2020-08-21 00:42:46 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2020-08-21 00:42:46 -0400 |
commit | 6f11aa4dae4c7334b150752f5cf8d270ce746d9c (patch) | |
tree | 45d7ed1776b9294ce5a0f89f872aff5e21a1f425 /components/chatwindow.cpp | |
parent | a201d5905ad9188e890eeb0cc0aee8d4fb9dcf3c (diff) | |
download | abaddon-portaudio-6f11aa4dae4c7334b150752f5cf8d270ce746d9c.tar.gz abaddon-portaudio-6f11aa4dae4c7334b150752f5cf8d270ce746d9c.zip |
shitty MESSAGE_CREATE handling
Diffstat (limited to 'components/chatwindow.cpp')
-rw-r--r-- | components/chatwindow.cpp | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/components/chatwindow.cpp b/components/chatwindow.cpp index b5fc94d..25f6831 100644 --- a/components/chatwindow.cpp +++ b/components/chatwindow.cpp @@ -1,8 +1,10 @@ #include "chatwindow.hpp" +#include "../abaddon.hpp" #include <map> ChatWindow::ChatWindow() { - m_update_dispatcher.connect(sigc::mem_fun(*this, &ChatWindow::SetMessagesInternal)); + m_message_set_dispatch.connect(sigc::mem_fun(*this, &ChatWindow::SetMessagesInternal)); + m_new_message_dispatch.connect(sigc::mem_fun(*this, &ChatWindow::AddNewMessageInternal)); m_main = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL)); m_listbox = Gtk::manage(new Gtk::ListBox); @@ -11,6 +13,8 @@ ChatWindow::ChatWindow() { m_input = Gtk::manage(new Gtk::TextView); m_entry_scroll = Gtk::manage(new Gtk::ScrolledWindow); + m_input->signal_key_press_event().connect(sigc::mem_fun(*this, &ChatWindow::on_key_press_event), false); + m_main->set_hexpand(true); m_main->set_vexpand(true); m_main->show(); @@ -51,6 +55,10 @@ ChatWindow::ChatWindow() { m_main->add(*m_entry_scroll); } +void ChatWindow::SetAbaddon(Abaddon* ptr) { + m_abaddon = ptr; +} + Gtk::Widget *ChatWindow::GetRoot() const { return m_main; } @@ -120,10 +128,33 @@ Gtk::ListBoxRow *ChatWindow::CreateChatEntryComponent(const MessageData *data) { return nullptr; } +bool ChatWindow::on_key_press_event(GdkEventKey *e) { + if (e->keyval == GDK_KEY_Return) { + auto buffer = m_input->get_buffer(); + + if (e->state & GDK_SHIFT_MASK) + return false; + + auto text = buffer->get_text(); + + buffer->set_text(""); + + return true; + } + + return false; +} + void ChatWindow::SetMessages(std::unordered_set<const MessageData *> msgs) { std::scoped_lock<std::mutex> guard(m_update_mutex); - m_update_queue.push(msgs); - m_update_dispatcher.emit(); + m_message_set_queue.push(msgs); + m_message_set_dispatch.emit(); +} + +void ChatWindow::AddNewMessage(Snowflake id) { + std::scoped_lock<std::mutex> guard(m_update_mutex); + m_new_message_queue.push(id); + m_new_message_dispatch.emit(); } void ChatWindow::ScrollToBottom() { @@ -131,6 +162,20 @@ void ChatWindow::ScrollToBottom() { x->set_value(x->get_upper()); } +void ChatWindow::AddNewMessageInternal() { + Snowflake id; + { + std::scoped_lock<std::mutex> guard(m_update_mutex); + id = m_new_message_queue.front(); + m_new_message_queue.pop(); + } + + auto data = m_abaddon->GetDiscordClient().GetMessage(id); + auto *row = CreateChatEntryComponent(data); + if (row != nullptr) + m_listbox->add(*row); +} + void ChatWindow::SetMessagesInternal() { auto children = m_listbox->get_children(); auto it = children.begin(); @@ -143,7 +188,7 @@ void ChatWindow::SetMessagesInternal() { std::unordered_set<const MessageData *> *msgs; { std::scoped_lock<std::mutex> guard(m_update_mutex); - msgs = &m_update_queue.front(); + msgs = &m_message_set_queue.front(); } // sort @@ -159,6 +204,6 @@ void ChatWindow::SetMessagesInternal() { { std::scoped_lock<std::mutex> guard(m_update_mutex); - m_update_queue.pop(); + m_message_set_queue.pop(); } } |