diff --git a/html/using.html b/html/using.html index 485d50e..3159de1 100644 --- a/html/using.html +++ b/html/using.html @@ -135,8 +135,8 @@
twitter_friends_poll - How often should the updated friends
- list be retrieved from the server. By default, only once every 10
+ twitter_friends_poll - How often should the updated friends and block
+ lists be retrieved from the server. By default, only once every 10
minutestwitter_timeout - How long should we wait before giving up
on a twitter operation. Should help avoid irssi pinging out of IRC
diff --git a/twirssi.pl b/twirssi.pl
index 9a0e2bd..9ba7027 100644
--- a/twirssi.pl
+++ b/twirssi.pl
@@ -34,8 +34,10 @@
my $poll;
my $last_poll;
my $last_friends_poll = 0;
+my $last_blocks_poll = 0;
my %nicks;
my %friends;
+my %blocks;
my %tweet_cache;
my %state;
my $failstatus = 0;
@@ -554,7 +556,7 @@ sub cmd_login {
return;
}
- %friends = %nicks = ();
+ %blocks = %friends = %nicks = ();
my $service;
if ( $user =~ /^(.*)@(twitter|identica)$/ ) {
@@ -758,10 +760,13 @@ sub verify_twitter_object {
Irssi::timeout_remove($poll) if $poll;
$poll = Irssi::timeout_add( &get_poll_time * 1000, \&get_updates, "" );
¬ice( [ "tweet", "$user\@$service" ],
- "Logged in as $user\@$service, loading friends list..." );
+ "Logged in as $user\@$service, loading friends list and blocks..." );
&load_friends();
¬ice( [ "tweet", "$user\@$service" ],
"loaded friends: " . scalar keys %friends );
+ &load_blocks();
+ ¬ice( [ "tweet", "$user\@$service" ],
+ "loaded blocks: " . scalar keys %blocks );
%nicks = %friends;
$nicks{$user} = 0;
@@ -1139,6 +1144,44 @@ sub load_friends {
return ( $added, $removed );
}
+sub load_blocks {
+ my $fh = shift;
+ my %new_blocks;
+ eval {
+ foreach my $t ( keys %twits ) {
+ print $fh "type:debug Loading blocks page ALL...\n"
+ if ( $fh and &debug );
+ my $blocks;
+ $blocks = $twits{$t}->blocking();
+ $new_blocks{ lc $_->{screen_name} } = time foreach @$blocks;
+ }
+ };
+
+ if ($@) {
+ print $fh "type:debug Error during blocks list update. Aborted.\n"
+ if $fh;
+ return;
+ }
+
+ my ( $added, $removed ) = ( 0, 0 );
+ print $fh "type:debug Scanning for new blocks...\n" if ( $fh and &debug );
+ foreach ( keys %new_blocks ) {
+ next if exists $blocks{$_};
+ $blocks{$_} = time;
+ $added++;
+ }
+
+ print $fh "type:debug Scanning for removed blocks...\n"
+ if ( $fh and &debug );
+ foreach ( keys %blocks ) {
+ next if exists $new_blocks{$_};
+ delete $blocks{$_};
+ $removed++;
+ }
+
+ return ( $added, $removed );
+}
+
sub get_updates {
print scalar localtime, " - get_updates starting" if &debug;
@@ -1206,6 +1249,23 @@ sub get_updates {
print $fh "$_ $friends{$_}\n";
}
+ print $fh "__blocks__\n";
+ if ( time - $last_blocks_poll > $settings{friends_poll} ) {
+ print $fh "__updated ", time, "\n";
+ my ( $added, $removed ) = &load_blocks($fh);
+ if ( $added + $removed ) {
+ print $fh "type:debug %R***%n Blocks list updated: ",
+ join( ", ",
+ sprintf( "%d added", $added ),
+ sprintf( "%d removed", $removed ) ),
+ "\n";
+ }
+ }
+
+ foreach ( sort keys %blocks ) {
+ print $fh "$_ $blocks{$_}\n";
+ }
+
if ($error) {
print $fh "type:debug Update encountered errors. Aborted\n";
print $fh "-- $last_poll";
@@ -1421,6 +1481,7 @@ sub do_updates {
$search->{max_id}, $username, $topic;
foreach my $t ( reverse @{ $search->{results} } ) {
+ next if exists $blocks{ lc $t->{from_user} };
my $text = &get_text( $t, $obj );
printf $fh "id:%s account:%s nick:%s type:search topic:%s %s\n",
$t->{id}, $username, $t->{from_user}, $topic, $text;
@@ -1457,6 +1518,8 @@ sub do_updates {
# TODO: consider applying ignore-settings to search results
my @results = @{ $search->{results} };
+
+ @results = grep { not exists $blocks{ lc $_->{from_user} } } @results;
if ( $max_results > 0 ) {
splice @results, $max_results;
}
@@ -1697,12 +1760,25 @@ sub monitor_child {
%friends = ();
while (