forked from OpenGamers/abaddon
actually retrieve roles for guilds
FetchRoles isnt needed anymore cuz full roles are fetched now
This commit is contained in:
@@ -720,7 +720,9 @@ void DiscordClient::ModifyRoleColor(Snowflake guild_id, Snowflake role_id, Gdk::
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DiscordClient::ModifyRolePosition(Snowflake guild_id, Snowflake role_id, int position, sigc::slot<void(DiscordError code)> callback) {
|
void DiscordClient::ModifyRolePosition(Snowflake guild_id, Snowflake role_id, int position, sigc::slot<void(DiscordError code)> callback) {
|
||||||
const auto roles = GetGuild(guild_id)->FetchRoles();
|
const auto guild = GetGuild(guild_id);
|
||||||
|
if (!guild.has_value() || !guild->Roles.has_value()) return;
|
||||||
|
const auto &roles = *guild->Roles;
|
||||||
if (static_cast<size_t>(position) > roles.size()) return;
|
if (static_cast<size_t>(position) > roles.size()) return;
|
||||||
// gay and makes you send every role in between new and old position
|
// gay and makes you send every role in between new and old position
|
||||||
constexpr auto IDX_MAX = ~size_t { 0 };
|
constexpr auto IDX_MAX = ~size_t { 0 };
|
||||||
|
|||||||
@@ -188,21 +188,6 @@ std::vector<Snowflake> GuildData::GetSortedChannels(Snowflake ignore) const {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<RoleData> GuildData::FetchRoles() const {
|
|
||||||
if (!Roles.has_value()) return {};
|
|
||||||
std::vector<RoleData> ret;
|
|
||||||
ret.reserve(Roles->size());
|
|
||||||
for (const auto thing : *Roles) {
|
|
||||||
auto r = Abaddon::Get().GetDiscordClient().GetRole(thing.ID);
|
|
||||||
if (r.has_value())
|
|
||||||
ret.push_back(*r);
|
|
||||||
}
|
|
||||||
std::sort(ret.begin(), ret.end(), [](const RoleData &a, const RoleData &b) -> bool {
|
|
||||||
return a.Position > b.Position;
|
|
||||||
});
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void from_json(const nlohmann::json &j, GuildApplicationData &m) {
|
void from_json(const nlohmann::json &j, GuildApplicationData &m) {
|
||||||
JS_D("user_id", m.UserID);
|
JS_D("user_id", m.UserID);
|
||||||
JS_D("guild_id", m.GuildID);
|
JS_D("guild_id", m.GuildID);
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ struct GuildData {
|
|||||||
std::optional<int> VerificationLevel;
|
std::optional<int> VerificationLevel;
|
||||||
std::optional<int> DefaultMessageNotifications;
|
std::optional<int> DefaultMessageNotifications;
|
||||||
std::optional<int> ExplicitContentFilter;
|
std::optional<int> ExplicitContentFilter;
|
||||||
std::optional<std::vector<RoleData>> Roles; // only access id
|
std::optional<std::vector<RoleData>> Roles;
|
||||||
std::optional<std::vector<EmojiData>> Emojis; // only access id
|
std::optional<std::vector<EmojiData>> Emojis; // only access id
|
||||||
std::optional<std::unordered_set<std::string>> Features;
|
std::optional<std::unordered_set<std::string>> Features;
|
||||||
std::optional<int> MFALevel;
|
std::optional<int> MFALevel;
|
||||||
@@ -96,5 +96,4 @@ struct GuildData {
|
|||||||
bool HasAnimatedIcon() const;
|
bool HasAnimatedIcon() const;
|
||||||
std::string GetIconURL(std::string ext = "png", std::string size = "32") const;
|
std::string GetIconURL(std::string ext = "png", std::string size = "32") const;
|
||||||
std::vector<Snowflake> GetSortedChannels(Snowflake ignore = Snowflake::Invalid) const;
|
std::vector<Snowflake> GetSortedChannels(Snowflake ignore = Snowflake::Invalid) const;
|
||||||
std::vector<RoleData> FetchRoles() const; // sorted
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -765,6 +765,16 @@ std::optional<GuildData> Store::GetGuild(Snowflake id) const {
|
|||||||
s->Reset();
|
s->Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto &s = m_stmt_get_guild_roles;
|
||||||
|
s->Bind(1, id);
|
||||||
|
r.Roles.emplace();
|
||||||
|
while (s->FetchOne()) {
|
||||||
|
r.Roles->push_back(GetRoleBound(s));
|
||||||
|
}
|
||||||
|
s->Reset();
|
||||||
|
}
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -961,9 +971,17 @@ std::optional<RoleData> Store::GetRole(Snowflake id) const {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto role = GetRoleBound(s);
|
||||||
|
|
||||||
|
s->Reset();
|
||||||
|
|
||||||
|
return role;
|
||||||
|
}
|
||||||
|
|
||||||
|
RoleData Store::GetRoleBound(std::unique_ptr<Statement> &s) const {
|
||||||
RoleData r;
|
RoleData r;
|
||||||
|
|
||||||
r.ID = id;
|
s->Get(0, r.ID);
|
||||||
//s->Get(1, guild id);
|
//s->Get(1, guild id);
|
||||||
s->Get(2, r.Name);
|
s->Get(2, r.Name);
|
||||||
s->Get(3, r.Color);
|
s->Get(3, r.Color);
|
||||||
@@ -973,8 +991,6 @@ std::optional<RoleData> Store::GetRole(Snowflake id) const {
|
|||||||
s->Get(7, r.IsManaged);
|
s->Get(7, r.IsManaged);
|
||||||
s->Get(8, r.IsMentionable);
|
s->Get(8, r.IsMentionable);
|
||||||
|
|
||||||
s->Reset();
|
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1726,6 +1742,14 @@ bool Store::CreateStatements() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_stmt_get_guild_roles = std::make_unique<Statement>(m_db, R"(
|
||||||
|
SELECT * FROM roles WHERE guild = ?
|
||||||
|
)");
|
||||||
|
if (!m_stmt_get_guild_roles->OK()) {
|
||||||
|
fprintf(stderr, "failed to prepare get guild roles statement: %s\n", m_db.ErrStr());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
m_stmt_set_emoji = std::make_unique<Statement>(m_db, R"(
|
m_stmt_set_emoji = std::make_unique<Statement>(m_db, R"(
|
||||||
REPLACE INTO emojis VALUES (
|
REPLACE INTO emojis VALUES (
|
||||||
?, ?, ?, ?, ?, ?, ?
|
?, ?, ?, ?, ?, ?, ?
|
||||||
|
|||||||
@@ -235,6 +235,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
Message GetMessageBound(std::unique_ptr<Statement> &stmt) const;
|
Message GetMessageBound(std::unique_ptr<Statement> &stmt) const;
|
||||||
|
RoleData GetRoleBound(std::unique_ptr<Statement> &stmt) const;
|
||||||
|
|
||||||
void SetMessageInteractionPair(Snowflake message_id, const MessageInteractionData &interaction);
|
void SetMessageInteractionPair(Snowflake message_id, const MessageInteractionData &interaction);
|
||||||
|
|
||||||
@@ -264,6 +265,7 @@ private:
|
|||||||
STMT(get_member);
|
STMT(get_member);
|
||||||
STMT(set_role);
|
STMT(set_role);
|
||||||
STMT(get_role);
|
STMT(get_role);
|
||||||
|
STMT(get_guild_roles);
|
||||||
STMT(set_emoji);
|
STMT(set_emoji);
|
||||||
STMT(get_emoji);
|
STMT(get_emoji);
|
||||||
STMT(set_perm);
|
STMT(set_perm);
|
||||||
|
|||||||
@@ -238,10 +238,11 @@ GuildSettingsMembersPaneRoles::GuildSettingsMembersPaneRoles(Snowflake guild_id)
|
|||||||
discord.signal_role_delete().connect(sigc::mem_fun(*this, &GuildSettingsMembersPaneRoles::OnRoleDelete));
|
discord.signal_role_delete().connect(sigc::mem_fun(*this, &GuildSettingsMembersPaneRoles::OnRoleDelete));
|
||||||
|
|
||||||
const auto guild = *discord.GetGuild(guild_id);
|
const auto guild = *discord.GetGuild(guild_id);
|
||||||
const auto roles = guild.FetchRoles();
|
if (guild.Roles.has_value()) {
|
||||||
for (const auto &role : roles) {
|
for (const auto &role : *guild.Roles) {
|
||||||
CreateRow(can_modify, role, guild.OwnerID == self_id);
|
CreateRow(can_modify, role, guild.OwnerID == self_id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_list.set_sort_func([this](Gtk::ListBoxRow *a, Gtk::ListBoxRow *b) -> int {
|
m_list.set_sort_func([this](Gtk::ListBoxRow *a, Gtk::ListBoxRow *b) -> int {
|
||||||
auto *rowa = dynamic_cast<GuildSettingsMembersPaneRolesItem *>(a);
|
auto *rowa = dynamic_cast<GuildSettingsMembersPaneRolesItem *>(a);
|
||||||
|
|||||||
@@ -79,9 +79,9 @@ GuildSettingsRolesPaneRoles::GuildSettingsRolesPaneRoles(Snowflake guild_id)
|
|||||||
discord.signal_role_delete().connect(sigc::mem_fun(*this, &GuildSettingsRolesPaneRoles::OnRoleDelete));
|
discord.signal_role_delete().connect(sigc::mem_fun(*this, &GuildSettingsRolesPaneRoles::OnRoleDelete));
|
||||||
|
|
||||||
const auto guild = *discord.GetGuild(GuildID);
|
const auto guild = *discord.GetGuild(GuildID);
|
||||||
const auto roles = guild.FetchRoles();
|
|
||||||
const bool can_modify = discord.HasGuildPermission(discord.GetUserData().ID, GuildID, Permission::MANAGE_ROLES);
|
const bool can_modify = discord.HasGuildPermission(discord.GetUserData().ID, GuildID, Permission::MANAGE_ROLES);
|
||||||
for (const auto &role : roles) {
|
if (guild.Roles.has_value()) {
|
||||||
|
for (const auto &role : *guild.Roles) {
|
||||||
auto *row = Gtk::manage(new GuildSettingsRolesPaneRolesListItem(guild, role));
|
auto *row = Gtk::manage(new GuildSettingsRolesPaneRolesListItem(guild, role));
|
||||||
row->drag_source_set(g_target_entries, Gdk::BUTTON1_MASK, Gdk::ACTION_MOVE);
|
row->drag_source_set(g_target_entries, Gdk::BUTTON1_MASK, Gdk::ACTION_MOVE);
|
||||||
row->set_margin_start(5);
|
row->set_margin_start(5);
|
||||||
@@ -93,6 +93,7 @@ GuildSettingsRolesPaneRoles::GuildSettingsRolesPaneRoles(Snowflake guild_id)
|
|||||||
else
|
else
|
||||||
m_list.add(*row);
|
m_list.add(*row);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_list.set_sort_func([this](Gtk::ListBoxRow *rowa_, Gtk::ListBoxRow *rowb_) -> int {
|
m_list.set_sort_func([this](Gtk::ListBoxRow *rowa_, Gtk::ListBoxRow *rowb_) -> int {
|
||||||
auto *rowa = dynamic_cast<GuildSettingsRolesPaneRolesListItem *>(rowa_);
|
auto *rowa = dynamic_cast<GuildSettingsRolesPaneRolesListItem *>(rowa_);
|
||||||
|
|||||||
Reference in New Issue
Block a user