diff --git a/src/abaddon.cpp b/src/abaddon.cpp index 14e43af..787265b 100644 --- a/src/abaddon.cpp +++ b/src/abaddon.cpp @@ -389,6 +389,7 @@ void Abaddon::ShowUserMenu(const GdkEvent *event, Snowflake id, Snowflake guild_ for (const auto child : m_user_menu_roles_submenu->get_children()) delete child; + if (guild.has_value() && user.has_value()) { const auto roles = user->GetSortedRoles(); m_user_menu_roles->set_visible(!roles.empty()); @@ -411,7 +412,7 @@ void Abaddon::ShowUserMenu(const GdkEvent *event, Snowflake id, Snowflake guild_ if (me == id) { m_user_menu_ban->set_visible(false); m_user_menu_kick->set_visible(false); - m_user_menu_open_dm->set_visible(false); + m_user_menu_open_dm->set_sensitive(false); } else { const bool has_kick = m_discord.HasGuildPermission(me, guild_id, Permission::KICK_MEMBERS); const bool has_ban = m_discord.HasGuildPermission(me, guild_id, Permission::BAN_MEMBERS); @@ -419,7 +420,7 @@ void Abaddon::ShowUserMenu(const GdkEvent *event, Snowflake id, Snowflake guild_ m_user_menu_kick->set_visible(has_kick && can_manage); m_user_menu_ban->set_visible(has_ban && can_manage); - m_user_menu_open_dm->set_visible(true); + m_user_menu_open_dm->set_sensitive(m_discord.FindDM(id).has_value()); } m_user_menu_remove_recipient->hide(); @@ -467,7 +468,7 @@ void Abaddon::SetupUserMenu() { m_user_menu_ban = Gtk::manage(new Gtk::MenuItem("Ban")); m_user_menu_kick = Gtk::manage(new Gtk::MenuItem("Kick")); m_user_menu_copy_id = Gtk::manage(new Gtk::MenuItem("Copy ID")); - m_user_menu_open_dm = Gtk::manage(new Gtk::MenuItem("Open DM")); + m_user_menu_open_dm = Gtk::manage(new Gtk::MenuItem("Go to DM")); m_user_menu_roles = Gtk::manage(new Gtk::MenuItem("Roles")); m_user_menu_info = Gtk::manage(new Gtk::MenuItem("View Profile")); m_user_menu_remove_recipient = Gtk::manage(new Gtk::MenuItem("Remove From Group")); @@ -578,18 +579,9 @@ void Abaddon::on_user_menu_copy_id() { void Abaddon::on_user_menu_open_dm() { const auto existing = m_discord.FindDM(m_shown_user_menu_id); - if (existing.has_value()) + if (existing.has_value()) { ActionChannelOpened(*existing); - else - m_discord.CreateDM(m_shown_user_menu_id, [this](DiscordError code, Snowflake channel_id) { - if (code == DiscordError::NONE) { - // give the gateway a little window to send CHANNEL_CREATE - auto cb = [this, channel_id] { - ActionChannelOpened(channel_id); - }; - Glib::signal_timeout().connect_once(sigc::track_obj(cb, *this), 200); - } - }); + } } void Abaddon::on_user_menu_remove_recipient() { diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp index d94f3df..bb29d77 100644 --- a/src/discord/discord.cpp +++ b/src/discord/discord.cpp @@ -552,19 +552,6 @@ void DiscordClient::UpdateStatus(PresenceStatus status, bool is_afk, const Activ m_signal_presence_update.emit(GetUserData(), status); } -void DiscordClient::CreateDM(Snowflake user_id, const sigc::slot &callback) { - CreateDMObject obj; - obj.Recipients.push_back(user_id); - m_http.MakePOST("/users/@me/channels", nlohmann::json(obj).dump(), [callback](const http::response &response) { - if (!CheckCode(response)) { - callback(DiscordError::NONE, Snowflake::Invalid); - return; - } - auto channel = nlohmann::json::parse(response.text).get(); - callback(GetCodeFromResponse(response), channel.ID); - }); -} - void DiscordClient::CloseDM(Snowflake channel_id) { m_http.MakeDELETE("/channels/" + std::to_string(channel_id), [](const http::response &response) { CheckCode(response); diff --git a/src/discord/discord.hpp b/src/discord/discord.hpp index 6310296..6bcd2d5 100644 --- a/src/discord/discord.hpp +++ b/src/discord/discord.hpp @@ -116,7 +116,6 @@ public: void BanUser(Snowflake user_id, Snowflake guild_id); // todo: reason, delete messages void UpdateStatus(PresenceStatus status, bool is_afk); void UpdateStatus(PresenceStatus status, bool is_afk, const ActivityData &obj); - void CreateDM(Snowflake user_id, const sigc::slot &callback); void CloseDM(Snowflake channel_id); std::optional FindDM(Snowflake user_id); // wont find group dms void AddReaction(Snowflake id, Glib::ustring param);