forked from OpenGamers/abaddon
actually retrieve roles for guilds
FetchRoles isnt needed anymore cuz full roles are fetched now
This commit is contained in:
parent
192b043e7a
commit
e02107feea
@ -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) {
|
||||
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;
|
||||
// gay and makes you send every role in between new and old position
|
||||
constexpr auto IDX_MAX = ~size_t { 0 };
|
||||
|
@ -188,21 +188,6 @@ std::vector<Snowflake> GuildData::GetSortedChannels(Snowflake ignore) const {
|
||||
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) {
|
||||
JS_D("user_id", m.UserID);
|
||||
JS_D("guild_id", m.GuildID);
|
||||
|
@ -50,7 +50,7 @@ struct GuildData {
|
||||
std::optional<int> VerificationLevel;
|
||||
std::optional<int> DefaultMessageNotifications;
|
||||
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::unordered_set<std::string>> Features;
|
||||
std::optional<int> MFALevel;
|
||||
@ -96,5 +96,4 @@ struct GuildData {
|
||||
bool HasAnimatedIcon() const;
|
||||
std::string GetIconURL(std::string ext = "png", std::string size = "32") 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();
|
||||
}
|
||||
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@ -961,9 +971,17 @@ std::optional<RoleData> Store::GetRole(Snowflake id) const {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto role = GetRoleBound(s);
|
||||
|
||||
s->Reset();
|
||||
|
||||
return role;
|
||||
}
|
||||
|
||||
RoleData Store::GetRoleBound(std::unique_ptr<Statement> &s) const {
|
||||
RoleData r;
|
||||
|
||||
r.ID = id;
|
||||
s->Get(0, r.ID);
|
||||
//s->Get(1, guild id);
|
||||
s->Get(2, r.Name);
|
||||
s->Get(3, r.Color);
|
||||
@ -973,8 +991,6 @@ std::optional<RoleData> Store::GetRole(Snowflake id) const {
|
||||
s->Get(7, r.IsManaged);
|
||||
s->Get(8, r.IsMentionable);
|
||||
|
||||
s->Reset();
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -1726,6 +1742,14 @@ bool Store::CreateStatements() {
|
||||
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"(
|
||||
REPLACE INTO emojis VALUES (
|
||||
?, ?, ?, ?, ?, ?, ?
|
||||
|
@ -235,6 +235,7 @@ private:
|
||||
};
|
||||
|
||||
Message GetMessageBound(std::unique_ptr<Statement> &stmt) const;
|
||||
RoleData GetRoleBound(std::unique_ptr<Statement> &stmt) const;
|
||||
|
||||
void SetMessageInteractionPair(Snowflake message_id, const MessageInteractionData &interaction);
|
||||
|
||||
@ -264,6 +265,7 @@ private:
|
||||
STMT(get_member);
|
||||
STMT(set_role);
|
||||
STMT(get_role);
|
||||
STMT(get_guild_roles);
|
||||
STMT(set_emoji);
|
||||
STMT(get_emoji);
|
||||
STMT(set_perm);
|
||||
|
@ -238,9 +238,10 @@ GuildSettingsMembersPaneRoles::GuildSettingsMembersPaneRoles(Snowflake guild_id)
|
||||
discord.signal_role_delete().connect(sigc::mem_fun(*this, &GuildSettingsMembersPaneRoles::OnRoleDelete));
|
||||
|
||||
const auto guild = *discord.GetGuild(guild_id);
|
||||
const auto roles = guild.FetchRoles();
|
||||
for (const auto &role : roles) {
|
||||
CreateRow(can_modify, role, guild.OwnerID == self_id);
|
||||
if (guild.Roles.has_value()) {
|
||||
for (const auto &role : *guild.Roles) {
|
||||
CreateRow(can_modify, role, guild.OwnerID == self_id);
|
||||
}
|
||||
}
|
||||
|
||||
m_list.set_sort_func([this](Gtk::ListBoxRow *a, Gtk::ListBoxRow *b) -> int {
|
||||
|
@ -79,19 +79,20 @@ GuildSettingsRolesPaneRoles::GuildSettingsRolesPaneRoles(Snowflake guild_id)
|
||||
discord.signal_role_delete().connect(sigc::mem_fun(*this, &GuildSettingsRolesPaneRoles::OnRoleDelete));
|
||||
|
||||
const auto guild = *discord.GetGuild(GuildID);
|
||||
const auto roles = guild.FetchRoles();
|
||||
const bool can_modify = discord.HasGuildPermission(discord.GetUserData().ID, GuildID, Permission::MANAGE_ROLES);
|
||||
for (const auto &role : roles) {
|
||||
auto *row = Gtk::manage(new GuildSettingsRolesPaneRolesListItem(guild, role));
|
||||
row->drag_source_set(g_target_entries, Gdk::BUTTON1_MASK, Gdk::ACTION_MOVE);
|
||||
row->set_margin_start(5);
|
||||
row->set_halign(Gtk::ALIGN_FILL);
|
||||
row->show();
|
||||
m_rows[role.ID] = row;
|
||||
if (can_modify)
|
||||
m_list.add_draggable(row);
|
||||
else
|
||||
m_list.add(*row);
|
||||
if (guild.Roles.has_value()) {
|
||||
for (const auto &role : *guild.Roles) {
|
||||
auto *row = Gtk::manage(new GuildSettingsRolesPaneRolesListItem(guild, role));
|
||||
row->drag_source_set(g_target_entries, Gdk::BUTTON1_MASK, Gdk::ACTION_MOVE);
|
||||
row->set_margin_start(5);
|
||||
row->set_halign(Gtk::ALIGN_FILL);
|
||||
row->show();
|
||||
m_rows[role.ID] = row;
|
||||
if (can_modify)
|
||||
m_list.add_draggable(row);
|
||||
else
|
||||
m_list.add(*row);
|
||||
}
|
||||
}
|
||||
|
||||
m_list.set_sort_func([this](Gtk::ListBoxRow *rowa_, Gtk::ListBoxRow *rowb_) -> int {
|
||||
|
Loading…
Reference in New Issue
Block a user