журнал (shhh) wrote in changelog,
журнал
shhh
changelog

[ljcom] r11737: LJSV-1266: Twitter digest doesn't work f...

Committer: nnikulochkina
LJSV-1266: Twitter digest doesn't work for some users
Code tidy.
U   trunk/cgi-bin/LJ/Client/Twitter.pm
U   trunk/cgi-bin/LJ/TwitterDigest.pm
Modified: trunk/cgi-bin/LJ/Client/Twitter.pm
===================================================================
--- trunk/cgi-bin/LJ/Client/Twitter.pm	2012-04-20 06:16:39 UTC (rev 11736)
+++ trunk/cgi-bin/LJ/Client/Twitter.pm	2012-04-20 06:54:57 UTC (rev 11737)
@@ -274,7 +274,7 @@
                                 'timeout' => $LJ::TWITTER_API_TIMEOUT, );
     my $post_params;
     if ($http_method eq 'POST') {
-	##
+        ##
         ## turn UTF-8 flag OFF here,
         ## TODO: what to do with GET requests?
         ##
@@ -287,48 +287,48 @@
     my $retry_number = $LJ::TWITTER_API_RETRY->{$api_method} || 1;
 
   RETRY:
-    while($retry_number){
+    while($retry_number) {
         my $res = ( $http_method eq 'GET' ) ? 
             $ua->get($request->to_url) : 
             $ua->post($request_url, $post_params);
-	
-	if ($res->is_success) {
-	    return LJ::JSON->from_json($res->content);
-	} else {
-	    if ($res->code eq '401' && $u) {
-		$u->log_event ("twitter_failed", { text => '401 Unauthorized' } )
-		    if $opts{'call_from_digest'};
-                
-		$u->clear_prop($_)
-		    foreach qw(
-			       twitter_access_token
-			       twitter_access_token_secret
-			       twitter_name
-			       twitter_link
-			       );
-                
-		my $lang = $u->prop('browselang') || $LJ::DEFAULT_LANG;
-		LJ::send_mail( {
-		    to       => $u->email_raw,
-		    from     => $LJ::BOGUS_EMAIL,
-		    wrap     => 1,
-		    charset  => $u->mailencoding || 'utf-8',
-		    subject  => LJ::Lang::get_text($lang, 'twitter.disconnect_letter.subject', undef),
-		    body     => LJ::Lang::get_text($lang, 'twitter.disconnect_letter.body', undef, { user => $u->username }),
-		} ) or warn "Unable to send_mail";
-		die "twitter error: 401 Unauthorized\n";
-	    } else {
-		$u->log_event ("twitter_failed", { text => $res->status_line } )
-		    if $opts{'call_from_digest'};
-		if( $res->code eq '502' && --$retry_number ){
+
+        if ($res->is_success) {
+            return LJ::JSON->from_json($res->content);
+        } else {
+            if ($res->code eq '401' && $u) {
+                $u->log_event ("twitter_failed", { text => '401 Unauthorized' } )
+                    if $opts{'call_from_digest'};
+
+                $u->clear_prop($_)
+                    foreach qw(
+                               twitter_access_token
+                               twitter_access_token_secret
+                               twitter_name
+                               twitter_link
+                               );
+
+                my $lang = $u->prop('browselang') || $LJ::DEFAULT_LANG;
+                LJ::send_mail( {
+                    to       => $u->email_raw,
+                    from     => $LJ::BOGUS_EMAIL,
+                    wrap     => 1,
+                    charset  => $u->mailencoding || 'utf-8',
+                    subject  => LJ::Lang::get_text($lang, 'twitter.disconnect_letter.subject', undef),
+                    body     => LJ::Lang::get_text($lang, 'twitter.disconnect_letter.body', undef, { user => $u->username }),
+                } ) or warn "Unable to send_mail";
+                die "twitter error: 401 Unauthorized\n";
+            } else {
+                $u->log_event ("twitter_failed", { text => $res->status_line } )
+                    if $opts{'call_from_digest'};
+                if( $res->code eq '502' && --$retry_number ) {
                     sleep 1;
-		    next RETRY;
-		} else {
-		    die "twitter connectivity error: " . $res->status_line;
-		}
-	    }
-	    return undef;
-	}
+                    next RETRY;
+                } else {
+                    die "twitter connectivity error: " . $res->status_line;
+                }
+            }
+            return undef;
+        }
     }
 }
 
@@ -398,7 +398,7 @@
     ## The real problem is that LJ::get_db_writer() doesn't check
     ## cached connection handle before returning it.
     ##
-    LJ::start_request();   
+    LJ::start_request();
 
     my $dbh = LJ::get_db_writer();
     $dbh->{'RaiseError'} = 1;
@@ -461,12 +461,12 @@
         # if they don't have a token, return an empty result
         return [];
     }
