diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2023-07-17 21:37:24 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2023-07-17 21:37:24 -0400 |
commit | d04e101800c451c4963a530b7cf745666105cec4 (patch) | |
tree | d73fdf97b00d8f40d8888de762574a424df435eb /src/components/chatlist.cpp | |
parent | 0f3814586e3949d1a7fc15bfc2aff2b99d4975a8 (diff) | |
parent | 857e94af3817932b78963873fb5621ae3c4596f7 (diff) | |
download | abaddon-portaudio-d04e101800c451c4963a530b7cf745666105cec4.tar.gz abaddon-portaudio-d04e101800c451c4963a530b7cf745666105cec4.zip |
Merge branch 'master' into rnnoise
Diffstat (limited to 'src/components/chatlist.cpp')
-rw-r--r-- | src/components/chatlist.cpp | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/components/chatlist.cpp b/src/components/chatlist.cpp index 93fb46f..ba18c0a 100644 --- a/src/components/chatlist.cpp +++ b/src/components/chatlist.cpp @@ -133,10 +133,9 @@ void ChatList::ProcessNewMessage(const Message &data, bool prepend) { m_menu_delete_message->set_sensitive(false); m_menu_edit_message->set_sensitive(false); } else { - const bool can_edit = client.GetUserData().ID == data->Author.ID; - const bool can_delete = can_edit || has_manage; + const bool can_delete = (client.GetUserData().ID == data->Author.ID) || has_manage; m_menu_delete_message->set_sensitive(can_delete); - m_menu_edit_message->set_sensitive(can_edit); + m_menu_edit_message->set_sensitive(data->IsEditable()); } m_menu.popup_at_pointer(reinterpret_cast<GdkEvent *>(ev)); @@ -253,6 +252,25 @@ void ChatList::ActuallyRemoveMessage(Snowflake id) { RemoveMessageAndHeader(it->second); } +std::optional<Snowflake> ChatList::GetLastSentEditableMessage() { + const auto &discord = Abaddon::Get().GetDiscordClient(); + const auto self_id = discord.GetUserData().ID; + + std::map<Snowflake, Gtk::Widget *> ordered(m_id_to_widget.begin(), m_id_to_widget.end()); + + for (auto it = ordered.crbegin(); it != ordered.crend(); it++) { + const auto *widget = dynamic_cast<ChatMessageItemContainer *>(it->second); + if (widget == nullptr) continue; + const auto msg = discord.GetMessage(widget->ID); + if (!msg.has_value()) continue; + if (msg->Author.ID != self_id) continue; + if (!msg->IsEditable()) continue; + return msg->ID; + } + + return std::nullopt; +} + void ChatList::SetupMenu() { m_menu_copy_id = Gtk::manage(new Gtk::MenuItem("Copy ID")); m_menu_copy_id->signal_activate().connect([this] { |