add menus to dm channels + close/leave dm

This commit is contained in:
ouwou 2021-02-18 18:37:25 -05:00
parent 901028cec9
commit c5bc3455b1
4 changed files with 31 additions and 0 deletions

View File

@ -54,6 +54,26 @@ ChannelListRowDMChannel::ChannelListRowDMChannel(const ChannelData *data) {
m_lbl = Gtk::manage(new Gtk::TextView);
MakeReadOnly(m_lbl);
AddWidgetMenuHandler(m_ev, m_menu);
AddWidgetMenuHandler(m_lbl, m_menu);
m_menu_copy_id = Gtk::manage(new Gtk::MenuItem("_Copy ID", true));
m_menu_copy_id->signal_activate().connect([this] {
Gtk::Clipboard::get()->set_text(std::to_string(ID));
});
if (data->Type == ChannelType::GROUP_DM)
m_menu_close = Gtk::manage(new Gtk::MenuItem("_Leave DM", true));
else
m_menu_close = Gtk::manage(new Gtk::MenuItem("_Close DM", true));
m_menu_close->signal_activate().connect([this] {
Abaddon::Get().GetDiscordClient().CloseDM(ID);
});
m_menu.append(*m_menu_copy_id);
m_menu.append(*m_menu_close);
m_menu.show_all();
get_style_context()->add_class("channel-row");
m_lbl->get_style_context()->add_class("channel-row-label");

View File

@ -44,6 +44,10 @@ protected:
StatusIndicator *m_status = nullptr;
Gtk::TextView *m_lbl;
Gtk::Image *m_icon = nullptr;
Gtk::Menu m_menu;
Gtk::MenuItem *m_menu_close; // leave if group
Gtk::MenuItem *m_menu_copy_id;
};
class ChannelListRowGuild : public ChannelListRow {

View File

@ -436,6 +436,12 @@ void DiscordClient::CreateDM(Snowflake user_id, sigc::slot<void(bool success, Sn
});
}
void DiscordClient::CloseDM(Snowflake channel_id) {
m_http.MakeDELETE("/channels/" + std::to_string(channel_id), [this](const http::response &response) {
CheckCode(response);
});
}
std::optional<Snowflake> DiscordClient::FindDM(Snowflake user_id) {
const auto &channels = m_store.GetChannels();
for (const auto &id : channels) {

View File

@ -109,6 +109,7 @@ public:
void UpdateStatus(PresenceStatus status, bool is_afk, const ActivityData &obj);
void CreateDM(Snowflake user_id);
void CreateDM(Snowflake user_id, sigc::slot<void(bool success, Snowflake channel_id)> callback);
void CloseDM(Snowflake channel_id);
std::optional<Snowflake> FindDM(Snowflake user_id); // wont find group dms
void AddReaction(Snowflake id, Glib::ustring param);
void RemoveReaction(Snowflake id, Glib::ustring param);