+sub do_updates {
+ my ( $fh, $username, $obj ) = @_;
+
+ print scalar localtime, " - Polling for updates for $username" if DEBUG;
+ my $tweets =
+ $obj->friends_timeline( { since => HTTP::Date::time2str($last_poll) } )
+ || [];
+ foreach my $t ( reverse @$tweets ) {
+ my $text = decode_entities( $t->{text} );
+ $text =~ s/%/%%/g;
+ $text =~ s/(^|\W)\@([-\w]+)/$1%B\@$2%n/g;
+ my $prefix = "";
+ if ( Irssi::settings_get_bool("show_reply_context")
+ and $t->{in_reply_to_screen_name} ne $username
+ and $t->{in_reply_to_screen_name}
+ and not exists $friends{ $t->{in_reply_to_screen_name} } )
+ {
+ $nicks{ $t->{in_reply_to_screen_name} } = time;
+ my $context = $obj->show_status( $t->{in_reply_to_status_id} );
+ if ($context) {
+ my $ctext = decode_entities( $context->{text} );
+ $ctext =~ s/%/%%/g;
+ $ctext =~ s/(^|\W)\@([-\w]+)/$1%B\@$2%n/g;
+ printf $fh "[%s%%B\@%s%%n] %s\n",
+ ( $username ne $user ? "$username: " : "" ),
+ $context->{user}{screen_name}, $ctext;
+ $prefix = "\--> ";
+ }
+ }
+ next
+ if $t->{user}{screen_name} eq $username
+ and not Irssi::settings_get_bool("show_own_tweets");
+ printf $fh "%s[%s%%B\@%s%%n] %s\n",
+ $prefix,
+ ( $username ne $user ? "$username: " : "" ),
+ $t->{user}{screen_name},
+ $text;
+ }
+
+ print scalar localtime, " - Polling for replies" if DEBUG;
+ $tweets = $obj->replies( { since => HTTP::Date::time2str($last_poll) } )
+ || [];
+ foreach my $t ( reverse @$tweets ) {
+ next
+ if exists $friends{ $t->{user}{screen_name} };
+
+ my $text = decode_entities( $t->{text} );
+ $text =~ s/%/%%/g;
+ $text =~ s/(^|\W)\@([-\w]+)/$1%B\@$2%n/g;
+ printf $fh "[%s%%B\@%s%%n] %s\n",
+ ( $username ne $user ? "$username: " : "" ),
+ $t->{user}{screen_name},
+ $text;
+ }
+
+ print scalar localtime, " - Polling for DMs" if DEBUG;
+ $tweets =
+ $obj->direct_messages( { since => HTTP::Date::time2str($last_poll) } )
+ || [];
+ foreach my $t ( reverse @$tweets ) {
+ my $text = decode_entities( $t->{text} );
+ $text =~ s/%/%%/g;
+ $text =~ s/(^|\W)\@([-\w]+)/$1%B\@$2%n/g;
+ printf $fh "[%s%%B\@%s%%n (%%WDM%%n)] %s\n",
+ ( $username ne $user ? "$username: " : "" ),
+ $t->{sender_screen_name},
+ $text;
+ }
+ print scalar localtime, " - Done" if DEBUG;
+}
+