Changeset 9da6022 for perl/modules/Facebook/lib
- Timestamp:
- Sep 19, 2011, 1:31:34 PM (13 years ago)
- 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)
- Location:
- perl/modules/Facebook/lib/BarnOwl
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
perl/modules/Facebook/lib/BarnOwl/Message/Facebook.pm
rb594537 r9da6022 14 14 15 15 sub context { return shift->{"name"}; } 16 sub subcontext { return shift->{" postid"}; }16 sub subcontext { return shift->{"topic"}; } 17 17 sub service { return "http://www.facebook.com"; } 18 18 sub long_sender { return shift->{"zsig"}; } # XXX hack, shouldn't be named zsig -
perl/modules/Facebook/lib/BarnOwl/Module/Facebook.pm
rf75a9ca r9da6022 130 130 sub cmd_facebook_comment { 131 131 my $cmd = shift; 132 my $postid = shift; 132 my $postid = shift; 133 134 my $topic = $facebook_handle->get_topic($postid); 133 135 134 136 # XXX UI should give some (better) indication /which/ conversation 135 137 # is being commented on 136 BarnOwl::start_edit_win("Write a comment ... ($postid)",138 BarnOwl::start_edit_win("Write a comment on '$topic'...", 137 139 sub { $facebook_handle->facebook_comment($postid, shift) }); 138 140 } -
perl/modules/Facebook/lib/BarnOwl/Module/Facebook/Handle.pm
rf75a9ca r9da6022 15 15 16 16 use Facebook::Graph; 17 use Data::Dumper; 17 18 use Lingua::EN::Keywords; 19 18 20 use JSON; 19 21 use Date::Parse; … … 80 82 'login_url' => 'http://goo.gl/yA42G', 81 83 82 'logged_in' => 0 84 'logged_in' => 0, 85 86 # would need another hash for topic de-dup 87 'topics' => {}, 83 88 }; 84 89 … … 144 149 # Ideally, we should have some worker thread for polling facebook. 145 150 # But BarnOwl is probably not thread-safe >_< 151 152 my $old_topics = $self->{topics}; 153 $self->{topics} = {}; 146 154 147 155 my $updates = eval { … … 158 166 $self->die_on_error($@); 159 167 160 #warn Dumper($updates);161 162 168 my $new_last_poll = $self->{last_poll}; 163 169 for my $post ( reverse @{$updates->{data}} ) { … … 173 179 my $name = $post->{to}{data}[0]{name} || $post->{from}{name}; 174 180 my $name_id = $post->{to}{data}[0]{id} || $post->{from}{id}; 181 my $postid = $post->{id}; 175 182 176 183 # Only handle post if it's new 177 184 my $created_time = str2time($post->{created_time}); 178 185 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; 179 189 # XXX indexing is fragile 180 190 my $msg = BarnOwl::Message->new( … … 186 196 direction => 'in', 187 197 body => $self->format_body($post), 188 postid => $post->{id}, 198 postid => $postid, 199 topic => $topic, 189 200 time => asctime(localtime $created_time), 190 201 # XXX The intent is to get the 'Comment' link, which also … … 194 205 ); 195 206 BarnOwl::queue_message($msg); 207 } else { 208 $self->{topics}->{$postid} = $old_topics->{$postid} || 'personal'; 196 209 } 197 210 … … 214 227 direction => 'in', 215 228 body => $comment->{message}, 216 postid => $post->{id}, 229 postid => $postid, 230 topic => $self->get_topic($postid), 217 231 time => asctime(localtime $comment_time), 218 232 ); … … 224 238 } 225 239 } 240 # old_topics gets GC'd 226 241 227 242 $self->{last_poll} = $new_last_poll; … … 308 323 } 309 324 325 sub get_topic { 326 my $self = shift; 327 328 my $postid = shift; 329 330 return $self->{topics}->{$postid} || 'personal'; 331 } 332 310 333 1;
Note: See TracChangeset
for help on using the changeset viewer.