Changeset 8462b38


Ignore:
Timestamp:
Aug 15, 2009, 2:32:16 PM (12 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.7, release-1.8, release-1.9
Children:
385dd69
Parents:
4bd9327
Message:
Replace do_with_default_account with find_account_default

Remove the twitter_FOO helpers in Twitter.pm, since the extra layer of
indirection doesn't seem to gain us anything and is somewhat confusing,
and make the cmd_FOO subs lookup the accout with find_account_default.

Note that at startup, we always set the $default_handle, so there's no
need to fall back to $twitter_handles[0].
Location:
lib/BarnOwl/Module
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lib/BarnOwl/Module/Twitter.pm

    r4bd9327 r8462b38  
    171171}
    172172
     173sub find_account_default {
     174    my $name = shift;
     175    if(defined($name)) {
     176        return find_account($name);
     177    } else {
     178        return $default_handle;
     179    }
     180}
     181
    173182sub twitter {
    174183    my $account = shift;
     
    187196}
    188197
    189 # do_for_default_account( SUB( HANDLE, ARGS...), ACCOUNT, ARGS... )
    190 sub do_for_default_account {
    191     my $lambda = shift;
    192     die ("do_for_default_account has nothing to do") unless defined $lambda && ref($lambda) eq 'CODE';
    193     my $account = shift;
    194 
    195     if (defined $account) {
    196         my $handle = find_account($account);
    197         $lambda->($handle, @_);
    198     } elsif (defined $default_handle) {
    199         $lambda->($default_handle, @_);
    200     }
    201     else {
    202         $lambda->($twitter_handles[0], @_);
    203     }
    204 }
    205 
    206 sub twitter_direct {
    207     my $account = shift;
    208     do_for_default_account( sub { my $handle = shift; $handle->twitter_direct(@_); }, $account, @_);
    209 }
    210 
    211 sub twitter_atreply {
    212     my $account = shift;
    213     do_for_default_account( sub { my $handle = shift; $handle->twitter_atreply(@_); }, $account, @_);
    214 }
    215 
    216 sub twitter_follow {
    217     my $account = shift;
    218     do_for_default_account( sub { my $handle = shift; $handle->twitter_follow(@_); }, $account, @_);
    219 }
    220 
    221 sub twitter_unfollow {
    222     my $account = shift;
    223     do_for_default_account( sub { my $handle = shift; $handle->twitter_unfollow(@_); }, $account, @_);
    224 }
    225 
    226198BarnOwl::new_command(twitter => \&cmd_twitter, {
    227199    summary     => 'Update Twitter from BarnOwl',
     
    283255    my $user = shift;
    284256    die("Usage: $cmd USER\n") unless $user;
    285     my $account = shift;
    286     BarnOwl::start_edit_win("$cmd $user" . (defined $account ? " $account" : ""), sub{twitter_direct($account, $user, shift)});
     257    my $account = find_account_default(shift);
     258    BarnOwl::start_edit_win("$cmd $user " . ($account->nickname||""),
     259                            sub { $account->twitter_direct($user, shift) });
    287260}
    288261
     
    291264    my $user = shift || die("Usage: $cmd USER [In-Reply-To ID]\n");
    292265    my $id   = shift;
    293     my $account = shift;
    294     BarnOwl::start_edit_win("Reply to \@" . $user . (defined $account ? " on $account" : ""), sub { twitter_atreply($account, $user, $id, shift) });
     266    my $account = find_account_default(shift);
     267
     268    BarnOwl::start_edit_win("Reply to \@" . $user . ($account->nickname ? (" on " . $account->nickname) : ""),
     269                            sub { $account->twitter_atreply($user, $id, shift) });
    295270}
    296271
     
    300275    die("Usage: $cmd USER\n") unless $user;
    301276    my $account = shift;
    302     twitter_follow($account, $user);
     277    find_account_default($account)->twitter_follow($user);
    303278}
    304279
     
    308283    die("Usage: $cmd USER\n") unless $user;
    309284    my $account = shift;
    310     twitter_unfollow($account, $user);
     285    find_account_default($account)->twitter_unfollow($user);
    311286}
    312287
  • lib/BarnOwl/Module/Twitter/Handle.pm

    r513da71 r8462b38  
    280280}
    281281
     282sub nickname {
     283    my $self = shift;
     284    return $self->{cfg}->{account_nickname};
     285}
     286
    2822871;
Note: See TracChangeset for help on using the changeset viewer.