+ print scalar localtime, " - get_updates ends" if &debug;
+}
+
+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 $reply = "tweet";
+ 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 "id:%d account:%s nick:%s type:tweet %s\n",
+ $context->{id}, $username,
+ $context->{user}{screen_name}, $ctext;
+ $reply = "reply";
+ } else {
+ print "Failed to get context from $t->{in_reply_to_screen_name}"
+ if &debug;
+ }
+ }
+ next
+ if $t->{user}{screen_name} eq $username
+ and not Irssi::settings_get_bool("show_own_tweets");
+ printf $fh "id:%d account:%s nick:%s type:%s %s\n",
+ $t->{id}, $username, $t->{user}{screen_name}, $reply, $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 "id:%d account:%s nick:%s type:tweet %s\n",
+ $t->{id}, $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 "id:%d account:%s nick:%s type:dm %s\n",
+ $t->{id}, $username, $t->{sender_screen_name}, $text;
+ }
+ print scalar localtime, " - Done" if &debug;