diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-06-20 20:32:16 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-06-20 20:32:16 -0400 |
commit | 7db2675087a563ec82574937759137fa2e57298c (patch) | |
tree | dc1dac731ef1ca4f4f89edb2913e34abc2eaeda9 /discord/store.cpp | |
parent | 78f3164063f90c2be53d56fef6fd4a1cd085d923 (diff) | |
download | abaddon-portaudio-7db2675087a563ec82574937759137fa2e57298c.tar.gz abaddon-portaudio-7db2675087a563ec82574937759137fa2e57298c.zip |
fetch pins from store if already requested
Diffstat (limited to 'discord/store.cpp')
-rw-r--r-- | discord/store.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/discord/store.cpp b/discord/store.cpp index 7aa74c0..b282100 100644 --- a/discord/store.cpp +++ b/discord/store.cpp @@ -463,6 +463,25 @@ std::vector<Snowflake> Store::GetChannelMessageIDs(Snowflake id) const { return ret; } +std::vector<Message> Store::GetPinnedMessages(Snowflake channel_id) const { + std::vector<Message> ret; + + Bind(m_get_pins_stmt, 1, channel_id); + while (FetchOne(m_get_pins_stmt)) { + Snowflake x; + Get(m_get_pins_stmt, 0, x); + auto msg = GetMessage(x); + if (msg.has_value()) + ret.push_back(*msg); + } + + Reset(m_get_pins_stmt); + + if (m_db_err != SQLITE_DONE) + fprintf(stderr, "error while fetching pins: %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)) { @@ -1138,6 +1157,10 @@ bool Store::CreateStatements() { SELECT id FROM messages WHERE channel_id = ? ORDER BY id ASC )"; + const char *get_pins = R"( + SELECT id FROM messages WHERE channel_id = ? AND pinned = 1 ORDER BY id ASC + )"; + 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)); @@ -1276,6 +1299,12 @@ bool Store::CreateStatements() { return false; } + 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)); + return false; + } + return true; } @@ -1303,6 +1332,7 @@ void Store::Cleanup() { sqlite3_finalize(m_set_msg_interaction_stmt); sqlite3_finalize(m_get_last_msgs_stmt); sqlite3_finalize(m_get_msg_ids_stmt); + sqlite3_finalize(m_get_pins_stmt); } void Store::Bind(sqlite3_stmt *stmt, int index, int num) const { |