mirror of
https://github.com/celisej567/abaddon.git
synced 2026-09-13 20:18:50 +03:00
add option to remove user from group dm in menu
also fix a crash when opening empty group dms
This commit is contained in:
27
abaddon.cpp
27
abaddon.cpp
@@ -86,6 +86,7 @@ int Abaddon::StartGTK() {
|
||||
m_user_menu_open_dm = Gtk::manage(new Gtk::MenuItem("Open 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"));
|
||||
m_user_menu_roles_submenu = Gtk::manage(new Gtk::Menu);
|
||||
m_user_menu_roles->set_submenu(*m_user_menu_roles_submenu);
|
||||
m_user_menu_insert_mention->signal_activate().connect(sigc::mem_fun(*this, &Abaddon::on_user_menu_insert_mention));
|
||||
@@ -93,17 +94,27 @@ int Abaddon::StartGTK() {
|
||||
m_user_menu_kick->signal_activate().connect(sigc::mem_fun(*this, &Abaddon::on_user_menu_kick));
|
||||
m_user_menu_copy_id->signal_activate().connect(sigc::mem_fun(*this, &Abaddon::on_user_menu_copy_id));
|
||||
m_user_menu_open_dm->signal_activate().connect(sigc::mem_fun(*this, &Abaddon::on_user_menu_open_dm));
|
||||
m_user_menu_remove_recipient->signal_activate().connect(sigc::mem_fun(*this, &Abaddon::on_user_menu_remove_recipient));
|
||||
m_user_menu_info->signal_activate().connect([this]() {
|
||||
auto *window = new ProfileWindow(m_shown_user_menu_id);
|
||||
window->show();
|
||||
});
|
||||
|
||||
m_user_menu_remove_recipient->override_color(Gdk::RGBA("#BE3C3D"));
|
||||
|
||||
m_user_menu->append(*m_user_menu_info);
|
||||
m_user_menu->append(*m_user_menu_insert_mention);
|
||||
m_user_menu->append(*Gtk::manage(new Gtk::SeparatorMenuItem));
|
||||
m_user_menu->append(*m_user_menu_ban);
|
||||
m_user_menu->append(*m_user_menu_kick);
|
||||
m_user_menu->append(*Gtk::manage(new Gtk::SeparatorMenuItem));
|
||||
m_user_menu->append(*m_user_menu_open_dm);
|
||||
m_user_menu->append(*m_user_menu_roles);
|
||||
m_user_menu->append(*Gtk::manage(new Gtk::SeparatorMenuItem));
|
||||
m_user_menu->append(*m_user_menu_remove_recipient);
|
||||
m_user_menu->append(*Gtk::manage(new Gtk::SeparatorMenuItem));
|
||||
m_user_menu->append(*m_user_menu_copy_id);
|
||||
|
||||
m_user_menu->show_all();
|
||||
|
||||
m_main_window->signal_action_connect().connect(sigc::mem_fun(*this, &Abaddon::ActionConnect));
|
||||
@@ -300,6 +311,14 @@ void Abaddon::ShowUserMenu(const GdkEvent *event, Snowflake id, Snowflake guild_
|
||||
m_user_menu_open_dm->set_visible(true);
|
||||
}
|
||||
|
||||
m_user_menu_remove_recipient->hide();
|
||||
if (me != id) {
|
||||
const auto channel_id = m_main_window->GetChatActiveChannel();
|
||||
const auto channel = m_discord.GetChannel(channel_id);
|
||||
if (channel.has_value() && channel->Type == ChannelType::GROUP_DM && id != *channel->OwnerID)
|
||||
m_user_menu_remove_recipient->show();
|
||||
}
|
||||
|
||||
m_user_menu->popup_at_pointer(event);
|
||||
}
|
||||
|
||||
@@ -335,6 +354,10 @@ void Abaddon::on_user_menu_open_dm() {
|
||||
});
|
||||
}
|
||||
|
||||
void Abaddon::on_user_menu_remove_recipient() {
|
||||
m_discord.RemoveGroupDMRecipient(m_main_window->GetChatActiveChannel(), m_shown_user_menu_id);
|
||||
}
|
||||
|
||||
void Abaddon::ActionConnect() {
|
||||
if (!m_discord.IsStarted())
|
||||
StartDiscord();
|
||||
@@ -386,8 +409,10 @@ void Abaddon::ActionChannelOpened(Snowflake id) {
|
||||
const auto recipients = channel->GetDMRecipients();
|
||||
if (recipients.size() > 1)
|
||||
display = std::to_string(recipients.size()) + " users";
|
||||
else
|
||||
else if (recipients.size() == 1)
|
||||
display = recipients[0].Username;
|
||||
else
|
||||
display = "Empty group";
|
||||
m_main_window->set_title(std::string(APP_TITLE) + " - " + display);
|
||||
}
|
||||
m_main_window->UpdateChatActiveChannel(id);
|
||||
|
||||
@@ -90,6 +90,7 @@ protected:
|
||||
Gtk::MenuItem *m_user_menu_copy_id;
|
||||
Gtk::MenuItem *m_user_menu_open_dm;
|
||||
Gtk::MenuItem *m_user_menu_roles;
|
||||
Gtk::MenuItem *m_user_menu_remove_recipient;
|
||||
Gtk::Menu *m_user_menu_roles_submenu;
|
||||
|
||||
void on_user_menu_insert_mention();
|
||||
@@ -97,6 +98,7 @@ protected:
|
||||
void on_user_menu_kick();
|
||||
void on_user_menu_copy_id();
|
||||
void on_user_menu_open_dm();
|
||||
void on_user_menu_remove_recipient();
|
||||
|
||||
private:
|
||||
SettingsManager m_settings;
|
||||
|
||||
@@ -522,6 +522,12 @@ void DiscordClient::DeleteInvite(const std::string &code, sigc::slot<void(bool s
|
||||
});
|
||||
}
|
||||
|
||||
void DiscordClient::RemoveGroupDMRecipient(Snowflake channel_id, Snowflake user_id) {
|
||||
m_http.MakeDELETE("/channels/" + std::to_string(channel_id) + "/recipients/" + std::to_string(user_id), [this](const http::response_type &response) {
|
||||
CheckCode(response);
|
||||
});
|
||||
}
|
||||
|
||||
std::vector<BanData> DiscordClient::GetBansInGuild(Snowflake guild_id) {
|
||||
return m_store.GetBans(guild_id);
|
||||
}
|
||||
|
||||
@@ -120,6 +120,7 @@ public:
|
||||
void UnbanUser(Snowflake guild_id, Snowflake user_id, sigc::slot<void(bool success)> callback);
|
||||
void DeleteInvite(const std::string &code);
|
||||
void DeleteInvite(const std::string &code, sigc::slot<void(bool success)> callback);
|
||||
void RemoveGroupDMRecipient(Snowflake channel_id, Snowflake user_id);
|
||||
|
||||
// FetchGuildBans fetches all bans+reasons via api, this func fetches stored bans (so usually just GUILD_BAN_ADD data)
|
||||
std::vector<BanData> GetBansInGuild(Snowflake guild_id);
|
||||
|
||||
Reference in New Issue
Block a user