summaryrefslogtreecommitdiff
path: root/discord
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2021-08-04 21:30:24 -0400
committerouwou <26526779+ouwou@users.noreply.github.com>2021-08-04 21:30:32 -0400
commit40897ece3ced8bfc051708a8d85f413f330631a9 (patch)
tree7741efc561550bb742df79edcb1a11408c0301c1 /discord
parenta19d21427206bcd5ab5cc0af273a05f3fe827720 (diff)
downloadabaddon-portaudio-40897ece3ced8bfc051708a8d85f413f330631a9.tar.gz
abaddon-portaudio-40897ece3ced8bfc051708a8d85f413f330631a9.zip
basic window to view threads
Diffstat (limited to 'discord')
-rw-r--r--discord/discord.cpp4
-rw-r--r--discord/discord.hpp1
-rw-r--r--discord/store.cpp32
-rw-r--r--discord/store.hpp2
4 files changed, 38 insertions, 1 deletions
diff --git a/discord/discord.cpp b/discord/discord.cpp
index 82d2131..49684ae 100644
--- a/discord/discord.cpp
+++ b/discord/discord.cpp
@@ -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;
diff --git a/discord/discord.hpp b/discord/discord.hpp
index 619a898..fa4b4c3 100644
--- a/discord/discord.hpp
+++ b/discord/discord.hpp
@@ -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;
diff --git a/discord/store.cpp b/discord/store.cpp
index 3cac46e..ba8e59a 100644
--- a/discord/store.cpp
+++ b/discord/store.cpp
@@ -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 {
diff --git a/discord/store.hpp b/discord/store.hpp
index 7e7d6ea..76c8a8e 100644
--- a/discord/store.hpp
+++ b/discord/store.hpp
@@ -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>