Changeset 1f69b54 for perl/modules/Twitter/lib/BarnOwl/Message/Twitter.pm
- Timestamp:
- Aug 20, 2017, 4:38:40 PM (8 years ago)
- Children:
- 834dc31
- Parents:
- 38c584e
- git-author:
- Edward Z. Yang <ezyang@cs.stanford.edu> (03/22/14 03:08:15)
- git-committer:
- Alex Dehnert <adehnert@mit.edu> (08/20/17 16:38:40)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
perl/modules/Twitter/lib/BarnOwl/Message/Twitter.pm
r38c584e r1f69b54 33 33 if($self->is_private) { 34 34 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); 37 64 } else { 38 65 # Give a dummy status ID 39 return BarnOwl::quote('twitter- atreply', $self->sender, '', $self->account);66 return BarnOwl::quote('twitter-prefill', $prefill, '', $self->account); 40 67 } 41 68 }
Note: See TracChangeset
for help on using the changeset viewer.