Ignore:
Timestamp:
Sep 19, 2011, 1:31:34 PM (13 years ago)
Author:
Edward Z. Yang <ezyang@mit.edu>
Children:
2226f91
Parents:
f75a9ca
git-author:
Edward Z. Yang <ezyang@mit.edu> (06/20/11 11:41:44)
git-committer:
Edward Z. Yang <ezyang@mit.edu> (09/19/11 13:31:34)
Message:
Implement automatic instance selection, with no de-dup.

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
Location:
perl/modules/Facebook/lib/BarnOwl
Files:
3 edited

Legend:

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

    rb594537 r9da6022  
    1414
    1515sub context { return shift->{"name"}; }
    16 sub subcontext { return shift->{"postid"}; }
     16sub subcontext { return shift->{"topic"}; }
    1717sub service { return "http://www.facebook.com"; }
    1818sub long_sender { return shift->{"zsig"}; } # XXX hack, shouldn't be named zsig
  • perl/modules/Facebook/lib/BarnOwl/Module/Facebook.pm

    rf75a9ca r9da6022  
    130130sub cmd_facebook_comment {
    131131    my $cmd  = shift;
    132     my $postid   = shift;
     132    my $postid = shift;
     133
     134    my $topic = $facebook_handle->get_topic($postid);
    133135
    134136    # XXX UI should give some (better) indication /which/ conversation
    135137    # is being commented on
    136     BarnOwl::start_edit_win("Write a comment... ($postid)",
     138    BarnOwl::start_edit_win("Write a comment on '$topic'...",
    137139                            sub { $facebook_handle->facebook_comment($postid, shift) });
    138140}
  • perl/modules/Facebook/lib/BarnOwl/Module/Facebook/Handle.pm

    rf75a9ca r9da6022  
    1515
    1616use Facebook::Graph;
    17 use Data::Dumper;
     17
     18use Lingua::EN::Keywords;
     19
    1820use JSON;
    1921use Date::Parse;
     
    8082        'login_url' => 'http://goo.gl/yA42G',
    8183
    82         'logged_in' => 0
     84        'logged_in' => 0,
     85
     86        # would need another hash for topic de-dup
     87        'topics' => {},
    8388    };
    8489
     
    144149    # Ideally, we should have some worker thread for polling facebook.
    145150    # But BarnOwl is probably not thread-safe >_<
     151
     152    my $old_topics = $self->{topics};
     153    $self->{topics} = {};
    146154
    147155    my $updates = eval {
     
    158166    $self->die_on_error($@);
    159167
    160     #warn Dumper($updates);
    161 
    162168    my $new_last_poll = $self->{last_poll};
    163169    for my $post ( reverse @{$updates->{data}} ) {
     
    173179        my $name    = $post->{to}{data}[0]{name} || $post->{from}{name};
    174180        my $name_id = $post->{to}{data}[0]{id} || $post->{from}{id};
     181        my $postid  = $post->{id};
    175182
    176183        # Only handle post if it's new
    177184        my $created_time = str2time($post->{created_time});
    178185        if ($created_time >= $self->{last_poll}) {
     186            my @keywords = keywords($post->{name} || $post->{message});
     187            my $topic = $keywords[0] || 'personal';
     188            $self->{topics}->{$postid} = $topic;
    179189            # XXX indexing is fragile
    180190            my $msg = BarnOwl::Message->new(
     
    186196                direction => 'in',
    187197                body      => $self->format_body($post),
    188                 postid    => $post->{id},
     198                postid    => $postid,
     199                topic     => $topic,
    189200                time      => asctime(localtime $created_time),
    190201                # XXX The intent is to get the 'Comment' link, which also
     
    194205               );
    195206            BarnOwl::queue_message($msg);
     207        } else {
     208            $self->{topics}->{$postid} = $old_topics->{$postid} || 'personal';
    196209        }
    197210
     
    214227                    direction => 'in',
    215228                    body      => $comment->{message},
    216                     postid    => $post->{id},
     229                    postid    => $postid,
     230                    topic     => $self->get_topic($postid),
    217231                    time      => asctime(localtime $comment_time),
    218232                   );
     
    224238        }
    225239    }
     240    # old_topics gets GC'd
    226241
    227242    $self->{last_poll} = $new_last_poll;
     
    308323}
    309324
     325sub get_topic {
     326    my $self = shift;
     327
     328    my $postid = shift;
     329
     330    return $self->{topics}->{$postid} || 'personal';
     331}
     332
    3103331;
Note: See TracChangeset for help on using the changeset viewer.