Changeset 99f0a77 for perl/modules/Facebook/lib/BarnOwl/Module/Facebook
- Timestamp:
- Sep 20, 2011, 11:15:31 PM (13 years ago)
- Branches:
- master, release-1.10, release-1.9
- Children:
- eb497a9
- Parents:
- 3199d8e
- git-author:
- Edward Z. Yang <ezyang@mit.edu> (06/20/11 11:41:44)
- git-committer:
- Edward Z. Yang <ezyang@mit.edu> (09/20/11 23:15:31)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
perl/modules/Facebook/lib/BarnOwl/Module/Facebook/Handle.pm
r3199d8e r99f0a77 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.