Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_discussions_by_blog to filter resteems #678

Merged
merged 1 commit into from Dec 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
65 changes: 60 additions & 5 deletions libraries/app/database_api.cpp
Expand Up @@ -1532,6 +1532,7 @@ vector<discussion> database_api::get_discussions_by_blog( const discussion_query
FC_ASSERT( my->_follow_api, "Node is not running the follow plugin" );
auto start_author = query.start_author ? *( query.start_author ) : "";
auto start_permlink = query.start_permlink ? *( query.start_permlink ) : "";
auto hide = query.hide ? *( query.hide ) : "";

const auto& account = my->_db.get_account( query.tag );

Expand All @@ -1555,10 +1556,30 @@ vector<discussion> database_api::get_discussions_by_blog( const discussion_query
break;
try
{
result.push_back( get_discussion( blog_itr->comment ) );
if( blog_itr->reblogged_on > time_point_sec() )
bool resteemed = blog_itr->reblogged_on > time_point_sec();

if( hide == "resteemed" ) // only show authored discussions
{
if( !resteemed )
{
result.push_back( get_discussion( blog_itr->comment ) );
}
}
else if( hide == "authored" ) // only show resteemed discussions
{
result.back().first_reblogged_on = blog_itr->reblogged_on;
if( resteemed )
{
result.push_back( get_discussion( blog_itr->comment ) );
result.back().first_reblogged_on = blog_itr->reblogged_on;
}
}
else // show mixed
{
result.push_back( get_discussion( blog_itr->comment ) );
if( resteemed )
{
result.back().first_reblogged_on = blog_itr->reblogged_on;
}
}
}
catch ( const fc::exception& e )
Expand Down Expand Up @@ -1948,7 +1969,7 @@ state database_api::get_state( string path )const
}
#endif
}
else if( part[1].size() == 0 || part[1] == "blog" )
else if( part[1].size() == 0 )
{
if( my->_follow_api )
{
Expand All @@ -1969,7 +1990,41 @@ state database_api::get_state( string path )const
}
}
}
else if( part[1].size() == 0 || part[1] == "feed" )
else if( part[1] == "blog" )
{
discussion_query q;
q.tag = eacnt.name;
q.limit = 20;
q.hide = "resteemed";
auto blog = get_discussions_by_blog( q );
eacnt.blog = vector< string >();

for( const auto& b : blog ) {
const auto link = b.author + "/" + b.permlink;
eacnt.blog->push_back( link );
_state.content[link] = std::move(b);
set_pending_payout( _state.content[ link ] );
}
}
else if( part[1] == "resteemed" )
{
discussion_query q;
q.tag = eacnt.name;
q.limit = 20;
q.hide = "authored";
auto blog = get_discussions_by_blog( q );
eacnt.resteemed = vector< string >();

for( const auto& b : blog ) {
const auto link = b.author + "/" + b.permlink;
eacnt.resteemed->push_back( link );
if( b.author.size() ) accounts.insert(b.author);
_state.content[link] = std::move(b);
set_pending_payout( _state.content[ link ] );
_state.content[ link ].first_reblogged_on = b.first_reblogged_on;
}
}
else if( part[1] == "feed" )
{
if( my->_follow_api )
{
Expand Down
3 changes: 2 additions & 1 deletion libraries/app/include/steemit/app/database_api.hpp
Expand Up @@ -92,6 +92,7 @@ struct discussion_query {
optional<string> start_permlink;
optional<string> parent_author;
optional<string> parent_permlink;
optional<string> hide; // used for get_discussions_by_blog, either "authored" or "resteemed"
};

/**
Expand Down Expand Up @@ -432,7 +433,7 @@ FC_REFLECT( steemit::app::scheduled_hardfork, (hf_version)(live_time) );
FC_REFLECT( steemit::app::liquidity_balance, (account)(weight) );
FC_REFLECT( steemit::app::withdraw_route, (from_account)(to_account)(percent)(auto_vest) );

FC_REFLECT( steemit::app::discussion_query, (tag)(filter_tags)(start_author)(start_permlink)(parent_author)(parent_permlink)(limit) );
FC_REFLECT( steemit::app::discussion_query, (tag)(filter_tags)(start_author)(start_permlink)(parent_author)(parent_permlink)(limit)(hide) );

FC_REFLECT_ENUM( steemit::app::withdraw_route_type, (incoming)(outgoing)(all) );

Expand Down
3 changes: 2 additions & 1 deletion libraries/app/include/steemit/app/state.hpp
Expand Up @@ -103,6 +103,7 @@ namespace steemit { namespace app {
optional<map<uint32_t,extended_limit_order>> open_orders;
optional<vector<string>> comments; /// permlinks for this user
optional<vector<string>> blog; /// blog posts for this user
optional<vector<string>> resteemed; /// resteemed posts for this user
optional<vector<string>> feed; /// feed posts for this user
optional<vector<string>> recent_replies; /// blog posts for this user
map<string,vector<string>> blog_category; /// blog posts for this user
Expand Down Expand Up @@ -187,7 +188,7 @@ namespace steemit { namespace app {
FC_REFLECT_DERIVED( steemit::app::extended_account,
(steemit::app::account_api_obj),
(vesting_balance)(reputation)
(transfer_history)(market_history)(post_history)(vote_history)(other_history)(witness_votes)(open_orders)(comments)(feed)(blog)(recent_replies)(blog_category)(recommended) )
(transfer_history)(market_history)(post_history)(vote_history)(other_history)(witness_votes)(open_orders)(comments)(feed)(blog)(resteemed)(recent_replies)(blog_category)(recommended) )


FC_REFLECT( steemit::app::vote_state, (voter)(weight)(rshares)(percent)(reputation)(time) );
Expand Down