mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-24 05:24:34 +00:00
add another flag field to getposts to allow selecting only DMs or RTs.
hint: to get (encrypted) DM posts use values "2 2"
This commit is contained in:
parent
fa004f5108
commit
57b554f7cf
@ -200,7 +200,7 @@ namespace libtorrent
|
|||||||
void read_piece(int piece);
|
void read_piece(int piece);
|
||||||
void on_disk_read_complete(int ret, disk_io_job const& j, peer_request r, read_piece_struct* rp);
|
void on_disk_read_complete(int ret, disk_io_job const& j, peer_request r, read_piece_struct* rp);
|
||||||
|
|
||||||
void get_pieces(std::vector<std::string> *pieces, int count, int max_id, int since_id, uint32_t filter_flags,
|
void get_pieces(std::vector<std::string> *pieces, int count, int max_id, int since_id, std::pair<uint32_t,uint32_t> flags,
|
||||||
mutex *mut, condition_variable *cond, int *reqs);
|
mutex *mut, condition_variable *cond, int *reqs);
|
||||||
void on_disk_read_get_piece_complete(int ret, disk_io_job const& j,
|
void on_disk_read_get_piece_complete(int ret, disk_io_job const& j,
|
||||||
std::vector<std::string> *pieces, mutex *mut, condition_variable *cond, int *reqs);
|
std::vector<std::string> *pieces, mutex *mut, condition_variable *cond, int *reqs);
|
||||||
|
@ -168,7 +168,7 @@ namespace libtorrent
|
|||||||
enum flags_t { overwrite_existing = 1 };
|
enum flags_t { overwrite_existing = 1 };
|
||||||
void add_piece(int piece, char const* data, int size, int flags = 0) const;
|
void add_piece(int piece, char const* data, int size, int flags = 0) const;
|
||||||
void read_piece(int piece) const;
|
void read_piece(int piece) const;
|
||||||
void get_pieces(std::vector<std::string> &pieces, int count, int max_id, int since_id, uint32_t filter_flags) const;
|
void get_pieces(std::vector<std::string> &pieces, int count, int max_id, int since_id, uint32_t allowed_flags, uint32_t required_flags) const;
|
||||||
bool have_piece(int piece) const;
|
bool have_piece(int piece) const;
|
||||||
void recheck_pieces(uint32_t piece_flags) const;
|
void recheck_pieces(uint32_t piece_flags) const;
|
||||||
|
|
||||||
|
@ -916,9 +916,11 @@ namespace libtorrent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void torrent::get_pieces(std::vector<std::string> *pieces, int count, int max_id, int since_id, uint32_t filter_flags,
|
void torrent::get_pieces(std::vector<std::string> *pieces, int count, int max_id, int since_id, std::pair<uint32_t,uint32_t> flags,
|
||||||
mutex *mut, condition_variable *cond, int *reqs)
|
mutex *mut, condition_variable *cond, int *reqs)
|
||||||
{
|
{
|
||||||
|
uint32_t allowed_flags = flags.first;
|
||||||
|
uint32_t required_flags = flags.second;
|
||||||
if( !m_picker ) return;
|
if( !m_picker ) return;
|
||||||
|
|
||||||
max_id = std::min( max_id, m_picker->last_have() );
|
max_id = std::min( max_id, m_picker->last_have() );
|
||||||
@ -927,7 +929,8 @@ namespace libtorrent
|
|||||||
|
|
||||||
for( int i = max_id; i >= 0 && i > since_id && (*reqs) < count; i--) {
|
for( int i = max_id; i >= 0 && i > since_id && (*reqs) < count; i--) {
|
||||||
if( m_picker->have_piece(i) &&
|
if( m_picker->have_piece(i) &&
|
||||||
(m_picker->post_flags(i) & filter_flags) == m_picker->post_flags(i) ) {
|
(m_picker->post_flags(i) & allowed_flags) == m_picker->post_flags(i) &&
|
||||||
|
(m_picker->post_flags(i) & required_flags) == required_flags ) {
|
||||||
(*reqs)++;
|
(*reqs)++;
|
||||||
|
|
||||||
peer_request r;
|
peer_request r;
|
||||||
|
@ -823,7 +823,7 @@ namespace libtorrent
|
|||||||
TORRENT_ASYNC_CALL1(read_piece, piece);
|
TORRENT_ASYNC_CALL1(read_piece, piece);
|
||||||
}
|
}
|
||||||
|
|
||||||
void torrent_handle::get_pieces(std::vector<std::string> &pieces, int count, int max_id, int since_id, uint32_t filter_flags) const
|
void torrent_handle::get_pieces(std::vector<std::string> &pieces, int count, int max_id, int since_id, uint32_t allowed_flags, uint32_t required_flags) const
|
||||||
{
|
{
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
@ -831,7 +831,7 @@ namespace libtorrent
|
|||||||
libtorrent::condition_variable cond;
|
libtorrent::condition_variable cond;
|
||||||
int reqs = 0;
|
int reqs = 0;
|
||||||
|
|
||||||
TORRENT_SYNC_CALL8(get_pieces, &pieces, count, max_id, since_id, filter_flags, &mut, &cond, &reqs);
|
TORRENT_SYNC_CALL8(get_pieces, &pieces, count, max_id, since_id, std::make_pair(allowed_flags,required_flags), &mut, &cond, &reqs);
|
||||||
|
|
||||||
mutex::scoped_lock l2(mut);
|
mutex::scoped_lock l2(mut);
|
||||||
while( reqs > 0 ) {
|
while( reqs > 0 ) {
|
||||||
|
@ -1311,6 +1311,7 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri
|
|||||||
if (strMethod == "getposts" && n > 0) ConvertTo<boost::int64_t>(params[0]);
|
if (strMethod == "getposts" && n > 0) ConvertTo<boost::int64_t>(params[0]);
|
||||||
if (strMethod == "getposts" && n > 1) ConvertTo<Array>(params[1]);
|
if (strMethod == "getposts" && n > 1) ConvertTo<Array>(params[1]);
|
||||||
if (strMethod == "getposts" && n > 2) ConvertTo<boost::int64_t>(params[2]);
|
if (strMethod == "getposts" && n > 2) ConvertTo<boost::int64_t>(params[2]);
|
||||||
|
if (strMethod == "getposts" && n > 3) ConvertTo<boost::int64_t>(params[3]);
|
||||||
if (strMethod == "getdirectmsgs" && n > 1) ConvertTo<boost::int64_t>(params[1]);
|
if (strMethod == "getdirectmsgs" && n > 1) ConvertTo<boost::int64_t>(params[1]);
|
||||||
if (strMethod == "getdirectmsgs" && n > 2) ConvertTo<Array>(params[2]);
|
if (strMethod == "getdirectmsgs" && n > 2) ConvertTo<Array>(params[2]);
|
||||||
if (strMethod == "getmentions" && n > 1) ConvertTo<boost::int64_t>(params[1]);
|
if (strMethod == "getmentions" && n > 1) ConvertTo<boost::int64_t>(params[1]);
|
||||||
|
@ -1831,7 +1831,7 @@ int findLastPublicPostLocalUser( std::string strUsername )
|
|||||||
std::vector<std::string> pieces;
|
std::vector<std::string> pieces;
|
||||||
int max_id = std::numeric_limits<int>::max();
|
int max_id = std::numeric_limits<int>::max();
|
||||||
int since_id = -1;
|
int since_id = -1;
|
||||||
h.get_pieces(pieces, 1, max_id, since_id, ~USERPOST_FLAG_DM);
|
h.get_pieces(pieces, 1, max_id, since_id, ~USERPOST_FLAG_DM, 0);
|
||||||
|
|
||||||
if( pieces.size() ) {
|
if( pieces.size() ) {
|
||||||
string const& piece = pieces.front();
|
string const& piece = pieces.front();
|
||||||
@ -2105,15 +2105,17 @@ Value newrtmsg(const Array& params, bool fHelp)
|
|||||||
|
|
||||||
Value getposts(const Array& params, bool fHelp)
|
Value getposts(const Array& params, bool fHelp)
|
||||||
{
|
{
|
||||||
if (fHelp || params.size() < 2 || params.size() > 3)
|
if (fHelp || params.size() < 2 || params.size() > 4)
|
||||||
throw runtime_error(
|
throw runtime_error(
|
||||||
"getposts <count> '[{\"username\":username,\"max_id\":max_id,\"since_id\":since_id},...]' [flags]\n"
|
"getposts <count> '[{\"username\":username,\"max_id\":max_id,\"since_id\":since_id},...]' [allowed_flags] [required_flags]\n"
|
||||||
"get posts from users\n"
|
"get posts from users\n"
|
||||||
"max_id and since_id may be omited");
|
"max_id and since_id may be omited\n"
|
||||||
|
"(optional) allowed/required flags are bitwise fields (1=RT,2=DM)");
|
||||||
|
|
||||||
int count = params[0].get_int();
|
int count = params[0].get_int();
|
||||||
Array users = params[1].get_array();
|
Array users = params[1].get_array();
|
||||||
int flags = (params.size() > 2) ? params[2].get_int() : ~USERPOST_FLAG_DM;
|
int allowed_flags = (params.size() > 2) ? params[2].get_int() : ~USERPOST_FLAG_DM;
|
||||||
|
int required_flags = (params.size() > 3) ? params[3].get_int() : 0;
|
||||||
|
|
||||||
std::multimap<int64,entry> postsByTime;
|
std::multimap<int64,entry> postsByTime;
|
||||||
|
|
||||||
@ -2132,7 +2134,7 @@ Value getposts(const Array& params, bool fHelp)
|
|||||||
torrent_handle h = getTorrentUser(strUsername);
|
torrent_handle h = getTorrentUser(strUsername);
|
||||||
if( h.is_valid() ){
|
if( h.is_valid() ){
|
||||||
std::vector<std::string> pieces;
|
std::vector<std::string> pieces;
|
||||||
h.get_pieces(pieces, count, max_id, since_id, flags);
|
h.get_pieces(pieces, count, max_id, since_id, allowed_flags, required_flags);
|
||||||
|
|
||||||
BOOST_FOREACH(string const& piece, pieces) {
|
BOOST_FOREACH(string const& piece, pieces) {
|
||||||
lazy_entry v;
|
lazy_entry v;
|
||||||
@ -2900,7 +2902,7 @@ Value search(const Array& params, bool fHelp)
|
|||||||
|
|
||||||
BOOST_FOREACH(const PAIRTYPE(std::string,torrent_handle)& item, users) {
|
BOOST_FOREACH(const PAIRTYPE(std::string,torrent_handle)& item, users) {
|
||||||
std::vector<std::string> pieces;
|
std::vector<std::string> pieces;
|
||||||
item.second.get_pieces(pieces, std::numeric_limits<int>::max(), std::numeric_limits<int>::max(), -1, ~USERPOST_FLAG_DM);
|
item.second.get_pieces(pieces, std::numeric_limits<int>::max(), std::numeric_limits<int>::max(), -1, ~USERPOST_FLAG_DM, 0);
|
||||||
|
|
||||||
BOOST_FOREACH(string const& piece, pieces) {
|
BOOST_FOREACH(string const& piece, pieces) {
|
||||||
lazy_entry const* p = searcher.matchRawMessage(piece, v);
|
lazy_entry const* p = searcher.matchRawMessage(piece, v);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user