diff --git a/plugins/social_network/include/golos/plugins/social_network/social_network.hpp b/plugins/social_network/include/golos/plugins/social_network/social_network.hpp index dc40d401ca..fb7d3bb308 100644 --- a/plugins/social_network/include/golos/plugins/social_network/social_network.hpp +++ b/plugins/social_network/include/golos/plugins/social_network/social_network.hpp @@ -17,13 +17,14 @@ namespace golos { namespace plugins { namespace social_network { using namespace golos::chain; using golos::api::comment_api_object; - DEFINE_API_ARGS(get_content, msg_pack, discussion) - DEFINE_API_ARGS(get_content_replies, msg_pack, std::vector) - DEFINE_API_ARGS(get_all_content_replies, msg_pack, std::vector) - DEFINE_API_ARGS(get_account_votes, msg_pack, std::vector) - DEFINE_API_ARGS(get_active_votes, msg_pack, std::vector) - DEFINE_API_ARGS(get_donates, msg_pack, std::vector) - DEFINE_API_ARGS(get_replies_by_last_update, msg_pack, std::vector) + DEFINE_API_ARGS(get_content, msg_pack, discussion) + DEFINE_API_ARGS(get_content_replies, msg_pack, std::vector) + DEFINE_API_ARGS(get_all_content_replies, msg_pack, std::vector) + DEFINE_API_ARGS(get_account_votes, msg_pack, std::vector) + DEFINE_API_ARGS(get_active_votes, msg_pack, std::vector) + DEFINE_API_ARGS(get_donates, msg_pack, std::vector) + DEFINE_API_ARGS(get_replies_by_last_update, msg_pack, std::vector) + DEFINE_API_ARGS(get_all_discussions_by_active, msg_pack, std::vector) class social_network final: public appbase::plugin { public: @@ -40,6 +41,7 @@ namespace golos { namespace plugins { namespace social_network { (get_active_votes) (get_donates) (get_replies_by_last_update) + (get_all_discussions_by_active) ) social_network(); diff --git a/plugins/social_network/social_network.cpp b/plugins/social_network/social_network.cpp index 72df475853..bf632103b9 100644 --- a/plugins/social_network/social_network.cpp +++ b/plugins/social_network/social_network.cpp @@ -111,6 +111,11 @@ namespace golos { namespace plugins { namespace social_network { uint32_t limit, uint32_t vote_limit, uint32_t vote_offset ) const; + std::vector get_all_discussions_by_active( + account_name_type start_author, std::string start_permlink, + uint32_t limit, std::string category, uint32_t vote_limit, uint32_t vote_offset + ) const; + discussion get_content(const std::string& author, const std::string& permlink, uint32_t limit, uint32_t offset) const; discussion get_discussion(const comment_object& c, uint32_t vote_limit, uint32_t vote_offset) const; @@ -965,6 +970,59 @@ namespace golos { namespace plugins { namespace social_network { return result; } + std::vector social_network::impl::get_all_discussions_by_active( + account_name_type start_author, + std::string start_permlink, + uint32_t limit, + std::string category, + uint32_t vote_limit, + uint32_t vote_offset + ) const { + std::vector result; + + if (!db.has_index()) { + return result; + } + + // Method returns only comments which are created when config flag was true + + result.reserve(limit); + + std::vector all_discussions; + const auto& idx = db.get_index(); + auto itr = idx.lower_bound(std::make_tuple(STEEMIT_ROOT_POST_PARENT, category)); + while ( + itr != idx.end() && + itr->parent_author == STEEMIT_ROOT_POST_PARENT + ) { + if (category.size() && to_string(itr->parent_permlink) != category) break; + all_discussions.emplace_back(get_discussion(*itr, vote_limit, vote_offset)); + ++itr; + } + + std::sort(all_discussions.begin(), all_discussions.end(), [&](auto& lhs, auto& rhs) { + if (!!lhs.active && !!rhs.active) return *lhs.active > *rhs.active; + return true; + }); + + int i = 0; + if (start_author.size() && start_permlink.size()) { + for (; i < all_discussions.size(); ++i) { + auto& dis = all_discussions[i]; + if (dis.author == start_author && dis.permlink == start_permlink) { + break; + } + } + } + + auto i_end = i + limit; + for (; i < all_discussions.size() && i < i_end; ++i) { + result.push_back(all_discussions[i]); + } + + return result; + } + /** * This method can be used to fetch replies to an account. * @@ -986,6 +1044,29 @@ namespace golos { namespace plugins { namespace social_network { }); } + /** + * Gets all discussions by active (last update by comment under post. + * + * Unlike the tags_plugin::get_discussions_by_*** methods, + * this method gets really ALL discussions, created from forum funding date to now. + * + * Supports filtering by category. + */ + DEFINE_API(social_network, get_all_discussions_by_active) { + PLUGIN_API_VALIDATE_ARGS( + (string, start_author) + (string, start_permlink) + (uint32_t, limit) + (string, category, "") + (uint32_t, vote_limit, DEFAULT_VOTE_LIMIT) + (uint32_t, vote_offset, 0) + + ); + return pimpl->db.with_weak_read_lock([&]() { + return pimpl->get_all_discussions_by_active(start_author, start_permlink, limit, category, vote_limit, vote_offset); + }); + } + void fill_comment_info(const golos::chain::database& db, const comment_object& co, comment_api_object& con) { if (db.has_index()) { const auto content = db.find(co.id);