Ignore:
Timestamp:
Sep 20, 2011, 11:15:33 PM (13 years ago)
Author:
Edward Z. Yang <ezyang@mit.edu>
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)
Message:
Wordwrap, write the config, style wibbles.

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
File:
1 edited

Legend:

Unmodified
Added
Removed
  • perl/modules/Facebook/lib/BarnOwl/Module/Facebook/Handle.pm

    r8aa81172 r7efa163  
    2626        my @words = split(' ', lc($sentence));
    2727        return () unless @words;
    28         return (reduce{ length($a) > length($b) ? $a : $b } @words,);
     28        return (reduce { length($a) > length($b) ? $a : $b } @words);
    2929    };
    3030} else {
     
    7171
    7272    my $self = {
    73         'cfg'  => $cfg,
     73        'cfg' => $cfg,
    7474        'facebook' => undef,
    7575
     
    238238    return unless $self->{logged_in};
    239239
    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 
    244240    my $old_topics = $self->{topics};
    245241    $self->{topics} = {};
     
    289285            }
    290286
     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.
    291291            my $link = $post->{actions}[0]{link};
    292292
     
    294294            my $created_time = str2time($post->{created_time});
    295295            if ($created_time >= $self->{last_poll}) {
    296                 # XXX indexing is fragile
    297296                my $msg = BarnOwl::Message->new(
    298297                    type      => 'Facebook',
     
    302301                    name_id   => $name_id,
    303302                    direction => 'in',
    304                     body      => $self->format_body($post),
     303                    body      => wordwrap($self->format_body($post)),
    305304                    post_id   => $post_id,
    306305                    topic     => $topic,
    307306                    time      => asctime(localtime $created_time),
    308                     # XXX The intent is to get the 'Comment' link, which also
    309                     # serves as a canonical link to the post.  The {name}
    310                     # field should equal 'Comment'.
    311307                    permalink => $link,
    312308                   );
     
    331327                        name_id   => $name_id,
    332328                        direction => 'in',
    333                         body      => $comment->{message},
     329                        body      => wordwrap($comment->{message}),
    334330                        post_id   => $post_id,
    335331                        topic     => $topic,
     
    348344        $self->{last_poll} = $new_last_poll;
    349345    });
     346}
     347
     348sub wordwrap {
     349    my $text = shift;
     350    return BarnOwl::wordwrap($text, BarnOwl::getvar('edit:maxwrapcols'));
    350351}
    351352
     
    431432    $self->facebook_do_auth(sub {
    432433        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.");
    434442    });
    435443    return;
Note: See TracChangeset for help on using the changeset viewer.