Skip to content
This repository was archived by the owner on Oct 4, 2019. It is now read-only.

Commit 2e6fe00

Browse files
authored
Merge pull request #465 from GolosChain/464-get-all-content-replies
Add API social_network::get_all_content_replies. #464
2 parents 0ba8ad7 + f0add18 commit 2e6fe00

2 files changed

Lines changed: 49 additions & 5 deletions

File tree

plugins/social_network/include/golos/plugins/social_network/social_network.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace golos {
2222
DEFINE_API_ARGS(get_content, msg_pack, discussion)
2323
DEFINE_API_ARGS(get_trending_tags, msg_pack, std::vector<tag_api_object>)
2424
DEFINE_API_ARGS(get_content_replies, msg_pack, std::vector<discussion>)
25+
DEFINE_API_ARGS(get_all_content_replies, msg_pack, std::vector<discussion>)
2526
DEFINE_API_ARGS(get_tags_used_by_author, msg_pack, tags_used_by_author_r)
2627
DEFINE_API_ARGS(get_discussions_by_payout, msg_pack, std::vector<discussion>)
2728
DEFINE_API_ARGS(get_discussions_by_trending, msg_pack, std::vector<discussion>)
@@ -160,6 +161,7 @@ namespace golos {
160161
**/
161162
(get_discussions_by_promoted)
162163
(get_content_replies)
164+
(get_all_content_replies)
163165
/**
164166
* This method is used to fetch all posts/comments by start_author that occur after before_date and start_permlink with up to limit being returned.
165167
*

plugins/social_network/social_network.cpp

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,17 @@ namespace golos {
182182
Args... args
183183
) const;
184184
185-
std::vector<discussion> get_content_replies(std::string author, std::string permlink) const;
185+
void select_content_replies(
186+
std::vector<discussion>& result, const std::string &author, const std::string &permlink
187+
) const;
188+
189+
std::vector<discussion> get_content_replies(
190+
const std::string &author, const std::string &permlink
191+
) const;
192+
193+
std::vector<discussion> get_all_content_replies(
194+
const std::string &author, const std::string &permlink
195+
) const;
186196
187197
std::vector<tag_api_object> get_trending_tags(std::string after, uint32_t limit) const;
188198
@@ -325,20 +335,31 @@ namespace golos {
325335
}
326336
}
327337
328-
std::vector<discussion> social_network_t::impl::get_content_replies(std::string author, std::string permlink) const {
338+
void social_network_t::impl::select_content_replies(
339+
std::vector<discussion> &result, const std::string &author, const std::string &permlink
340+
) const {
329341
account_name_type acc_name = account_name_type(author);
330342
const auto &by_permlink_idx = database().get_index<comment_index>().indices().get<by_parent>();
331343
auto itr = by_permlink_idx.find(boost::make_tuple(acc_name, permlink));
332-
std::vector<discussion> result;
333-
while (itr != by_permlink_idx.end() && itr->parent_author == author &&
334-
to_string(itr->parent_permlink) == permlink) {
344+
while (
345+
itr != by_permlink_idx.end() &&
346+
itr->parent_author == author &&
347+
!strcmp(itr->parent_permlink.c_str(), permlink.c_str())
348+
) {
335349
discussion push_discussion(*itr);
336350
push_discussion.active_votes = get_active_votes(author, permlink);
337351
338352
result.emplace_back(*itr);
339353
set_pending_payout(result.back());
340354
++itr;
341355
}
356+
}
357+
358+
std::vector<discussion> social_network_t::impl::get_content_replies(
359+
const std::string &author, const std::string &permlink
360+
) const {
361+
std::vector<discussion> result;
362+
select_content_replies(result, author, permlink);
342363
return result;
343364
}
344365
@@ -351,6 +372,27 @@ namespace golos {
351372
});
352373
}
353374
375+
std::vector<discussion> social_network_t::impl::get_all_content_replies(
376+
const std::string &author, const std::string &permlink
377+
) const {
378+
std::vector<discussion> result;
379+
select_content_replies(result, author, permlink);
380+
for (std::size_t i = 0; i < result.size(); ++i) {
381+
if (result[i].children > 0) {
382+
select_content_replies(result, result[i].author, result[i].permlink);
383+
}
384+
}
385+
return result;
386+
}
387+
388+
DEFINE_API(social_network_t, get_all_content_replies) {
389+
CHECK_ARG_SIZE(2)
390+
auto author = args.args->at(0).as<string>();
391+
auto permlink = args.args->at(1).as<string>();
392+
return pimpl->database().with_read_lock([&]() {
393+
return pimpl->get_all_content_replies(author, permlink);
394+
});
395+
}
354396
boost::multiprecision::uint256_t to256(const fc::uint128_t &t) {
355397
boost::multiprecision::uint256_t result(t.high_bits());
356398
result <<= 65;

0 commit comments

Comments
 (0)