Changeset 7efa163 for perl/modules/Facebook
- Timestamp:
- Sep 20, 2011, 11:15:33 PM (13 years ago)
- Branches:
- master, release-1.10, release-1.9
- Children:
- f4037cf
- Parents:
- 1d11b78
- git-author:
- Edward Z. Yang <ezyang@mit.edu> (07/30/11 23:27:31)
- git-committer:
- Edward Z. Yang <ezyang@mit.edu> (09/20/11 23:15:33)
- Location:
- perl/modules/Facebook/lib/BarnOwl/Module
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
perl/modules/Facebook/lib/BarnOwl/Module/Facebook.pm
r395d304 r7efa163 61 61 #BarnOwl::new_command('facebook-message' => \&cmd_facebook_direct, { 62 62 # summary => 'Send a Facebook message', 63 # usage => ' twitter-directUSER',64 # description => 'Send a private Facebook Message to USER.'63 # usage => 'facebook-message USER', 64 # description => 'Send a private Facebook message to USER.' 65 65 #}); 66 66 … … 93 93 BarnOwl::start_edit_win( 94 94 defined $user ? "Write something to $user..." : "What's on your mind?", 95 sub { $facebook_handle->facebook($user, shift) }95 sub { $facebook_handle->facebook($user, shift) } 96 96 ); 97 97 } … … 132 132 sub check_ready { 133 133 if (!$facebook_handle->{logged_in}) { 134 BarnOwl::message(" Need to login to Facebook first with ':facebook-auth'.");134 BarnOwl::message("You need to login to Facebook first with ':facebook-auth'."); 135 135 return 0; 136 136 } … … 139 139 140 140 BarnOwl::filter(qw{facebook type ^facebook$}); 141 BarnOwl::bindkey(qw(recv f command facebook)); 141 142 142 143 sub complete_user { return keys %{$facebook_handle->{friends}}; } -
perl/modules/Facebook/lib/BarnOwl/Module/Facebook/Handle.pm
r8aa81172 r7efa163 26 26 my @words = split(' ', lc($sentence)); 27 27 return () unless @words; 28 return (reduce { length($a) > length($b) ? $a : $b } @words,);28 return (reduce { length($a) > length($b) ? $a : $b } @words); 29 29 }; 30 30 } else { … … 71 71 72 72 my $self = { 73 'cfg' 73 'cfg' => $cfg, 74 74 'facebook' => undef, 75 75 … … 238 238 return unless $self->{logged_in}; 239 239 240 # XXX Oh no! This blocks the user interface. Not good.241 # Ideally, we should have some worker thread for polling facebook.242 # But BarnOwl is probably not thread-safe >_<243 244 240 my $old_topics = $self->{topics}; 245 241 $self->{topics} = {}; … … 289 285 } 290 286 287 # XXX The intent is to get the 'Comment' link, which also 288 # serves as a canonical link to the post. The {name} 289 # field should equal 'Comment'. But we don't check 290 # this, we assume that the first element is the right one. 291 291 my $link = $post->{actions}[0]{link}; 292 292 … … 294 294 my $created_time = str2time($post->{created_time}); 295 295 if ($created_time >= $self->{last_poll}) { 296 # XXX indexing is fragile297 296 my $msg = BarnOwl::Message->new( 298 297 type => 'Facebook', … … 302 301 name_id => $name_id, 303 302 direction => 'in', 304 body => $self->format_body($post),303 body => wordwrap($self->format_body($post)), 305 304 post_id => $post_id, 306 305 topic => $topic, 307 306 time => asctime(localtime $created_time), 308 # XXX The intent is to get the 'Comment' link, which also309 # serves as a canonical link to the post. The {name}310 # field should equal 'Comment'.311 307 permalink => $link, 312 308 ); … … 331 327 name_id => $name_id, 332 328 direction => 'in', 333 body => $comment->{message},329 body => wordwrap($comment->{message}), 334 330 post_id => $post_id, 335 331 topic => $topic, … … 348 344 $self->{last_poll} = $new_last_poll; 349 345 }); 346 } 347 348 sub wordwrap { 349 my $text = shift; 350 return BarnOwl::wordwrap($text, BarnOwl::getvar('edit:maxwrapcols')); 350 351 } 351 352 … … 431 432 $self->facebook_do_auth(sub { 432 433 my $raw_cfg = to_json($self->{cfg}); 433 BarnOwl::admin_message('Facebook', "Add this as the contents of your ~/.owl/facebook file:\n$raw_cfg"); 434 my $cfg_file; 435 unless (open($cfg_file, ">", BarnOwl::get_config_dir() . "/facebook")) { 436 BarnOwl::admin_message('Facebook', "Add this as the contents of your ~/.owl/facebook file:\n$raw_cfg"); 437 return; 438 } 439 print $cfg_file $raw_cfg; 440 close $cfg_file; 441 BarnOwl::admin_message('Facebook', "Saved your login credentials to ~/.owl/facebook."); 434 442 }); 435 443 return;
Note: See TracChangeset
for help on using the changeset viewer.