Changeset 8b62088
- Timestamp:
- Sep 20, 2011, 11:15:31 PM (13 years ago)
- Branches:
- master, release-1.10, release-1.9
- Children:
- 65c2b3c
- Parents:
- eb20731
- git-author:
- Edward Z. Yang <ezyang@mit.edu> (06/22/11 18:30:55)
- git-committer:
- Edward Z. Yang <ezyang@mit.edu> (09/20/11 23:15:31)
- Location:
- perl/modules/Facebook
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
perl/modules/Facebook/README
r4b23009 r8b62088 32 32 and blocks the entire BarnOwl interface. We need to confront 33 33 Perl's threading demon. 34 * Need to detect if you have two friends with the same name and 35 disambiguate if so. 36 * No messaging support. 37 * No auto-completion support. 38 * No posting to an arbitrary user's wall. 39 * See code comments for more work items! 34 * No messaging support. (We'll add it when Facebook makes the new endpoint.) 35 * Smarter name de-duplication (see code comments for details.) 36 * Grep for XXX and TODO for more work items. 40 37 41 38 TECHNICAL NOTES -
perl/modules/Facebook/lib/BarnOwl/Module/Facebook.pm
reb497a9 r8b62088 123 123 sub cmd_facebook { 124 124 my $cmd = shift; 125 BarnOwl::start_edit_win("What's on your mind?", sub{ facebook(shift) }); 126 # User prompt for other person's wall is "Write something..." which 127 # we will ostensibly check for soon. 125 my $user = shift; 126 127 BarnOwl::start_edit_win( 128 defined $user ? "Write something to $user..." : "What's on your mind?", 129 sub{ facebook($user, shift) } 130 ); 128 131 } 129 132 … … 156 159 BarnOwl::filter(qw{facebook type ^facebook$}); 157 160 161 # Autocompletion support 162 163 sub complete_user { return keys %{$facebook_handle->{friends}}; } 164 BarnOwl::Completion::register_completer(facebook => sub { complete_user(@_) }); 165 158 166 1; -
perl/modules/Facebook/lib/BarnOwl/Module/Facebook/Handle.pm
reb20731 r8b62088 80 80 'facebook' => undef, 81 81 82 # Ideally this should be done using Facebook realtime updates, 83 # but we can't assume that the BarnOwl lives on a publically 84 # addressable server (XXX maybe we can setup an option for this.) 85 'last_friend_poll' => 0, 86 'friend_timer' => undef, 87 82 88 # Initialized with our 'time', but will be synced to Facebook 83 # soon enough. 89 # soon enough. (Subtractive amount is just to preseed with some 90 # values.) 84 91 'last_poll' => time - 60 * 60 * 24 * 2, 85 92 'timer' => undef, … … 100 107 # would need another hash for topic de-dup 101 108 'topics' => {}, 109 110 # deduplicated map of names to user ids 111 'friends' => {}, 102 112 }; 103 113 … … 125 135 126 136 # Stop any existing timers. 137 if (defined $self->{friend_timer}) { 138 $self->{friend_timer}->stop; 139 $self->{friend_timer} = undef; 140 } 127 141 if (defined $self->{timer}) { 128 142 $self->{timer}->stop; … … 135 149 } 136 150 151 $self->{friend_timer} = BarnOwl::Timer->new({ 152 name => "Facebook friend poll", 153 after => $delay, 154 interval => 60 * 60 * 24, 155 cb => sub { $weak->poll_friends if $weak } 156 }); 137 157 $self->{timer} = BarnOwl::Timer->new({ 138 158 name => "Facebook poll", … … 142 162 }); 143 163 # XXX implement message polling 164 } 165 166 sub poll_friends { 167 my $self = shift; 168 169 return unless BarnOwl::getvar('facebook:poll') eq 'on'; 170 return unless $self->{logged_in}; 171 172 my $friends = eval { $self->{facebook}->fetch('me/friends'); }; 173 if ($@) { 174 warn "Poll failed $@"; 175 return; 176 } 177 178 $self->{last_friend_poll} = time; 179 $self->{friends} = {}; 180 181 for my $friend ( @{$friends->{data}} ) { 182 if (defined $self->{friends}{$friend->{name}}) { 183 # XXX We should try a little harder here, rather than just 184 # tacking on a number. Ideally, we should be able to 185 # calculate some extra piece of information that the user 186 # needs to disambiguate between the two users. An old 187 # version of Facebook used to disambiguate with your primary 188 # network (so you might have Edward Yang (MIT) and Edward 189 # Yang (Cambridge), the idea being that users in the same 190 # network would probably have already disambiguated 191 # themselves with middle names or nicknames. We no longer 192 # get network information, since Facebook axed that 193 # information, but the Education/Work fields may still be 194 # a reasonable approximation (but which one do you pick?! 195 # The most recent one.) Since getting this information 196 # involves extra queries, there are also caching and 197 # efficiency concerns. 198 # We may want a facility for users to specify custom 199 # aliases for Facebook users, which are added into this 200 # hash. See also username support. 201 warn "Duplicate friend name " . $friend->{name}; 202 my $name = $friend->{name}; 203 my $i = 2; 204 while (defined $self->{friends}{$friend->{name} . ' ' . $i}) { $i++; } 205 $self->{friends}{$friend->{name} . ' ' . $i} = $friend->{id}; 206 } else { 207 $self->{friends}{$friend->{name}} = $friend->{id}; 208 } 209 } 210 211 # XXX We should also have support for usernames, and not just real 212 # names. However, since this data is not returned by the friends 213 # query, it would require a rather expensive set of queries. We 214 # might try to preserve old data, but all-in-all it's a bit 215 # complicated, so we don't bother. 144 216 } 145 217 … … 283 355 my $self = shift; 284 356 357 my $user = shift; 285 358 my $msg = shift; 286 my $reply_to = shift;287 359 288 360 if (!defined $self->{facebook} || !$self->{logged_in}) { … … 290 362 return; 291 363 } 292 $self->{facebook}->add_post->set_message( $msg )->publish; 364 if (defined $user) { 365 $user = $self->{friends}{$user} || $user; 366 $self->{facebook}->add_post( $user )->set_message( $msg )->publish; 367 } else { 368 $self->{facebook}->add_post->set_message( $msg )->publish; 369 } 293 370 $self->sleep(0); 294 371 }
Note: See TracChangeset
for help on using the changeset viewer.