Add new setting - twitter_timeout, defaults to 30 seconds. Requests that take longer...
[twirssi-net-twitter-lite.git] / twirssi.pl
index 1f0f895067c53f1d30a9f1512c00735aaa5f61b3..331715ce03737fbfe13a9606df4d34fc16799292 100644 (file)
@@ -499,6 +499,15 @@ sub cmd_login {
         ssl      => Irssi::settings_get_bool("twirssi_avoid_ssl") ? 0 : 1,
     );
 
+    unless ($twit) {
+        &notice("Failed to create Net::$service object!  Aborting.");
+        return;
+    }
+
+    if ( my $timeout = Irssi::settings_get_int("twitter_timeout") ) {
+        $twit->ua->timeout($timeout);
+    }
+
     unless ( $twit->verify_credentials() ) {
         &notice("Login as $user\@$service failed");
         $twit = undef;
@@ -910,7 +919,9 @@ sub do_updates {
     printf $fh "id:%u account:%s type:last_id timeline\n",
       $new_poll_id, $username;
 
-    print scalar localtime, " - Polling for replies" if &debug;
+    print scalar localtime, " - Polling for replies since ",
+      $id_map{__last_id}{$username}{reply}
+      if &debug;
     $new_poll_id = 0;
     eval {
         if ( $id_map{__last_id}{$username}{reply} )
@@ -1032,7 +1043,7 @@ sub monitor_child {
     # pretend
 
     if ( open FILE, $filename ) {
-        bindmode FILE, ":utf8";
+        binmode FILE, ":utf8";
         my @lines;
         my %new_cache;
         while (<FILE>) {
@@ -1163,8 +1174,16 @@ sub monitor_child {
             }
 
             if (/^-- (\d+)$/) {
-                ($new_last_poll) = ($1);
-                last;
+                $new_last_poll = $1;
+                if ( $new_last_poll >= $last_poll ) {
+                    last;
+                } else {
+                    print "Impossible!  ",
+                      "new_last_poll=$new_last_poll < last_poll=$last_poll!"
+                      if &debug;
+                    undef $new_last_poll;
+                    next;
+                }
             }
             my ( $f, $t ) = split ' ', $_;
             $nicks{$f} = $friends{$f} = $t;
@@ -1501,6 +1520,7 @@ Irssi::settings_add_str( "twirssi", "twirssi_replies_store",
     ".irssi/scripts/twirssi.json" );
 
 Irssi::settings_add_int( "twirssi", "twitter_friends_poll", 600 );
+Irssi::settings_add_int( "twirssi", "twitter_timeout", 30 );
 
 Irssi::settings_add_bool( "twirssi", "twirssi_upgrade_beta",      0 );
 Irssi::settings_add_bool( "twirssi", "tweet_to_away",             0 );