-    
+
     my $params =  { 'count'       => $LJ::TWITTER_RECENT_FEED_DEPTH,
                     'include_rts' => 1, # with retweets
                   };
     $params->{'since_id'} = $u->{'last_tweet_id'} if $u->{'last_tweet_id'};
-    
+
     my $min_post_time = time - 86400;
 
     my @tweets;
@@ -474,18 +474,18 @@
 
   TW_PART:
     until ( $res && scalar(@$res) < $params->{count} ) {
-     	$res = LJ::Client::Twitter->call(
-		    'api_method' => 'statuses/user_timeline',
+        $res = LJ::Client::Twitter->call(
+                    'api_method' => 'statuses/user_timeline',
                     'user' => $u,
                     'http_method' => 'GET',
                     'params' => $params,
                     %$opts,
         );
 
-	return [] unless $res;
-	
-	return \@tweets unless @$res;
-	
+        return [] unless $res;
+
+        return \@tweets unless @$res;
+
         foreach (@$res) {
             next if $_->{in_reply_to_status_id};
             my $tw = LJ::Client::Twitter::Tweet->from_hash($_);
@@ -495,7 +495,7 @@
 
         my $oldest_tw = LJ::Client::Twitter::Tweet->from_hash( $res->[-1] );
         last TW_PART if $oldest_tw->post_time < $min_post_time;
-        
+
         $params->{max_id} = $oldest_tw->id - 1;
     }
 

Modified: trunk/cgi-bin/LJ/TwitterDigest.pm
===================================================================
--- trunk/cgi-bin/LJ/TwitterDigest.pm	2012-04-20 06:16:39 UTC (rev 11736)
+++ trunk/cgi-bin/LJ/TwitterDigest.pm	2012-04-20 06:54:57 UTC (rev 11737)
@@ -220,21 +220,21 @@
     my $twu = LJ::Client::Twitter->get_userinfo( 'user' => $u, 'call_from_digest' => 1 );
     
     unless ( $twu ) {
-	unless ( LJ::Client::Twitter->get_user_access_token($u) ) {
-	    
-	    # we don't have twitter access tokens
-	    # set TwitterDigest disabled for this user
-	    LJ::TwitterDigest->disable_for_user($u);
-	    die "Can't get twitter access tokens for user. Set digest disabled.";
+        unless ( LJ::Client::Twitter->get_user_access_token($u) ) {
+            
+            # we don't have twitter access tokens
+            # set TwitterDigest disabled for this user
+            LJ::TwitterDigest->disable_for_user($u);
+            die "Can't get twitter access tokens for user. Set digest disabled.";
 
-	} else {
-	    die "Unexpected empty userinfo";
-	}
+        } else {
+            die "Unexpected empty userinfo";
+        }
     }
     
     if( $twu->protected ) {
-	$u->log_event ("twitter_skipped", { text => "Twitter account is protected" });
-	return;
+        $u->log_event ("twitter_skipped", { text => "Twitter account is protected" });
+        return;
     }
 
     if (my $u_system = LJ::load_user('system')) {

Tags: ljcom, nikulochkina, nnikulochkina, pm
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments