Committer: afedorov
LJSUP-12834: If user has social capital equal 0 we shouldn't send ping back bot notification from this userU trunk/cgi-bin/TheSchwartz/Worker/NotifyPingbackServer.pm
Modified: trunk/cgi-bin/TheSchwartz/Worker/NotifyPingbackServer.pm =================================================================== --- trunk/cgi-bin/TheSchwartz/Worker/NotifyPingbackServer.pm 2012-07-17 10:31:56 UTC (rev 22459) +++ trunk/cgi-bin/TheSchwartz/Worker/NotifyPingbackServer.pm 2012-07-17 11:20:53 UTC (rev 22460) @@ -3,6 +3,7 @@ use base 'TheSchwartz::Worker'; use LJ::Entry; use LJ::PingBack; +use LJ::ExtBlock; sub work { my ($class, $job) = @_; @@ -27,7 +28,19 @@ my $source_entry = LJ::Entry->new_from_url($source_uri); return unless $source_entry; + + my $antispam_params = &_get_antispam_params(); + if ( $antispam_params->{enable_reader_weight} ) { + my $weight_data = LJ::PersonalStats::DB->fetch_raw('ratings', { + func => 'get_reader_weight', + journal_id => $source_entry->posterid, + }); + if ($weight_data && $weight_data->{status} eq 'Ok') { + return if $weight_data->{reader_weight} < $antispam_params->{min_reader_weight}; + } + } + my @links = ExtractLinksWithContext->do_parse($source_entry->event_raw); # use Data::Dumper; # warn "Links: " . Dumper(\@links); @@ -103,6 +116,29 @@ return 1; } +sub _get_antispam_params { + + my $result = { + enable_reader_weight => 0, + min_reader_weight => 0, + }; + + my $ext_block; + my $eval_res = eval { $ext_block = LJ::ExtBlock->load_by_id('antispam_params'); 1 }; + if ($eval_res) { + my $values = $ext_block ? LJ::JSON->from_json($ext_block->blocktext) : { c => {} }; + if ( $values->{c}->{enable_reader_weight} && $values->{c}->{min_reader_weight} ) { + $result->{enable_reader_weight} = $values->{c}->{enable_reader_weight}; + $result->{min_reader_weight} = $values->{c}->{min_reader_weight}; + } + } else { + warn $@; + } + + return $result; + +} + package ExtractLinksWithContext; use strict; use HTML::Parser;