mirror of
https://github.com/celisej567/abaddon.git
synced 2026-09-27 16:16:35 +03:00
basic window to view threads
This commit is contained in:
@@ -249,6 +249,10 @@ std::set<Snowflake> DiscordClient::GetChannelsInGuild(Snowflake id) const {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<ChannelData> DiscordClient::GetPublicThreads(Snowflake channel_id) const {
|
||||
return m_store.GetThreads(channel_id);
|
||||
}
|
||||
|
||||
bool DiscordClient::HasGuildPermission(Snowflake user_id, Snowflake guild_id, Permission perm) const {
|
||||
const auto base = ComputePermissions(user_id, guild_id);
|
||||
return (base & perm) == perm;
|
||||
|
||||
@@ -86,6 +86,7 @@ public:
|
||||
std::optional<RoleData> GetMemberHighestRole(Snowflake guild_id, Snowflake user_id) const;
|
||||
std::set<Snowflake> GetUsersInGuild(Snowflake id) const;
|
||||
std::set<Snowflake> GetChannelsInGuild(Snowflake id) const;
|
||||
std::vector<ChannelData> GetPublicThreads(Snowflake channel_id) const;
|
||||
|
||||
bool HasGuildPermission(Snowflake user_id, Snowflake guild_id, Permission perm) const;
|
||||
|
||||
|
||||
@@ -499,6 +499,25 @@ std::vector<Message> Store::GetPinnedMessages(Snowflake channel_id) const {
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<ChannelData> Store::GetThreads(Snowflake channel_id) const {
|
||||
std::vector<ChannelData> ret;
|
||||
|
||||
Bind(m_get_threads_stmt, 1, channel_id);
|
||||
while (FetchOne(m_get_threads_stmt)) {
|
||||
Snowflake x;
|
||||
Get(m_get_threads_stmt, 0, x);
|
||||
auto chan = GetChannel(x);
|
||||
if (chan.has_value())
|
||||
ret.push_back(*chan);
|
||||
}
|
||||
|
||||
Reset(m_get_threads_stmt);
|
||||
|
||||
if (m_db_err != SQLITE_DONE)
|
||||
fprintf(stderr, "error while fetching threads: %s\n", sqlite3_errstr(m_db_err));
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::optional<ChannelData> Store::GetChannel(Snowflake id) const {
|
||||
Bind(m_get_chan_stmt, 1, id);
|
||||
if (!FetchOne(m_get_chan_stmt)) {
|
||||
@@ -1186,6 +1205,10 @@ bool Store::CreateStatements() {
|
||||
SELECT id FROM messages WHERE channel_id = ? AND pinned = 1 ORDER BY id ASC
|
||||
)";
|
||||
|
||||
const char *get_threads = R"(
|
||||
SELECT id FROM channels WHERE parent_id = ? AND type = 11
|
||||
)";
|
||||
|
||||
m_db_err = sqlite3_prepare_v2(m_db, set_user, -1, &m_set_user_stmt, nullptr);
|
||||
if (m_db_err != SQLITE_OK) {
|
||||
fprintf(stderr, "failed to prepare set user statement: %s\n", sqlite3_errstr(m_db_err));
|
||||
@@ -1326,7 +1349,13 @@ bool Store::CreateStatements() {
|
||||
|
||||
m_db_err = sqlite3_prepare_v2(m_db, get_pins, -1, &m_get_pins_stmt, nullptr);
|
||||
if (m_db_err != SQLITE_OK) {
|
||||
fprintf(stderr, "failed to prepare getp ins statement: %s\n", sqlite3_errstr(m_db_err));
|
||||
fprintf(stderr, "failed to prepare get pins statement: %s\n", sqlite3_errstr(m_db_err));
|
||||
return false;
|
||||
}
|
||||
|
||||
m_db_err = sqlite3_prepare_v2(m_db, get_threads, -1, &m_get_threads_stmt, nullptr);
|
||||
if (m_db_err != SQLITE_OK) {
|
||||
fprintf(stderr, "failed to prepare get threads statement: %s\n", sqlite3_errstr(m_db_err));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1358,6 +1387,7 @@ void Store::Cleanup() {
|
||||
sqlite3_finalize(m_get_last_msgs_stmt);
|
||||
sqlite3_finalize(m_get_msg_ids_stmt);
|
||||
sqlite3_finalize(m_get_pins_stmt);
|
||||
sqlite3_finalize(m_get_threads_stmt);
|
||||
}
|
||||
|
||||
void Store::Bind(sqlite3_stmt *stmt, int index, int num) const {
|
||||
|
||||
@@ -44,6 +44,7 @@ public:
|
||||
std::vector<Message> GetLastMessages(Snowflake id, size_t num) const;
|
||||
std::vector<Snowflake> GetChannelMessageIDs(Snowflake id) const;
|
||||
std::vector<Message> GetPinnedMessages(Snowflake channel_id) const;
|
||||
std::vector<ChannelData> GetThreads(Snowflake channel_id) const; // public
|
||||
|
||||
void ClearGuild(Snowflake id);
|
||||
void ClearChannel(Snowflake id);
|
||||
@@ -135,6 +136,7 @@ private:
|
||||
mutable sqlite3_stmt *m_get_last_msgs_stmt;
|
||||
mutable sqlite3_stmt *m_get_msg_ids_stmt;
|
||||
mutable sqlite3_stmt *m_get_pins_stmt;
|
||||
mutable sqlite3_stmt *m_get_threads_stmt;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
||||
Reference in New Issue
Block a user