Changeset 40def31a for perl


Ignore:
Timestamp:
May 20, 2020, 7:21:29 PM (4 years ago)
Author:
GitHub <noreply@github.com>
Parents:
9a0d25d (diff), 834dc31 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Alex Dehnert <adehnert@mit.edu> (05/20/20 19:21:29)
git-committer:
GitHub <noreply@github.com> (05/20/20 19:21:29)
Message:
Merge 834dc312682e1820f1f2fa826ea9040caea8813f into 9a0d25d1513e92f2b0c99d89ab5fc5ae2c061151
Location:
perl
Files:
2 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • perl/modules/Twitter/lib/BarnOwl/Message/Twitter.pm

    r8106870 r1f69b54  
    3333    if($self->is_private) {
    3434        return $self->replysendercmd;
    35     } elsif(exists($self->{status_id})) {
    36         return BarnOwl::quote('twitter-atreply', $self->sender, $self->{status_id}, $self->account);
     35    }
     36    # Roughly, this is how Twitter's @-reply calculation works
     37    # (based on a few experiments)
     38    #
     39    #   1. The person who wrote the tweet you are replying to is added.
     40    #      This is the only time when your own name can show up in an
     41    #      at-reply string.
     42    #   2. Next, Twitter goes through the Tweet front to back, adding
     43    #      mentioned usernames that have not already been added to the
     44    #      string.
     45    #
     46    # In degenerate cases, the at-reply string might be longer than
     47    # the max Tweet size; Twitter doesn't care.
     48
     49    # XXX A horrifying violation of encapsulation
     50    # NB: names array includes @-signs.
     51    my $account = BarnOwl::Module::Twitter::find_account_default($self->{account});
     52    my @inside_names = grep($_ ne ("@" . $account->{cfg}->{user}),
     53                            $self->{body} =~ /(?:^|\s)(@\w+)/g );
     54    my @dup_names = ( ( "@" . $self->sender ), @inside_names );
     55
     56    # XXX Really should use List::MoreUtils qw(uniq).  This code snippet
     57    # lifted from `perldoc -q duplicate`.
     58    my %seen = ();
     59    my @names = grep { ! $seen{ $_ }++ } @dup_names;
     60    my $prefill = join(' ', @names) . ' '; # NB need trailing space
     61
     62    if(exists($self->{status_id})) {
     63        return BarnOwl::quote('twitter-prefill', $prefill, $self->{status_id}, $self->account);
    3764    } else {
    38         return BarnOwl::quote('twitter-atreply', $self->sender, $self->account);
     65        # Give a dummy status ID
     66        return BarnOwl::quote('twitter-prefill', $prefill, '', $self->account);
    3967    }
    4068}
  • perl/modules/Twitter/lib/BarnOwl/Module/Twitter.pm

    r140429f r1f69b54  
    243243BarnOwl::new_command(twitter => \&cmd_twitter, {
    244244    summary     => 'Update Twitter from BarnOwl',
    245     usage       => 'twitter [ACCOUNT] [MESSAGE]',
     245    usage       => 'twitter [ACCOUNT [MESSAGE]]',
    246246    description => 'Update Twitter on ACCOUNT. If MESSAGE is provided, use it as your status.'
    247247    . "\nIf no ACCOUNT is provided, update all services which have publishing enabled."
     
    259259    {
    260260    summary     => 'Send a Twitter @ message',
    261     usage       => 'twitter-atreply USER [ACCOUNT]',
     261    usage       => 'twitter-atreply USER [ID [ACCOUNT]]',
    262262    description => 'Send a Twitter @reply Message to USER on ACCOUNT (defaults to default_sender,'
     263    . "\nor first service if no default is provided)"
     264    }
     265);
     266
     267BarnOwl::new_command( 'twitter-prefill' => sub { cmd_twitter_prefill(@_); },
     268    {
     269    summary     => 'Send a Twitter message with prefilled text',
     270    usage       => 'twitter-prefill PREFILL [ID [ACCOUNT]]',
     271    description => 'Send a Twitter message with initial text PREFILL on ACCOUNT (defaults to default_sender,'
    263272    . "\nor first service if no default is provided)"
    264273    }
     
    356365                            sub { $account->twitter_atreply($user, $id, shift) });
    357366    BarnOwl::Editwin::insert_text("\@$user ");
     367}
     368
     369sub cmd_twitter_prefill {
     370    my $cmd  = shift;
     371    # prefill is responsible for spacing
     372    my $prefill = shift || die("Usage: $cmd PREFILL [In-Reply-To ID]\n");
     373    my $id   = shift;
     374    my $account = find_account_default(shift);
     375
     376    my $msg = "What's happening?";
     377    if ($id) {
     378        # So, this isn't quite semantically correct, but it's close
     379        # enough, and under the planned use-case, it will look identical.
     380        $msg = "Reply to " . $prefill;
     381    }
     382    if ($account->nickname) {
     383        # XXX formatting slightly suboptimal on What's happening message;
     384        # and the behavior does not match up with 'twitter' anyhoo,
     385        # which doesn't dispatch through account_find_default
     386        $msg .= " on " . $account->nickname;
     387    }
     388    BarnOwl::start_edit_win($msg,
     389                            sub { $account->twitter_atreply(undef, $id, shift) });
     390    BarnOwl::Editwin::insert_text($prefill);
    358391}
    359392
  • perl/modules/Twitter/lib/BarnOwl/Module/Twitter/Handle.pm

    r140429f r834dc31  
    290290            $orig = $tweet unless defined($orig);
    291291
     292            my $url = $self->{cfg}->{service} . '/' . $orig->{user}{screen_name} . '/status/' . $tweet->{id};
    292293            my $msg = BarnOwl::Message->new(
    293294                type      => 'Twitter',
     
    299300                body      => decode_entities($orig->{text}),
    300301                status_id => $tweet->{id},
     302                url       => $url,
    301303                service   => $self->{cfg}->{service},
    302304                account   => $self->{cfg}->{account_nickname},
  • perl/Makefile.am

    reea7bed4 r4fd3c04  
    22nobase_dist_pkgdata_DATA = \
    33        lib/BarnOwl.pm \
    4         lib/BarnOwl/Complete/AIM.pm \
    54        lib/BarnOwl/Complete/Client.pm \
    65        lib/BarnOwl/Complete/Filter.pm \
     
    1716        lib/BarnOwl/MainLoopCompatHook.pm \
    1817        lib/BarnOwl/Message.pm \
    19         lib/BarnOwl/Message/AIM.pm \
    2018        lib/BarnOwl/Message/Admin.pm \
    2119        lib/BarnOwl/Message/Generic.pm \
  • perl/lib/BarnOwl/Complete/Filter.pm

    r6dba228 r4fd3c04  
    3636    body      => undef,
    3737    hostname  => undef,
    38     type      => sub { qw(zephyr aim admin); },
     38    type      => sub { qw(zephyr admin); },
    3939    direction => sub { qw(in out none); },
    4040    login     => sub { qw(login logout none); },
  • perl/lib/BarnOwl/Logging.pm

    rb807d8f r4fd3c04  
    7575            summary     => 'enable logging of login notifications',
    7676            description => "When this is enabled, BarnOwl will log login and logout notifications\n"
    77                          . "for AIM, zephyr, or other protocols.  If disabled BarnOwl will not log\n"
     77                         . "for zephyr or other protocols.  If disabled BarnOwl will not log\n"
    7878                         . "login or logout notifications."
    7979        });
  • perl/lib/BarnOwl/Message.pm

    r5dee79a r4fd3c04  
    77
    88use BarnOwl::Message::Admin;
    9 use BarnOwl::Message::AIM;
    109use BarnOwl::Message::Generic;
    1110use BarnOwl::Message::Loopback;
     
    4342sub is_generic  { return (shift->{"type"} eq "generic"); }
    4443sub is_zephyr   { return (shift->{"type"} eq "zephyr"); }
    45 sub is_aim      { return (shift->{"type"} eq "AIM"); }
     44sub is_aim      { return ''; }
    4645sub is_jabber   { return (shift->{"type"} eq "jabber"); }
    4746sub is_icq      { return (shift->{"type"} eq "icq"); }
Note: See TracChangeset for help on using the changeset viewer.