+sub get_timeline {
+ my ( $fh, $target, $username, $obj, $cache ) = @_;
+ my $tweets;
+ my $last_id = $id_map{__last_id}{$username}{$target};
+
+ print $fh "type:debug get_timeline("
+ . "$fix_replies_index{$username}=$target > $last_id) started."
+ . " username = $username\n";
+ eval {
+ $tweets = $obj->user_timeline(
+ {
+ id => $target,
+ ( $last_id ? ( since_id => $last_id ) : () ),
+ }
+ );
+ };
+
+ 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 = &get_text( $t, $obj );
+ 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 = &get_text( $context, $obj );
+ printf $fh "id:%s account:%s nick:%s type:tweet %s\n",
+ $context->{id}, $username,
+ $context->{user}{screen_name}, $ctext;
+ $reply = "reply";
+ }
+ }
+ printf $fh "id:%s account:%s nick:%s type:%s %s\n",
+ $t->{id}, $username, $t->{user}{screen_name}, $reply, $text;
+ $last_id = $t->{id} if $last_id < $t->{id};
+ }
+ printf $fh "id:%s account:%s type:last_id_fixreplies %s\n",
+ $last_id, $username, $target;
+
+ return 1;
+}
+