forked from OpenGamers/abaddon
reduce concurrent requests in guild settings + profile
disable gtk's treeview search in bans+invites
This commit is contained in:
parent
72d771d88b
commit
65943b4bd7
8
components/inotifyswitched.hpp
Normal file
8
components/inotifyswitched.hpp
Normal file
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
// for things that are used in stackswitchers to be able to be told when they're switched to
|
||||
|
||||
class INotifySwitched {
|
||||
public:
|
||||
virtual void on_switched_to() {};
|
||||
};
|
@ -9,15 +9,20 @@ GuildSettingsAuditLogPane::GuildSettingsAuditLogPane(Snowflake id)
|
||||
set_hexpand(true);
|
||||
set_vexpand(true);
|
||||
|
||||
m_list.set_selection_mode(Gtk::SELECTION_NONE);
|
||||
m_list.show();
|
||||
add(m_list);
|
||||
}
|
||||
|
||||
void GuildSettingsAuditLogPane::on_switched_to() {
|
||||
if (m_requested) return;
|
||||
m_requested = true;
|
||||
|
||||
auto &discord = Abaddon::Get().GetDiscordClient();
|
||||
const auto self_id = discord.GetUserData().ID;
|
||||
|
||||
if (discord.HasGuildPermission(self_id, GuildID, Permission::VIEW_AUDIT_LOG))
|
||||
discord.FetchAuditLog(GuildID, sigc::mem_fun(*this, &GuildSettingsAuditLogPane::OnAuditLogFetch));
|
||||
|
||||
m_list.set_selection_mode(Gtk::SELECTION_NONE);
|
||||
m_list.show();
|
||||
add(m_list);
|
||||
}
|
||||
|
||||
void GuildSettingsAuditLogPane::OnAuditLogFetch(const AuditLogData &data) {
|
||||
|
@ -1,12 +1,17 @@
|
||||
#pragma once
|
||||
#include <gtkmm.h>
|
||||
#include "../../components//inotifyswitched.hpp"
|
||||
#include "../../discord/objects.hpp"
|
||||
|
||||
class GuildSettingsAuditLogPane : public Gtk::ScrolledWindow {
|
||||
class GuildSettingsAuditLogPane : public Gtk::ScrolledWindow, public INotifySwitched {
|
||||
public:
|
||||
GuildSettingsAuditLogPane(Snowflake id);
|
||||
|
||||
private:
|
||||
void on_switched_to() override;
|
||||
|
||||
bool m_requested = false;
|
||||
|
||||
Gtk::ListBox m_list;
|
||||
|
||||
void OnAuditLogFetch(const AuditLogData &data);
|
||||
|
@ -22,9 +22,7 @@ GuildSettingsBansPane::GuildSettingsBansPane(Snowflake id)
|
||||
const auto self_id = discord.GetUserData().ID;
|
||||
const auto can_ban = discord.HasGuildPermission(self_id, GuildID, Permission::BAN_MEMBERS);
|
||||
|
||||
if (can_ban) {
|
||||
discord.FetchGuildBans(id, sigc::mem_fun(*this, &GuildSettingsBansPane::OnGuildBansFetch));
|
||||
} else {
|
||||
if (!can_ban) {
|
||||
for (const auto &ban : discord.GetBansInGuild(id))
|
||||
OnGuildBanFetch(ban);
|
||||
|
||||
@ -50,11 +48,25 @@ GuildSettingsBansPane::GuildSettingsBansPane(Snowflake id)
|
||||
add(m_scroll);
|
||||
show_all_children();
|
||||
|
||||
m_view.set_enable_search(false);
|
||||
m_view.set_model(m_model);
|
||||
m_view.append_column("User", m_columns.m_col_user);
|
||||
m_view.append_column("Reason", m_columns.m_col_reason);
|
||||
}
|
||||
|
||||
void GuildSettingsBansPane::on_switched_to() {
|
||||
if (m_requested) return;
|
||||
m_requested = true;
|
||||
|
||||
auto &discord = Abaddon::Get().GetDiscordClient();
|
||||
|
||||
const auto self_id = discord.GetUserData().ID;
|
||||
const auto can_ban = discord.HasGuildPermission(self_id, GuildID, Permission::BAN_MEMBERS);
|
||||
|
||||
if (can_ban)
|
||||
discord.FetchGuildBans(GuildID, sigc::mem_fun(*this, &GuildSettingsBansPane::OnGuildBansFetch));
|
||||
}
|
||||
|
||||
void GuildSettingsBansPane::OnGuildBanFetch(const BanData &ban) {
|
||||
const auto user = Abaddon::Get().GetDiscordClient().GetUser(ban.User.ID);
|
||||
auto &row = *m_model->append();
|
||||
|
@ -1,13 +1,18 @@
|
||||
#pragma once
|
||||
#include <gtkmm.h>
|
||||
#include "../../components/inotifyswitched.hpp"
|
||||
#include "../../discord/snowflake.hpp"
|
||||
#include "../../discord/ban.hpp"
|
||||
|
||||
class GuildSettingsBansPane : public Gtk::Box {
|
||||
class GuildSettingsBansPane : public Gtk::Box, public INotifySwitched {
|
||||
public:
|
||||
GuildSettingsBansPane(Snowflake id);
|
||||
|
||||
private:
|
||||
void on_switched_to() override;
|
||||
|
||||
bool m_requested = false;
|
||||
|
||||
void OnGuildBanFetch(const BanData &ban);
|
||||
void OnGuildBansFetch(const std::vector<BanData> &bans);
|
||||
void OnMenuUnban();
|
||||
|
@ -16,10 +16,6 @@ GuildSettingsInvitesPane::GuildSettingsInvitesPane(Snowflake id)
|
||||
m_menu.show_all();
|
||||
|
||||
auto &discord = Abaddon::Get().GetDiscordClient();
|
||||
const auto self_id = discord.GetUserData().ID;
|
||||
|
||||
if (discord.HasGuildPermission(self_id, GuildID, Permission::MANAGE_GUILD))
|
||||
discord.FetchGuildInvites(GuildID, sigc::mem_fun(*this, &GuildSettingsInvitesPane::OnInvitesFetch));
|
||||
|
||||
discord.signal_invite_create().connect(sigc::mem_fun(*this, &GuildSettingsInvitesPane::OnInviteCreate));
|
||||
discord.signal_invite_delete().connect(sigc::mem_fun(*this, &GuildSettingsInvitesPane::OnInviteDelete));
|
||||
@ -27,6 +23,7 @@ GuildSettingsInvitesPane::GuildSettingsInvitesPane(Snowflake id)
|
||||
m_view.show();
|
||||
add(m_view);
|
||||
|
||||
m_view.set_enable_search(false);
|
||||
m_view.set_model(m_model);
|
||||
m_view.append_column("Code", m_columns.m_col_code);
|
||||
m_view.append_column("Expires", m_columns.m_col_expires);
|
||||
@ -39,6 +36,17 @@ GuildSettingsInvitesPane::GuildSettingsInvitesPane(Snowflake id)
|
||||
column->set_resizable(true);
|
||||
}
|
||||
|
||||
void GuildSettingsInvitesPane::on_switched_to() {
|
||||
if (m_requested) return;
|
||||
m_requested = true;
|
||||
|
||||
auto &discord = Abaddon::Get().GetDiscordClient();
|
||||
const auto self_id = discord.GetUserData().ID;
|
||||
|
||||
if (discord.HasGuildPermission(self_id, GuildID, Permission::MANAGE_GUILD))
|
||||
discord.FetchGuildInvites(GuildID, sigc::mem_fun(*this, &GuildSettingsInvitesPane::OnInvitesFetch));
|
||||
}
|
||||
|
||||
void GuildSettingsInvitesPane::AppendInvite(const InviteData &invite) {
|
||||
auto &discord = Abaddon::Get().GetDiscordClient();
|
||||
auto &row = *m_model->append();
|
||||
|
@ -1,12 +1,17 @@
|
||||
#pragma once
|
||||
#include <gtkmm.h>
|
||||
#include "../../components/inotifyswitched.hpp"
|
||||
#include "../../discord/objects.hpp"
|
||||
|
||||
class GuildSettingsInvitesPane : public Gtk::ScrolledWindow {
|
||||
class GuildSettingsInvitesPane : public Gtk::ScrolledWindow, public INotifySwitched {
|
||||
public:
|
||||
GuildSettingsInvitesPane(Snowflake id);
|
||||
|
||||
private:
|
||||
void on_switched_to() override;
|
||||
|
||||
bool m_requested = false;
|
||||
|
||||
void AppendInvite(const InviteData &invite);
|
||||
void OnInviteFetch(const std::optional<InviteData> &invite);
|
||||
void OnInvitesFetch(const std::vector<InviteData> &invites);
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "guildsettingswindow.hpp"
|
||||
#include "../abaddon.hpp"
|
||||
#include "../components/inotifyswitched.hpp"
|
||||
|
||||
GuildSettingsWindow::GuildSettingsWindow(Snowflake id)
|
||||
: m_main(Gtk::ORIENTATION_VERTICAL)
|
||||
@ -40,6 +41,11 @@ GuildSettingsWindow::GuildSettingsWindow(Snowflake id)
|
||||
m_switcher.set_margin_top(10);
|
||||
m_switcher.show();
|
||||
|
||||
m_stack.property_visible_child().signal_changed().connect([this]() {
|
||||
if (auto *w = dynamic_cast<INotifySwitched *>(m_stack.property_visible_child().get_value()))
|
||||
w->on_switched_to();
|
||||
});
|
||||
|
||||
m_pane_info.show();
|
||||
m_pane_members.show();
|
||||
m_pane_roles.show();
|
||||
|
@ -40,7 +40,7 @@ MutualFriendsPane::MutualFriendsPane(Snowflake id)
|
||||
show_all_children();
|
||||
}
|
||||
|
||||
void MutualFriendsPane::SetMutualFriends(const std::vector<UserData> &users) {
|
||||
void MutualFriendsPane::OnFetchRelationships(const std::vector<UserData> &users) {
|
||||
for (auto child : m_list.get_children())
|
||||
delete child;
|
||||
|
||||
@ -50,3 +50,10 @@ void MutualFriendsPane::SetMutualFriends(const std::vector<UserData> &users) {
|
||||
m_list.add(*item);
|
||||
}
|
||||
}
|
||||
|
||||
void MutualFriendsPane::on_switched_to() {
|
||||
if (m_requested) return;
|
||||
m_requested = true;
|
||||
|
||||
Abaddon::Get().GetDiscordClient().FetchUserRelationships(UserID, sigc::mem_fun(*this, &MutualFriendsPane::OnFetchRelationships));
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include <gtkmm.h>
|
||||
#include "../../components/inotifyswitched.hpp"
|
||||
#include "../../discord/objects.hpp"
|
||||
|
||||
class MutualFriendItem : public Gtk::Box {
|
||||
@ -11,14 +12,18 @@ private:
|
||||
Gtk::Label m_name;
|
||||
};
|
||||
|
||||
class MutualFriendsPane : public Gtk::ScrolledWindow {
|
||||
class MutualFriendsPane : public Gtk::ScrolledWindow, public INotifySwitched {
|
||||
public:
|
||||
MutualFriendsPane(Snowflake id);
|
||||
|
||||
void SetMutualFriends(const std::vector<UserData> &users);
|
||||
|
||||
Snowflake UserID;
|
||||
|
||||
private:
|
||||
void on_switched_to() override;
|
||||
|
||||
bool m_requested = false;
|
||||
|
||||
void OnFetchRelationships(const std::vector<UserData> &users);
|
||||
|
||||
Gtk::ListBox m_list;
|
||||
};
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "profilewindow.hpp"
|
||||
#include "../abaddon.hpp"
|
||||
#include "../components/inotifyswitched.hpp"
|
||||
|
||||
ProfileWindow::ProfileWindow(Snowflake user_id)
|
||||
: ID(user_id)
|
||||
@ -13,7 +14,6 @@ ProfileWindow::ProfileWindow(Snowflake user_id)
|
||||
auto user = *discord.GetUser(ID);
|
||||
|
||||
discord.FetchUserProfile(user_id, sigc::mem_fun(*this, &ProfileWindow::OnFetchProfile));
|
||||
discord.FetchUserRelationships(user_id, sigc::mem_fun(*this, &ProfileWindow::OnFetchRelationships));
|
||||
|
||||
set_name("user-profile");
|
||||
set_default_size(450, 375);
|
||||
@ -72,6 +72,11 @@ ProfileWindow::ProfileWindow(Snowflake user_id)
|
||||
m_switcher.set_halign(Gtk::ALIGN_START);
|
||||
m_switcher.set_hexpand(true);
|
||||
|
||||
m_stack.property_visible_child().signal_changed().connect([this]() {
|
||||
if (auto *w = dynamic_cast<INotifySwitched *>(m_stack.property_visible_child().get_value()))
|
||||
w->on_switched_to();
|
||||
});
|
||||
|
||||
m_stack.add(m_pane_info, "info", "User Info");
|
||||
m_stack.add(m_pane_guilds, "guilds", "Mutual Servers");
|
||||
m_stack.add(m_pane_friends, "friends", "Mutual Friends");
|
||||
@ -127,7 +132,3 @@ void ProfileWindow::OnFetchProfile(const UserProfileData &data) {
|
||||
m_badges.add(*image);
|
||||
}
|
||||
}
|
||||
|
||||
void ProfileWindow::OnFetchRelationships(const std::vector<UserData> &data) {
|
||||
m_pane_friends.SetMutualFriends(data);
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ public:
|
||||
|
||||
private:
|
||||
void OnFetchProfile(const UserProfileData &data);
|
||||
void OnFetchRelationships(const std::vector<UserData> &data);
|
||||
|
||||
Gtk::Box m_main;
|
||||
Gtk::Box m_upper;
|
||||
|
Loading…
Reference in New Issue
Block a user