Skip to content

Commit

Permalink
Fixed getting archived threads
Browse files Browse the repository at this point in the history
Used get_active_threads as a template to properly implement threads_get_public_archived and threads_get_private_archived
  • Loading branch information
CMDisme authored and Mishura4 committed Feb 16, 2024
1 parent 053e6ca commit 4334c94
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/dpp/cluster/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,41 @@ void cluster::threads_get_private_archived(snowflake channel_id, time_t before_t
{"before", before_timestamp},
{"limit", limit},
});
rest_request_list<thread>(this, API_PATH "/channels", std::to_string(channel_id), "/threads/archived/private" + parameters, m_get, "", callback);
this->post_rest(API_PATH "/channels", std::to_string(channel_id), "/threads/archived/private" + parameters, m_get, "", [this, callback](json &j, const http_request_completion_t& http) {
std::unordered_map<snowflake, thread> list;
confirmation_callback_t e(this, confirmation(), http);
if (!e.is_error()) {
if (j.contains("threads")) {
for (auto &curr_item: j["threads"]) {
list[snowflake_not_null(&curr_item, "id")].fill_from_json(&curr_item);
}
}
}
if (callback) {
callback(confirmation_callback_t(this, list, http));
}
});
}

void cluster::threads_get_public_archived(snowflake channel_id, time_t before_timestamp, uint16_t limit, command_completion_event_t callback) {
std::string parameters = utility::make_url_parameters({
{"before", before_timestamp},
{"limit", limit},
});
rest_request_list<thread>(this, API_PATH "/channels", std::to_string(channel_id), "/threads/archived/public" + parameters, m_get, "", callback);
this->post_rest(API_PATH "/channels", std::to_string(channel_id), "/threads/archived/public" + parameters, m_get, "", [this, callback](json &j, const http_request_completion_t& http) {
std::unordered_map<snowflake, thread> list;
confirmation_callback_t e(this, confirmation(), http);
if (!e.is_error()) {
if (j.contains("threads")) {
for (auto &curr_item: j["threads"]) {
list[snowflake_not_null(&curr_item, "id")].fill_from_json(&curr_item);
}
}
}
if (callback) {
callback(confirmation_callback_t(this, list, http));
}
});
}

void cluster::thread_member_get(const snowflake thread_id, const snowflake user_id, command_completion_event_t callback) {
Expand Down

0 comments on commit 4334c94

Please sign in to comment.