Первый фоллен на хелле (wildkin) wrote in changelog,
Первый фоллен на хелле
wildkin
changelog

[ljcom] r9904: LJSUP-7679: Twitter optimization

Committer: dnikolaev
LJSUP-7679: Twitter optimization

U   trunk/cgi-bin/LJ/Client/Twitter.pm
Modified: trunk/cgi-bin/LJ/Client/Twitter.pm
===================================================================
--- trunk/cgi-bin/LJ/Client/Twitter.pm	2011-01-13 09:41:36 UTC (rev 9903)
+++ trunk/cgi-bin/LJ/Client/Twitter.pm	2011-01-13 10:39:51 UTC (rev 9904)
@@ -11,6 +11,7 @@
 
 use LJ::Client::Twitter::Tweet;
 use LJ::Client::Twitter::User;
+require 'ljlang.pl';
 
 =head1 NAME
 
@@ -204,7 +205,9 @@
     my $api_method  = $opts{'api_method'};
     die 'API method not provided' unless $api_method;
 
-    if (my $u = $opts{'user'}) {
+    my $u = $opts{user};
+
+    if ($u) {
         $opts{'access_token'} = {
             'public' => $u->prop('twitter_access_token'),
             'secret' => $u->prop('twitter_access_token_secret'),
@@ -279,11 +282,31 @@
     }
 
     unless ($res->is_success) {
-        require Data::Dumper;
-        warn 'twitter connectivity error: ' .
-             Data::Dumper::Dumper($res);
+        if ($res->code eq '401' && $u) {
+            warn "twitter error: 401 Unauthorized\n";
 
-        die "twitter connectivity error";
+            $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";
+        } else {
+            require Data::Dumper;
+            warn 'twitter connectivity error: ' . Data::Dumper::Dumper($res);
+            die "twitter connectivity error";
+        }
     }
 
     return LJ::JSON->from_json($res->content);

Tags: ljcom, pm, wildkin
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