+sub get_timeline {
+ my ( $fh, $target, $username, $obj, $cache ) = @_;
+ print $fh "type:debug get_timeline($fix_replies_index{$username}=$target) started. username = $username\n";
+ my $tweets;
+ eval {
+ $tweets = $obj->user_timeline({id => $target});
+ };
+
+ if ($@) {
+ print $fh "type:debug Error during user_timeline($target) call: Aborted.\n";
+ print $fh "type:debug : $_\n" foreach split /\n/, Dumper($@);
+ return undef;
+ }
+
+ unless ($tweets) {
+ print $fh "type:debug user_timeline($target) call returned undef! Aborted\n";
+ return 1;
+ }
+
+ foreach my $t ( reverse @$tweets ) {
+ my $text = decode_entities( $t->{text} );
+ $text =~ s/[\n\r]/ /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;
+ unless ( $cache->{ $t->{in_reply_to_status_id} } ) {
+ eval {
+ $cache->{ $t->{in_reply_to_status_id} } =
+ $obj->show_status( $t->{in_reply_to_status_id} );
+ };
+
+ }
+ $context = $cache->{ $t->{in_reply_to_status_id} };
+
+ if ($context) {
+ my $ctext = decode_entities( $context->{text} );
+ $ctext =~ s/[\n\r]/ /g;
+ if ( $context->{truncated} and ref($obj) ne 'Net::Identica' ) {
+ $ctext .=
+ " -- http://twitter.com/$context->{user}{screen_name}"
+ . "/status/$context->{id}";
+ }
+ printf $fh "id:%s account:%s nick:%s type:tweet %s\n",
+ $context->{id}, $username,
+ $context->{user}{screen_name}, $ctext;
+ $reply = "reply";
+ }
+ }
+ if ( $t->{truncated} and ref($obj) ne 'Net::Identica' ) {
+ $text .= " -- http://twitter.com/$t->{user}{screen_name}"
+ . "/status/$t->{id}";
+ }
+ printf $fh "id:%s account:%s nick:%s type:%s %s\n",
+ $t->{id}, $username, $t->{user}{screen_name}, $reply, $text;
+ }
+
+ return 1;
+}
+